gpt4 book ai didi

pytorch - 无法从 'ResNet50_Weights' 导入名称 'torchvision.models.resnet'

转载 作者:行者123 更新时间:2023-12-05 04:26:35 28 4
gpt4 key购买 nike

我之前成功加载了带有 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com