yolov5 下torchvision版本问题 #VersionConflict: (torchvision Requirement.parse(‘torchvision>=0.8.1‘))

运行detect.py时出现torchvision版本冲突报错,给出两种解决方案。方案一在线下载报错,方案二采用离线下载,更新torchvision和torch版本。经多次尝试和版本匹配,最终成功运行detect.py,强调torch和torchvision都应离线下载更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

继续运行detect.py,报错
VersionConflict: (torchvision 0.2.2.post3 (d:\yolov5-master\venv\lib\site-packages), Requirement.parse(‘torchvision>=0.8.1’))
也就是torchvision的版本不符合要求
在这里插入图片描述

方案一:

参考此链接https://stackoverflow.com/questions/66107660/installing-yolov5-dependencies-torchvision
在pycharm terminal中输入
pip install torch1.7.1+cu101 torchvision0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

但是报错
在这里插入图片描述在这里插入图片描述

ReadTimeoutError(self._pool, None, “Read timed out.”)
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘download.pytorch.org’, port=443): Read timed out.

方案二:

其实方案一是在线下载,然后方案二是离线下载
[1] torch版本为1.7.1+cu101 torchvision版本为0.8.2+cu101
a)全部版本下载地址为,https://download.pytorch.org/whl/torch_stable.html
b)torch上述指定版本,https://download.pytorch.org/whl/cu101/torch-1.7.1%2Bcu101-cp39-cp39-win_amd64.whl
c)torchvision上述指定版本,https://download.pytorch.org/whl/cu101/torchvision-0.8.2%2Bcu101-cp39-cp39-win_amd64.whl

[2] 然后pip list
在这里插入图片描述

发现原来已经安装的torch就是1.7.1版本的,所以没有再动torch,然后torchvision目前的版本是0.2.2.post3,所以更新刚刚下载好的0.8.2的包。terminal中
pip install XXX.whl 即可
(XXX.whl 是刚刚下载的0.8.2torchvison的离线包 所在的位置/文件名) 没有报错
在这里插入图片描述

[3] 我的Torch是1.7.1,但是如果安装torchvison0.8.1就会报错,如下图
在这里插入图片描述
所以,查看torch和torchvison对应的版本,戳这里
https://github.com/pytorch/vision#installation

[4] 之后继续运行detect.py发现没有关于torchvison的报错啦,棒(๑•̀ㅂ•́)و✧
在这里插入图片描述

[5] 然后没有高兴过三秒,报错还是关于版本不匹配
在这里插入图片描述
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.

所以,更新一下刚刚下载的1.7.1的torch看看,OK!
在这里插入图片描述
[6] 然后对比,更新torch之前的显示的版本(图1)和更新后(图2)
更新前
更新后
所以还是有区别的哈,因此,torch和torchvision都要安安稳稳下载离线包然后更新,不能和我一样偷懒哈哈哈哈哈

[7] 继续运行detect.py 妈耶!!!成功了,真是听者落泪,闻者伤心,太感人了!!!!!
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

参考链接
1)https://stackoverflow.com/questions/66107660/installing-yolov5-dependencies-torchvision
2)https://blog.csdn.net/weixin_45437033/article/details/113557656?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-7&spm=1001.2101.3001.4242
3)https://jingyan.baidu.com/article/5552ef47996851518ffbc9d2.html

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值