YOLOv8 : RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase
Asked Answered
T

3

11

An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    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.

** This error shows up when trying to train a YOLOv8 model in a python environment** 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)

# 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
Thrilling answered 13/1, 2023 at 15:26 Comment(0)
T
24

I managed to overcome this by keeping the model process code under the name of the top-level environment (if name == 'main':) , as seen below:

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
Thrilling answered 13/1, 2023 at 15:36 Comment(0)
O
1

In python code, just mentioned workers=0. It will be fine.

e.g.

from ultralytics import YOLO

# Load a model
model = YOLO('yolov8s-seg.yaml')  # build a new model from YAML
model = YOLO('yolov8s-seg.pt')  # load a pretrained model (recommended for training)
model = YOLO('yolov8s-seg.yaml').load('yolov8n.pt')  # build from YAML and transfer weights

# Train the model
results = model.train(data='./data/dataset.yaml', epochs=100, imgsz=640, workers=0)

Oxidase answered 7/3, 2024 at 6:8 Comment(1)
Yes, but that will make it much slower.Jarrod
S
-1

I had the same error, instead of using the python script I just used the CLI to do the training.

from the ultralytics directory go to the terminal:

yolo task=detect mode=train epochs=100 data=yolov8n.yaml model=yolov8n.pt imgsz=640
Scoundrelly answered 14/3, 2023 at 15:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.