yolov8 运行报错 RuntimeError: An attempt has been made to start a new process before the

文章讨论了在使用YOLOv8时遇到的RuntimeError,该错误通常由于在进程初始化阶段尝试启动新进程引起。解决方案是在主模块中添加if__name__==__main__条件来确保正确启动子进程。文章提供了加载和训练YOLO模型的代码示例,包括使用预训练权重、训练模型、验证以及将模型导出为ONNX格式。
部署运行你感兴趣的模型镜像
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") 

您可能感兴趣的与本文相关的镜像

Yolo-v8.3

Yolo-v8.3

Yolo

YOLO(You Only Look Once)是一种流行的物体检测和图像分割模型,由华盛顿大学的Joseph Redmon 和Ali Farhadi 开发。 YOLO 于2015 年推出,因其高速和高精度而广受欢迎

评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值