配置yolov5环境时最后一步测试出现错误,RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions,找了很多方法,卸载安装了很多次。一开始说是torch和torchvision版本不匹配,但看了配置的是和github(GitHub - pytorch/vision: Datasets, Transforms and Models specific to Computer Vision)上一样的,
最后重新卸载安装也不能用,仍然报错。于是就随便试试安装低版本的torch和torchvision,没想到成功解决了。我是将torch1.12.0+torchvision0.13.0换成了torch1.11.0+torchvision0.12.0.
1.先在conda环境中进入自己设置的环境,我的命名为pytorch,激活环境进去后,卸载高版本torch1.12.0和torchvision0.13.0
pip uninstall torch
pip uninstall torchvision
2. 去pytorch官网找之前的版本,https://pytorch.org/
# CUDA 10.2
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=10.2 -c pytorch
# CUDA 11.3
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
# CPU Only
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cpuonly -c pytorch
根据官网提示选择自己的配置 ,我使用CPU所以使用了最后一行,安装完后再运行测试文件就正常了,咱也不知道这是为啥
小插曲:中间重新安装torch时,我第一次不知道在哪看的不用加上pytorch官网给的代码的最后一小段 -c pytorch,于是它就出问题了,提示我没有可获得的包,所以大家还是老老实实复制官网上给的代码吧
PackagesNotFoundError: The following packages are not available from current channels:
- torchvision==0.12.0
- torchaudio==0.11.0
- pytorch==1.11.0