YOLOv8:RuntimeError:在当前进程完成其引导阶段之前已尝试启动新进程

问题描述 投票:0回答:2

已尝试在 当前进程已完成引导阶段。

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

** 尝试在 python 环境中训练 YOLOv8 模型时出现此错误** 从 ultralytics 导入 YOLO

# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)

# Use the model
results = model.train(data="coco128.yaml", epochs=3)  # train the model
results = model.val()  # evaluate model performance on the validation set
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
success = YOLO("yolov8n.pt").export(format="onnx")  # export a model to ONNX format
python yolo
2个回答
0
投票

我设法通过将模型过程代码保留在顶级环境的名称下(如果 name == 'main':) 来克服这个问题,如下所示:

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)

if __name__ == '__main__':
    # Use the model
    results = model.train(data="coco128.yaml", epochs=3)  # train the model
    results = model.val()  # evaluate model performance on the validation set
    results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
    success = YOLO("yolov8n.pt").export(format="onnx")  # export a model to ONNX format

0
投票

我有同样的错误,我没有使用 python 脚本,而是使用 CLI 进行培训。

从 ultralytics 目录转到终端: yolo task=detect mode=train epochs=100 data=yolov8n.yaml model=yolov8n.pt imgsz=640

© www.soinside.com 2019 - 2024. All rights reserved.