作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我之前成功加载了带有 ResNet50_Weights 参数的 ResNet 模型,但突然我开始收到以下错误:
Traceback (most recent call last):
File "splitting_models.py", line 3, in <module>
from torchvision.models.resnet import ResNet50_Weights
ImportError: cannot import name 'ResNet50_Weights' from 'torchvision.models.resnet' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torchvision/models/resnet.py)
这里是导入:
from torchvision.models import ResNet50_Weights
我该如何解决这个问题?
PyTorch 版本:1.2.0
torch 视觉版本:0.4.0
升级使用
pip install --upgrade torch torchvision
到以下版本修复了问题:
PyTorch 版本:1.12.0
torch 视觉版本:0.13.0
最佳答案
这个问题花了我几天时间才解决。在运行包含 Pytorch 模型的代码之前,请确保您已连接到稳定的网络。这是因为当您第一次运行 resnet50、alexnet、resnet18 等 Pytorch 模型时,它会下载其功能,因此如果出现安装错误,它会缓存其下载并绘制此类错误,如果您尝试重新运行。要解决问题,请找到缓存文件所在的位置,将其删除并尝试在网络稳定的情况下重新运行代码。对于我的情况:
C:\Users\user/.cache\torch\hub\checkpoints\resnet18-f37072fd.pth
这是缓存文件所在的位置,将其删除并尝试在稳定的网络下重新运行。
希望对您有所帮助。谢谢问候,
关于pytorch - 无法从 'ResNet50_Weights' 导入名称 'torchvision.models.resnet',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73029425/
我是一名优秀的程序员,十分优秀!