Torchvision URL error when loading pretrained model


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

But I get the following error:

Downloading: "" to /home/.torch/models/vgg19-dcbb9e9d.pth
Traceback (most recent call last):
  File "", line 19, in <module>
  File "/home/some-folder/", line 18, in trainer
    cnn = torchvision.models.vgg19(pretrained=True)
  File "/home/pytorch/local/lib/python2.7/site-packages/torchvision/models/", line 141, in vgg19
  File "/home/pytorch/local/lib/python2.7/site-packages/torch/utils/", 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/", line 61, in _download_url_to_file
    u = urlopen(url)
  File "/usr/lib/python2.7/", line 127, in urlopen
    return, data, timeout)
  File "/usr/lib/python2.7/", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/", 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.


I could download the file just now without problem. Can you check if the following link works for you?

1 Like

I got the same issue, but wget works fine.


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

cannot download from API call, but can download via wget

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


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)

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.