yolov8 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 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.
解决办法:
添加
if __name__ == '__main__':
即
from ultralytics import YOLO
# 加载模型
model = YOLO("yolov8n.yaml") # 从头开始构建新模型
# model = YOLO("weights/yolov8n.pt") # 加载预训练模型(推荐用于训练)
# Use the model
# results = model.train(data="ultralytics/datasets/rain.yaml", epochs=20, batch=-1) # 训练模型
if __name__ == '__main__':
# Use the model
results = model.train(data="ultralytics/datasets/rain.yaml", epochs=150, batch=32) # 训练模型
results = model.val()
results = model("自己的验证图片")
success = YOLO("yolov8n.pt").export(format="onnx")
文章讨论了在使用YOLOv8时遇到的RuntimeError,该错误通常由于在进程初始化阶段尝试启动新进程引起。解决方案是在主模块中添加if__name__==__main__条件来确保正确启动子进程。文章提供了加载和训练YOLO模型的代码示例,包括使用预训练权重、训练模型、验证以及将模型导出为ONNX格式。
1773





