pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
16.11k stars 6.94k forks source link

Cannot download pretrained models #3940

Closed EdHeredia closed 3 years ago

EdHeredia commented 3 years ago

🐛 Bug

I am trying to download pre-trained models from torchvision using both conventional PyTorch code and also manually using wget. In both cases the download procedure stalls and fails to finish.

To Reproduce

Using conventional code: from torchvision import models model = models.resnet50(pretrained=True)

Using wget: wget -c https://download.pytorch.org/models/resnet50-0676ba61.pth Also tried using http instead of https

Using conventional code the process stalls and never finishes. Using wget (http or https) I can see that the error message is 'failed: connection timed out'. Using wget I can see that my machine keeps trying to connect but it gets the same error message. The servers are probably down or unreachable.

Also, my internet connection shows good speed and no problems. For example, I had no problem downloading the collect_env.py script recommended below.

Environment

Please copy and paste the output from our environment collection script (or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

PyTorch version: 1.7.1 Is debug build: False CUDA used to build PyTorch: 10.2 ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64) GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Clang version: Could not collect CMake version: version 3.10.2 Libc version: glibc-2.10

Python version: 3.7 (64-bit runtime) Python platform: Linux-5.4.0-73-generic-x86_64-with-debian-buster-sid Is CUDA available: True CUDA runtime version: 10.0.130 GPU models and configuration: GPU 0: GeForce RTX 2070 with Max-Q Design Nvidia driver version: 460.73.01 cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5 HIP runtime version: N/A MIOpen runtime version: N/A

Versions of relevant libraries: [pip3] numpy==1.19.2 [pip3] torch==1.7.1 [pip3] torchaudio==0.7.0a0+a853dff [pip3] torchfile==0.1.0 [pip3] torchnet==0.0.4 [pip3] torchsummary==1.5.1 [pip3] torchvision==0.8.2 [conda] blas 1.0 mkl
[conda] cudatoolkit 10.2.89 h8f6ccaa_8 conda-forge [conda] mkl 2020.2 256
[conda] mkl-service 2.3.0 py37h8f50634_2 conda-forge [conda] mkl_fft 1.2.1 py37h54f3939_0
[conda] mkl_random 1.2.0 py37h9fdb41a_1 conda-forge [conda] numpy 1.19.2 py37h54aff64_0
[conda] numpy-base 1.19.2 py37hfa32c7d_0
[conda] pytorch 1.7.1 py3.7_cuda10.2.89_cudnn7.6.5_0 pytorch [conda] torchaudio 0.7.2 py37 pytorch [conda] torchfile 0.1.0 pypi_0 pypi [conda] torchnet 0.0.4 pypi_0 pypi [conda] torchsummary 1.5.1 pypi_0 pypi [conda] torchvision 0.8.2 py37_cu102 pytorch

EdHeredia commented 3 years ago

One more observation. If I click on the link to invoke a browser-based download, I can get the pth file in seconds. I can manually move this file to the cache and make it work. The problem is that this operation should work using standard PyTorch code.

oke-aditya commented 3 years ago

Hi @EdHeredia ! I tried reproducing the issue. But unfortunately I couldn't.

wget -c https://download.pytorch.org/models/resnet50-0676ba61.pth worked fine for me.

Also I'm able to download using torchvision. My environment tested is also similar, I'm using Ubuntu 20.04.2 LTS, Python 3.6 I think it should work fine

>>> from torchvision import models
>>> model = models.resnet50(pretrained=True)

A rare chance is that the server might be unavailable for a slight while and you faced a one-off error (oops) Another possible issue can be VPN / firewall / any such configs that might block connections.

EdHeredia commented 3 years ago

Hi @oke-aditya Thanks for the quick response. I did some additional tests: 1) Tested on a second Ubuntu 18.04 machine in the same network and I see the same issue 2) Tested on a Mac (same network) and it works fine. The models get downloaded in seconds

Also, I downloaded models before to the Ubuntu machines, so the problem could be related to recent OS or module updates?

oke-aditya commented 3 years ago

As such I cannot confirm any OS related issues :sweat_smile: If possible you can try switching network for ubuntu machine and try again. Perhaps that might work.

But overall I don't see this to be really an issue pertaining to torchvision. I can suggest an alternative if you really don't have network.

On Ubuntu

You can also manually download the weights and place in

/home/usename/.cache/torch/hub/checkpoints/

E.g. in my case assume my username is abc and I download resnet50 weights.

/home/abc/.cache/torch/hub/checkpoints/resnet50-0676ba61.pth

This would allow you to load pretrained weights using models.resnet50(pretrained=True).

Feel free to re-open!

EdHeredia commented 3 years ago

Thanks @oke-aditya. Yes, I agree it doesn't seem to be a torchvision problem. For now I can manually download the pretrained models and move them to the cache.

I will continue investigating and reopen if appropriate.