Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to download model using torch.hub.load(). #33233

Closed
TariqAHassan opened this issue Feb 12, 2020 · 15 comments
Closed

Unable to download model using torch.hub.load(). #33233

TariqAHassan opened this issue Feb 12, 2020 · 15 comments
Labels
module: hub triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@TariqAHassan
Copy link

TariqAHassan commented Feb 12, 2020

馃悰 Bug

At the moment, attempts to download (at least some) models with torch.hub.load()
result in 403 errors.

To Reproduce

Steps to reproduce the behavior:

  1. Run the code from here:
import torch

model = torch.hub.load('pytorch/vision:v0.5.0', 'mobilenet_v2', pretrained=True)

This produces the following error:

Downloading: "https://download.pytorch.org/models/mobilenet_v2-b0353104.pth" to .../.cache/torch/checkpoints/mobilenet_v2-b0353104.pth
Traceback (most recent call last):
  File ".../opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3319, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-5-5d64f107c2fe>", line 2, in <module>
    model = torch.hub.load('pytorch/vision:v0.5.0', 'mobilenet_v2', pretrained=True)
  File ".../opt/anaconda3/lib/python3.7/site-packages/torch/hub.py", line 366, in load
    model = entry(*args, **kwargs)
  File ".../.cache/torch/hub/pytorch_vision_v0.4.2/torchvision/models/mobilenet.py", line 160, in mobilenet_v2
    progress=progress)
  File ".../opt/anaconda3/lib/python3.7/site-packages/torch/hub.py", line 492, in load_state_dict_from_url
    download_url_to_file(url, cached_file, hash_prefix, progress=progress)
  File ".../opt/anaconda3/lib/python3.7/site-packages/torch/hub.py", line 391, in download_url_to_file
    u = urlopen(url)
  File ".../opt/anaconda3/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File ".../opt/anaconda3/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File ".../opt/anaconda3/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File ".../opt/anaconda3/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File ".../opt/anaconda3/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File ".../opt/anaconda3/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

NOTE: a copy of the model must not be present in the cache in order for the code snippet above to result in this error.

Expected behavior

Download to complete without an error.

Environment

PyTorch version: 1.4.0
Is debug build: No
CUDA used to build PyTorch: None

OS: Mac OSX 10.15.3
GCC version: Could not collect
CMake version: version 3.15.5

Python version: 3.7
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip] numpy==1.18.1
[pip] numpydoc==0.9.2
[pip] torch==1.4.0
[pip] torchvision==0.5.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2019.5                      281    conda-forge
[conda] mkl-service               2.3.0            py37h0b31af3_0    conda-forge
[conda] mkl_fft                   1.1.0            py37h3b54f70_1    conda-forge
[conda] mkl_random                1.1.0            py37h4a8c4bd_0    conda-forge
[conda] torch                     1.4.0                    pypi_0    pypi
[conda] torchvision               0.5.0                    pypi_0    pypi

Additional context

cc @ailzhang

@ptrblck
Copy link
Collaborator

ptrblck commented Feb 12, 2020

Could you rerun the code now?
We had some server issues as explained here, which should be resolved now.

I just verified that I'm able to download checkpoints from torch hub again.

Related issue: #33234

@zhangguanheng66
Copy link
Contributor

The issue should be resolved. Feel free to reopen the issue.

@zhangguanheng66 zhangguanheng66 added module: hub triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Feb 12, 2020
@happyCodingSusan
Copy link

Hello,

I am running windows 10, installed pytorch 1.4.0, torchvision 0.5.0

When I run the following codes,
import torch
model = torch.hub.load('pytorch/vision', 'resnet18', pretrained=True)

I got the error message of "Exception has occurred: URLError, "

In fact, I want to load the following model, and I got the same error message,
model = torch.hub.load('rwightman/pytorch-pretrained-gluonresnet', 'gluon_resnet34_v1b', pretrained=True)

I wonder if anybody know how to make "torch.hub.load" work in Windows 10.

Many thanks!

@ptrblck
Copy link
Collaborator

ptrblck commented Jan 7, 2021

model = torch.hub.load('rwightman/pytorch-pretrained-gluonresnet', 'gluon_resnet34_v1b', pretrained=True)

works on my Windows10 system with torch==1.8.0.dev20201116, so you might need to update PyTorch to the latest stable release or a nightly build.

@pavi-rajes
Copy link

torch.hub.load() command is not working for me.

Syntax used:
torch.hub.load('pytorch/vision', 'resnet18', pretrained = True)

Error:
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: rate limit exceeded

Environment: Windows 10, python 3.7 , torchvision-0.10.0+cu102

Any help to quickly resolve this issue would be appreciated. Thanks!

@RoyeA
Copy link

RoyeA commented Jul 21, 2021

same here.

torch.hub.list('pytorch/vision',force_reload=True)
urllib.error.HTTPError: HTTP Error 403: rate limit exceeded

torch.version
'1.9.0+cu102'

Resolved the issue by downgrading the torch to version 1.8.1
$python -m pip uninstall torch
$python -m pip install torch==1.8.1

@sieu-n
Copy link

sieu-n commented Sep 17, 2021

This is not resolved and I still experience this bug. Even official COLAB tutorials are bugged.
https://colab.research.google.com/github/pytorch/pytorch.github.io/blob/master/assets/hub/pytorch_vision_deeplabv3_resnet101.ipynb#scrollTo=2zgiOo4JphT5
The only fix is to use torchvision.models alternatively.

