Torchvision URL error when loading pretrained model

username: stacked.twix
cooked: <p>Hi.</p>
<p>I’m trying to load a pretrained vgg16 with:<br>
<code>cnn = torchvision.models.vgg19(pretrained=True)</code></p>
<p>But I get the following error:</p>
<pre><code>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 &lt;module&gt;
    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: &lt;urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure&gt;
</code></pre>
<p>I couldn’t find anything useful with googling.<br>
Thanks in advance.</p>
<p>Sunwoo</p>

username: fmassa
cooked: <p>I could download the file just now without problem. Can you check if the following link works for you?<br>
<a href="https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" class="onebox" target="_blank">https://download.pytorch.org/models/vgg19-dcbb9e9d.pth</a></p>

username: sunshineatnoon
cooked: <aside class="quote no-group" data-username="fmassa" data-post="2" data-topic="2544">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/fmassa/48/58_2.png" class="avatar"> fmassa:</div>
<blockquote>
<p><a href="https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" rel="noopener nofollow ugc">https://download.pytorch.org/models/vgg19-dcbb9e9d.pth</a></p>
</blockquote>
</aside>
<p>I got the same issue, but <code>wget https://download.pytorch.org/models/vgg19-dcbb9e9d.pth</code> works fine.</p>

username: stacked.twix
cooked: <p>Thanks!</p>
<p><code>wget https://download.pytorch.org/models/vgg19-dcbb9e9d.pth</code><br>
and then<br>
<code>mv vgg19-dcbb9e9d.pth ~/.torch/models/</code><br>
solved the problem.</p>
<p>The line <code>cnn = torchvision.models.vgg19(pretrained=True)</code> still did not work though, before downloading with <code>wget</code>.<br>
Not sure if it’s problem of mine or not…</p>

username: handesy
cooked: <p>+1<br>
cannot download from API call <code>models.xxx(pretrained=True)</code>, but can download via wget</p>

username: smth
cooked: <p>it looks like the SSL is giving some people an issue. changing https:// to http:// should fix it.</p>

username: petered
cooked: <p>Following smth’s suggestion, the following hack worked for me.</p>
<pre><code>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)</code></pre>

username: Gagan_Ganapathy
cooked: <p>Use this:</p>
<p>import ssl</p>
<p>ssl._create_default_https_context = ssl._create_unverified_context</p>

username: KingCyrus
cooked: <p>This worked for me while doing the Intro to Pytorch module of Udacity’s Intro to Deep Learning course. Thanks</p>

username: Vaibhav_Baswal
cooked: <aside class="quote no-group" data-username="petered" data-post="7" data-topic="2544">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/p/6a8cbe/48.png" class="avatar"> petered:</div>
<blockquote>
<pre><code class="lang-auto">model_urls['vgg16'] = model_urls['vgg16'].replace('https://', 'http://')
vgg16 = torchvision.models.vgg16(pretrained=True)
</code></pre>
</blockquote>
</aside>
<p>still not working for me with torchvision 0.5.0 and pytorch 1.4.0<br>
trying vgg19</p>

username: ptrblck
cooked: <p>Which model are you trying to load and what kind of error are you getting?</p>

username: Vaibhav_Baswal
cooked: <p>trying vgg19 in a docker container</p>

username: ptrblck
cooked: <p>Could you post the error message as well as the used PyTorch version, please?</p>

username: Aryaman_Sriram
cooked: <p>Has anyone fixed this issue. I am trying this on kaggle and it isnt working</p>

username: Vaibhav_Baswal
cooked: <p>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.</p>