Torchvision URL error when loading pretrained model

Hi.

I’m trying to load a pretrained vgg16 with:
cnn = torchvision.models.vgg19(pretrained=True)

But I get the following error:

Downloading: "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" to /home/.torch/models/vgg19-dcbb9e9d.pth
Traceback (most recent call last):
  File "main.py", line 19, in <module>
    train.trainer(config)
  File "/home/some-folder/train.py", line 18, in trainer
    cnn = torchvision.models.vgg19(pretrained=True)
  File "/home/pytorch/local/lib/python2.7/site-packages/torchvision/models/vgg.py", line 141, in vgg19
    model.load_state_dict(model_zoo.load_url(model_urls['vgg19']))
  File "/home/pytorch/local/lib/python2.7/site-packages/torch/utils/model_zoo.py", line 56, in load_url
    _download_url_to_file(url, cached_file, hash_prefix)
  File "/home/pytorch/local/lib/python2.7/site-packages/torch/utils/model_zoo.py", line 61, in _download_url_to_file
    u = urlopen(url)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure>

I couldn’t find anything useful with googling.
Thanks in advance.

Sunwoo

I could download the file just now without problem. Can you check if the following link works for you?
https://download.pytorch.org/models/vgg19-dcbb9e9d.pth

1 Like

I got the same issue, but wget https://download.pytorch.org/models/vgg19-dcbb9e9d.pth works fine.

Thanks!

wget https://download.pytorch.org/models/vgg19-dcbb9e9d.pth
and then
mv vgg19-dcbb9e9d.pth ~/.torch/models/
solved the problem.

The line cnn = torchvision.models.vgg19(pretrained=True) still did not work though, before downloading with wget.
Not sure if it’s problem of mine or not…

1 Like

+1
cannot download from API call models.xxx(pretrained=True), but can download via wget

it looks like the SSL is giving some people an issue. changing https:// to http:// should fix it.

3 Likes

Following smth’s suggestion, the following hack worked for me.

import torchvision.models
from torchvision.models.vgg import model_urls

model_urls['vgg16'] = model_urls['vgg16'].replace('https://', 'http://')
vgg16 = torchvision.models.vgg16(pretrained=True)
11 Likes

Use this:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

1 Like

This worked for me while doing the Intro to Pytorch module of Udacity’s Intro to Deep Learning course. Thanks

still not working for me with torchvision 0.5.0 and pytorch 1.4.0
trying vgg19

Which model are you trying to load and what kind of error are you getting?

trying vgg19 in a docker container

Could you post the error message as well as the used PyTorch version, please?

Has anyone fixed this issue. I am trying this on kaggle and it isnt working

Its most probably network issue. I solved it by downloading the checkpoints customly and saving it in the cache directory where it searches the checkpoint before running the model.