背景:PyCharm下使用代码运行yolov8
问题描述 连续运行两次导致进程冲突 RuntimeError
原因:在当前进程完成引导阶段之前,试图启动新的子进程。
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
File “D:\Program
Files\Python\Python38\lib\multiprocessing\spawn.py”, line 154, in
get_preparation_data
_check_not_importing_main() File “D:\Program Files\Python\Python38\lib\multiprocessing\spawn.py”, line 134, in
_check_not_importing_main
raise RuntimeError(‘’’ RuntimeError:
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 yourchild processes and you have forgotten to use the proper idiomin the main module:if __name__ == '__main__':freeze_support()...The "freeze_support()" line can be omitted if the programis not going to be frozen to produce an executable. albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01,
blur_limit=(3, 7)), ToGray(p=0.01), CLAHE(p=0.01, clip_limit=(1, 4.0),
tile_grid_size=(8, 8))
解决方式
将线程书设置为0:workers=0
from ultralytics import YOLOolov8n.yaml').load('yolov8n.pt') # build from YAML and transfer weights# Train the model
results = model.train(data='coco128.yaml', epochs=5, imgsz=640,batch=-1,workers=0)