@vermavinay982
Copy link

vermavinay982 commented Sep 24, 2021

import torch
model = torch.hub.load('facebookresearch/pytorchvideo', 'slow_r50', pretrained=True)
Downloading: "https://github.com/facebookresearch/pytorchvideo/archive/master.zip"
 to /root/.cache/torch/hub/master.zip
Traceback (most recent call last):
  File "load_model.py", line 2, in <module>
    model = torch.hub.load('facebookresearch/pytorchvideo', 'slow_r50', pretrained=True)
  File "/opt/conda/lib/python3.8/site-packages/torch/hub.py", line 337, in load
    repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose)

  File "/opt/conda/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Not able to load the model from torch hub. Any fix for that required.
torch 1.8.0a0+52ea372

@herculesdynamics
Copy link

Got the same issue as @vermavinay982 above. torch 1.9.0 python 3.8.10. Wondering if it's something I'm doing or if we have server issues. Thanks.

Traceback (most recent call last): File "pyv.py", line 27, in <module> model = torch.hub.load("facebookresearch/pytorchvideo", model=model_name, pretrained=True) File "/usr/lib/python3/dist-packages/torch/hub.py", line 362, in load repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose) File "/usr/lib/python3/dist-packages/torch/hub.py", line 169, in _get_cache_or_reload download_url_to_file(url, cached_file, progress=False) File "/usr/lib/python3/dist-packages/torch/hub.py", line 419, in download_url_to_file u = urlopen(req) File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.8/urllib/request.py", line 531, in open response = meth(req, response) File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response response = self.parent.error( File "/usr/lib/python3.8/urllib/request.py", line 563, in error result = self._call_chain(*args) File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(*args) File "/usr/lib/python3.8/urllib/request.py", line 755, in http_error_302 return self.parent.open(new, timeout=req.timeout) File "/usr/lib/python3.8/urllib/request.py", line 531, in open response = meth(req, response) File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response response = self.parent.error( File "/usr/lib/python3.8/urllib/request.py", line 569, in error return self._call_chain(*args) File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(*args) File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found

@vermavinay982
Copy link

vermavinay982 commented Sep 25, 2021

@herculesdynamics what model are you trying to download?
I have fixed my issue, hope it helps you too. I went to this /opt/conda/lib/python3.8/site-packages/torch/hub.py. Opened in nano. Changed MASTER_BRANCH to 'main' - saved the code - went again and my models were loading perfectly.
Its just a branch name conflict as the master is changed to main - but in code branch was master so Models cant be loaded.

# file: /opt/conda/lib/python3.8/site-packages/torch/hub.py
MASTER_BRANCH = 'master' # CHANGE THIS TO 'main'
ENV_GITHUB_TOKEN = 'GITHUB_TOKEN'
ENV_TORCH_HOME = 'TORCH_HOME'

To find your hub.py you can do the following.
Open terminal, open python

>>> import torch 
>>> torch.hub
<module 'torch.hub' from '/opt/conda/lib/python3.8/site-packages/torch/hub.py'>

This is the location of hub file, just do nano /opt/conda/lib/python3.8/site-packages/torch/hub.py and change.

@ptrblck Can you confirm this? I was using 1.8.1, and upgraded to 1.9.1 too, both having master branch as default. I have checked the current code in master branch of torch the error is fixed, It will check for main first then master

@herculesdynamics
Copy link

@vermavinay982 thank you very much, that actually worked for me as well! I was able to download slowfast_r50 now.

@zacharygilbert437
Copy link

Can verify @herculesdynamics solution works. Thank you much!

@AkanimohOD19A
Copy link

AkanimohOD19A commented Jul 17, 2022

Followed @vermavinay982 instructions but the issue still persists.

Here is the error message:
Loaded Dependencies. /n
Downloading: "https://github.com/utralytics/yolov5/archive/main.zip" to C:\Users\PC/.cache\torch\hub\main.zip
Traceback (most recent call last):
File "C:\Users\PC\PycharmProjects\ComputerVision\DROWSINESS\realtime_drowsiness.py", line 15, in
model = torch.hub.load('utralytics/yolov5',
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\site-packages\torch\hub.py", line 337, in load
repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, verbose)
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\site-packages\torch\hub.py", line 144, in _get_cache_or_reload
download_url_to_file(url, cached_file, progress=False)
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\site-packages\torch\hub.py", line 394, in download_url_to_file
u = urlopen(req)
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\urllib\request.py", line 561, in error
return self._call_chain(*args)
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "C:\Users\PC\Anaconda3\envs\tf-gpu2.5\lib\urllib\request.py", line 641, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Kindly assist. Thanks

I'm tried the following for custom models:
model = torch.hub.load('utralytics/yolov5:master', 'custom', path=run_model_path)

model = torch.hub.load('utralytics/yolov5:main', 'custom', path=run_model_path)

Both throw the same error.

@vermavinay982
Copy link

import torch
# works perfectly
model = torch.hub.load('ultralytics/yolov5', 'yolov5m') 

# works but requires parameters, including path for pt file
model = torch.hub.load('ultralytics/yolov5', 'custom', path='path/to/best.pt', source='local') 

@AkanimohOD19A You can try by pointing it to your .pt file, it is working for me.

@AkanimohOD19A
Copy link

@vermavinay982 thanks so much, resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: hub triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests