Couldn‘t load custom C++ ops. This can happen if your PyTorch an
【摘要】 问题背景在运行yolov5的detect.py文件时,报了下面的错误,之前也遇到过且解决过,所以这次记录下解决方案。RuntimeError: Couldn’t load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors...
问题背景
在运行yolov5的detect.py文件时,报了下面的错误,之前也遇到过且解决过,所以这次记录下解决方案。
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, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.version and your torchvision version with torchvision.version and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.
问题原因
显然,根据报错信息得知:torch版本和torchvision版本不匹配。我们需要重装torch或者torchvision使得它们版本匹配。
点此查看torch和torchvision正确对应版本,看完之后发现自己版本也是对应的啊,为什么会报错呢?这里就是最细节的地方,因为比如我的torch是torch1.11.0+cu111,那么torchvision也得是torchvision0.10.0+cu111,而不是0.10.0。默认安装时很可能没有选择相同版本的安装包导致出错。
解决方案
1、进入https://download.pytorch.org/whl/cu113,分别进入torch和torchvision分支选择版本对应且后缀相同的安装包,然后下载到本地。因为我的ubuntu是aarch64架构的,所以后缀就是下面这样的,你们下载时候先uname -a
查看下ubuntu架构。
2、然后卸载已之前的torch和torchvision,pip uninstall torch
和 pip uninstall torchvision
3、whl格式本质上是一个压缩包,里面包含了py文件,以及经过编译的pyd文件。我们切换到安装包的下载目录,然后先pip install torch-1.9.0-cp38-cp38-manylinux2014_aarch64.whl
,后 pip install torchvision-0.10.0-cp38-cp38-manylinux2014_aarch64.whl
。
注意,一定要先安装torch,再安装torchvision!如果顺序反过来,它会自动下载torch进行安装,然后版本又不对了,还得卸载了重新安装,我帮你们又踩了下坑。
4、我们再次运行yolov5,没有任何问题,检测结果已成功保存。
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)