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)

问题解决。

相关推荐
ghostwritten1 分钟前
Conda 安装 Jupyter Notebook
开发语言·ide·python·jupyter·conda
行知SLAM2 分钟前
第0章 机器人及自动驾驶SLAM定位方法全解析及入门进阶学习建议
人工智能·算法·机器人·自动驾驶
qq_2739002322 分钟前
torch.reciprocal介绍
人工智能·pytorch·python·深度学习
云边的快乐猫25 分钟前
官网自动化测试工具安装(node.js、Appium、Android SDK、手机模拟器、APPium-python-Client)
自动化测试·python·appium·移动端测试·手机模拟器
hakesashou31 分钟前
Python中对象序列化以及反序列化的方法
linux·开发语言·python
pencil_pen_lv32 分钟前
后端Java开发:第十天
开发语言·python
weixin_307779131 小时前
Kafka和Jenkins实现EMR上PySpark和EC2上Airflow的CI/CD
数据仓库·python·ci/cd·kafka·云计算
API_Zevin1 小时前
如何优化亚马逊广告以提高ROI?
大数据·开发语言·前端·后端·爬虫·python·学习
青松@FasterAI1 小时前
【NLP高频面题 - 分布式训练篇】ZeRO主要为了解决什么问题?
人工智能·深度学习·自然语言处理·分布式训练·nlp面试
lu_rong_qq1 小时前
【LLM】一文了解 NLP 里程碑模型 BERT
人工智能·自然语言处理·bert