torch.hub.load报错urllib.error.HTTPError: HTTP Error 403: rate limit exceeded

在运行DINOv2的示例代码时,需要载入预训练的模型,比如:

python 复制代码
backbone_model = torch.hub.load(repo_or_dir="facebookresearch/dinov2", model=backbone_name)

torch.hub.load报错"urllib.error.HTTPError: HTTP Error 403: rate limit exceeded",具体报错信息如下:

Traceback (most recent call last):

File "/data1/domainnet/dinov2/demo.py", line 15, in <module>

backbone_model = torch.hub.load(repo_or_dir="facebookresearch/dinov2", model=backbone_name)

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/site-packages/torch/hub.py", line 555, in load

repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, trust_repo, "load",

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/site-packages/torch/hub.py", line 222, in _get_cache_or_reload

_validate_not_a_forked_repo(repo_owner, repo_name, ref)

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/site-packages/torch/hub.py", line 181, in _validate_not_a_forked_repo

response = json.loads(_read_url(Request(url, headers=headers)))

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/site-packages/torch/hub.py", line 164, in _read_url

with urlopen(url) as r:

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/urllib/request.py", line 214, in urlopen

return opener.open(url, data, timeout)

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/urllib/request.py", line 523, in open

response = meth(req, response)

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/urllib/request.py", line 632, in http_response

response = self.parent.error(

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/urllib/request.py", line 561, in error

return self._call_chain(*args)

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/urllib/request.py", line 494, in _call_chain

result = func(*args)

File "/root/miniconda3/envs/dinov2-extras/lib/python3.9/urllib/request.py", line 641, in http_error_default

raise HTTPError(req.full_url, code, msg, hdrs, fp)

urllib.error.HTTPError: HTTP Error 403: rate limit exceeded

据说这个是PyTorch部分版本的Bug,可以在torch.hub相关代码前加一行,如下:

python 复制代码
torch.hub._validate_not_a_forked_repo = lambda a, b, c: True

backbone_model = torch.hub.load(repo_or_dir="facebookresearch/dinov2", model=backbone_name)

问题解决。

相关推荐
初级炼丹师(爱说实话版)29 分钟前
nn.MultiheadAttention返回的注意力权重和标准的计算注意力权重的区别
人工智能·深度学习·机器学习
roman_日积跬步-终至千里31 分钟前
【人工智能基础】计算机视觉
人工智能·计算机视觉
敲代码不忘补水32 分钟前
Python Matplotlib 经典 3D 绘图类型:从二维到三维的可视化解析
开发语言·python·3d·数据分析·numpy·pandas·matplotlib
努力的小好1 小时前
【python】摄像头调用马赛克恶搞
python
AI小杨1 小时前
【数据分析】一、pandas数据处理指南:100个基于pandas数据预处理方法
python·数据挖掘·数据分析·pandas·pandas使用技巧
weixin_431470861 小时前
文本数据分析(nlp)
开发语言·python·深度学习·自然语言处理
終不似少年遊*1 小时前
数据分析-机器学习-第三方库使用基础
python·机器学习·数据挖掘·数据分析·numpy
天天要nx1 小时前
D79【 python 接口自动化学习】- python基础之HTTP
python
ystraw_ah1 小时前
python 画图例子
python
Francek Chen1 小时前
【大数据分析&深度学习】在Hadoop上实现分布式深度学习
人工智能·hadoop·分布式·深度学习·数据分析