在运行DINOv2的示例代码时,需要载入预训练的模型,比如:
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相关代码前加一行,如下:文章来源:https://www.toymoban.com/news/detail-766367.html
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)
问题解决。文章来源地址https://www.toymoban.com/news/detail-766367.html
到了这里,关于torch.hub.load报错urllib.error.HTTPError: HTTP Error 403: rate limit exceeded的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!