[YOLOv8] 问题分析和解决 - NotImplementedError: Could not run ‘torchvision::nms‘ ...from the ‘CUDA‘ backend

问题描述

当使用YOLOv8训练自定义的数据集时,

from ultralytics import YOLO

# 加载一个模型
model = YOLO('yolov8n.yaml')  # 从YAML建立一个新模型
# 训练模型
results = model.train(
    data='D:/YOLOv8Train/v8_train_datasets/mktk_dataset/data.yaml',
    device='0',
    epochs=5,
    batch=4,
    verbose=True,
    imgsz=640)

抛出如下错误:

 NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build).

运行环境说明

windows10 + python3.11 + cuda11.8

pip install ultralytics
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

原因分析和解决

查看当前python运行环境的torch版本: 

咱这么奇怪,torch + torchaudio都是coda版本,torchvision却不是,估计问题就出在这里。

为什么会出现这种情况呢? 当你“pip install ultralytics” 时,torch和torchvision会作为它的依赖一起安装了,当执行“pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118”时,会卸载torch,然后再安装torch+cuda版本,但是不会自动卸载torchvision已有版本,然后再安装torchvision+cuda版本。

解决方法一:

手动卸载“torchvision” ,然后重新安装对应的cuda版本,

重新跑python代码,问题解决。

解决方法二:
或许,先安装pytorch cuda版本,然后再安装ultralytics:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install ultralytics

有空的朋友可以试试看。

有网友,验证了,方法2不可行:

  • 19
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老狼IT工作室

你的鼓励将是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值