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版本。

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-16 12:48:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-16 12:48:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-16 12:48:02       87 阅读
  4. Python语言-面向对象

    2024-06-16 12:48:02       96 阅读

热门阅读

  1. windows11键盘失灵

    2024-06-16 12:48:02       29 阅读
  2. ssl安全证书免费申请方法,非自签证书

    2024-06-16 12:48:02       28 阅读
  3. 服务和协议的关系?

    2024-06-16 12:48:02       35 阅读
  4. 【DevOps】Logstash详解:高效日志管理与分析工具

    2024-06-16 12:48:02       26 阅读
  5. 285. 二叉搜索树中的中序后继

    2024-06-16 12:48:02       26 阅读
  6. vue学习(一)

    2024-06-16 12:48:02       28 阅读
  7. vue相关的前端知识回顾

    2024-06-16 12:48:02       31 阅读
  8. vue中的组件通信

    2024-06-16 12:48:02       48 阅读
  9. 使用C++调用VTK库实现三维显示示例

    2024-06-16 12:48:02       42 阅读