pytorch版本与torchvision版本不匹配问题处理

问题

在新环境中,利用yolov8训练模型的时候报错,错误内容如下:

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). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'torchvision::nms' is only available for these backends: [CPU, Meta, QuantizedCPU, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradMPS, AutogradXPU, AutogradHPU, AutogradLazy, AutogradMeta, Tracer, AutocastCPU, AutocastCUDA, FuncTorchBatched, BatchedNestedTensor, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PreDispatch, PythonDispatcher].

这个问题出现出现的原因是因为pytorch版本与torchvision版本不匹配导致利用pip查看安装的包,果然存在问题,发现pytorch版本为GPU版本,但是torchvision为CPU版本。

问题复现

我问题出现的原因是在新环境中,利用如下安装命令:

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

安装pytorch的时候,pytorch由于很大,下载很慢,所以我单独下载了pytorch的whl包进行了安装,然后利用如下命令安装了torchvision和torchaudio:

pip3 install torchvision torchaudio

正是这句安装命令导致了问题,这句安装命令会默认安装torchvision的CPU版本

解决方法

解决方法很简单,卸载掉torchvision,然后安装GPU版本的torchvision即可。
安装命令如下:

pip3 install torchvision --index-url https://download.pytorch.org/whl/cu118

两点注意内容

其一:pytorch版本与torchvision版本对应关系

pytorch版本与torchvision版本对应关系可以参考官网,链接地址如下:
https://github.com/pytorch/vision
下翻可找到对应对应关系表,如下所示:
在这里插入图片描述

其二:CPU版本或GPU版本问题

注意,你安装pytorch为CPU版本,那么torchvision也需要是CPU版本,同样,pytorch为GPU版本,那么torchvision也需要是GPU版本。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

脑洞笔记

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

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

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

打赏作者

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

抵扣说明:

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

余额充值