urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

在训练模型的时候,要加载一些预训练模型,比如vgg等,代码如下

model = torchvision.models.vgg19(pretrained=True)

train的时候会显示

Downloading: "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" to /root/.cache/torch/checkpoints/vgg19-dcbb9e9d.pth

然后出错:

socket.gaierror: [Errno -3] Temporary failure in name resolution
和
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

这是因为无法下载预训练模型,要用外网下载。
所以比较方便的做法就是先把模型下下来,自己想办法连外网然后输链接就自动下了https://download.pytorch.org/models/vgg19-dcbb9e9d.pth
然后把下载的.pth模型文件放在一个固定路径下面,比如

/home/team/torch/models/pre_model/vgg19-dcbb9e9d.pth

最后把代码改成

model = torchvision.models.vgg19(pretrained=False)
pthfile = r'/home/team/torch/models/pre_model/vgg19-dcbb9e9d.pth'
model.load_state_dict(torch.load(pthfile))```
就可以了。
  • 14
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值