当前位置:   article > 正文

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

urllib.error.httperror: http error 403: rate limit exceeded

在运行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相关代码前加一行,如下:

  1. torch.hub._validate_not_a_forked_repo = lambda a, b, c: True
  2. backbone_model = torch.hub.load(repo_or_dir="facebookresearch/dinov2", model=backbone_name)

问题解决。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/342944
推荐阅读
相关标签
  

闽ICP备14008679号