timm模块加载预训练模型报错——解决
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.下载保存到项目路径下
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)

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)