timm模块加载预训练模型报错——解决

报错 代码片.

import timm

model = timm.create_model('res2net101_26w_4s', pretrained=True)
print(model)

Traceback (most recent call last):
File “C:\Users\chen.conda\envs\pytorch\lib\site-packages\urllib3\connectionpool.py”, line 711, in urlopen
self._prepare_proxy(conn)
File “C:\Users\chen.conda\envs\pytorch\lib\site-packages\urllib3\connectionpool.py”, line 1007, in _prepare_proxy
conn.connect()
…………
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:
…………
File “C:\Users\chen.conda\envs\pytorch\lib\site-packages\requests\sessions.py”, line 589, in request
resp = self.send(prep, **send_kwargs)
File “C:\Users\chen.conda\envs\pytorch\lib\site-packages\requests\sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “C:\Users\chen.conda\envs\pytorch\lib\site-packages\huggingface_hub\utils_http.py”, line 63, in send
return super().send(request, *args, **kwargs)
File “C:\Users\chen.conda\envs\pytorch\lib\site-packages\requests\adapters.py”, line 513, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: (MaxRetryError(“HTTPSConnectionPool(host=‘huggingface.co’, port=443): Max retries exceeded with url: /timm/res2net101_26w_4s.in1k/resolve/main/model.safetensors (Caused by ProxyError(‘Cannot connect to proxy.’, OSError(0, ‘Error’)))”), ‘(Request ID: ab50cad4-304e-4831-aa7e-1d5213e952c9)’)
进程已结束,退出代码1

大概就是因为网络请求错误问题啥的
timm他会默认先从huggingfaceHub下载,但是HF现在又被墙了,所以要手动下载

1、先获取cfg信息

import timm
model = timm.create_model('res2net101_26w_4s')
print(model.default_cfg)

在这里插入图片描述

2.【科学上网】去https://huggingface.co/上搜索然后再下载模型
在这里插入图片描述
3.下载保存到项目路径下
alt
4、添加参数,再次运行成功打印模型

import timm

model = timm.create_model('res2net101_26w_4s', pretrained=True,
                          pretrained_cfg_overlay=dict(file='checkpoint/res2net101_26w_4s/pytorch_model.bin'))
print(model)

在这里插入图片描述

  • 30
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值