I use model_conv = models.resnet18(pretrained=True) and The following error occurs

username: tinger1234
cooked: <h2>Downloading: “<a href="https://download.pytorch.org/models/resnet18-5c106cde.pth" rel="nofollow noopener">https://download.pytorch.org/models/resnet18-5c106cde.pth</a>” to /root/.cache/torch/checkpoints/resnet18-5c106cde.pth</h2>
<p>gaierror                                  Traceback (most recent call last)<br>
/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)<br>
1318                 h.request(req.get_method(), req.selector, req.data, headers,<br>
-&gt; 1319                           encode_chunked=req.has_header(‘Transfer-encoding’))<br>
1320             except OSError as err: # timeout error</p>
<p>/opt/conda/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked)<br>
1251         “”“Send a complete request to the server.”""<br>
-&gt; 1252         self._send_request(method, url, body, headers, encode_chunked)<br>
1253</p>
<p>/opt/conda/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)<br>
1297             body = _encode(body, ‘body’)<br>
-&gt; 1298         self.endheaders(body, encode_chunked=encode_chunked)<br>
1299</p>
<p>/opt/conda/lib/python3.7/http/client.py in endheaders(self, message_body, encode_chunked)<br>
1246             raise CannotSendHeader()<br>
-&gt; 1247         self._send_output(message_body, encode_chunked=encode_chunked)<br>
1248</p>
<p>/opt/conda/lib/python3.7/http/client.py in _send_output(self, message_body, encode_chunked)<br>
1025         del self._buffer[:]<br>
-&gt; 1026         self.send(msg)<br>
1027</p>
<p>/opt/conda/lib/python3.7/http/client.py in send(self, data)<br>
965             if self.auto_open:<br>
–&gt; 966                 self.connect()<br>
967             else:</p>
<p>/opt/conda/lib/python3.7/http/client.py in connect(self)<br>
1413<br>
-&gt; 1414             super().connect()<br>
1415</p>
<p>/opt/conda/lib/python3.7/http/client.py in connect(self)<br>
937         self.sock = self._create_connection(<br>
–&gt; 938             (self.host,self.port), self.timeout, self.source_address)<br>
939         self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)</p>
<p>/opt/conda/lib/python3.7/socket.py in create_connection(address, timeout, source_address)<br>
706     err = None<br>
–&gt; 707     for res in getaddrinfo(host, port, 0, SOCK_STREAM):<br>
708         af, socktype, proto, canonname, sa = res</p>
<p>/opt/conda/lib/python3.7/socket.py in getaddrinfo(host, port, family, type, proto, flags)<br>
751     addrlist = []<br>
–&gt; 752     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):<br>
753         af, socktype, proto, canonname, sa = res</p>
<p>gaierror: [Errno -3] Temporary failure in name resolution</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>URLError                                  Traceback (most recent call last)<br>
 in <br>
----&gt; 1 model = SVHN_Model1()<br>
2 criterion = nn.CrossEntropyLoss()<br>
3 optimizer = torch.optim.Adam(model.parameters(), 0.001)<br>
4 best_loss = 1000.0<br>
5</p>
<p> in <strong>init</strong>(self)<br>
6         super(SVHN_Model1, self).<strong>init</strong>()<br>
7<br>
----&gt; 8         model_conv = models.resnet18(pretrained=True)<br>
9         model_conv.avgpool = nn.AdaptiveAvgPool2d(1)<br>
10         model_conv = nn.Sequential(*list(model_conv.children())[:-1])</p>
<p>/opt/conda/lib/python3.7/site-packages/torchvision/models/resnet.py in resnet18(pretrained, progress, **kwargs)<br>
239     “”"<br>
240     return _resnet(‘resnet18’, BasicBlock, [2, 2, 2, 2], pretrained, progress,<br>
–&gt; 241                    **kwargs)<br>
242<br>
243</p>
<p>/opt/conda/lib/python3.7/site-packages/torchvision/models/resnet.py in _resnet(arch, block, layers, pretrained, progress, **kwargs)<br>
225     if pretrained:<br>
226         state_dict = load_state_dict_from_url(model_urls[arch],<br>
–&gt; 227                                               progress=progress)<br>
228         model.load_state_dict(state_dict)<br>
229     return model</p>
<p>/opt/conda/lib/python3.7/site-packages/torch/hub.py in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash)<br>
493         sys.stderr.write(‘Downloading: “{}” to {}\n’.format(url, cached_file))<br>
494         hash_prefix = HASH_REGEX.search(filename).group(1) if check_hash else None<br>
–&gt; 495         download_url_to_file(url, cached_file, hash_prefix, progress=progress)<br>
496<br>
497     # Note: extractall() defaults to overwrite file if exists. No need to clean up beforehand.</p>
<p>/opt/conda/lib/python3.7/site-packages/torch/hub.py in download_url_to_file(url, dst, hash_prefix, progress)<br>
392     # We use a different API for python2 since urllib(2) doesn’t recognize the CA<br>
393     # certificates in older Python<br>
–&gt; 394     u = urlopen(url)<br>
395     meta = u.info()<br>
396     if hasattr(meta, ‘getheaders’):</p>
<p>/opt/conda/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)<br>
220     else:<br>
221         opener = _opener<br>
–&gt; 222     return opener.open(url, data, timeout)<br>
223<br>
224 def install_opener(opener):</p>
<p>/opt/conda/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)<br>
523             req = meth(req)<br>
524<br>
–&gt; 525         response = self._open(req, data)<br>
526<br>
527         # post-process response</p>
<p>/opt/conda/lib/python3.7/urllib/request.py in _open(self, req, data)<br>
541         protocol = req.type<br>
542         result = self._call_chain(self.handle_open, protocol, protocol +<br>
–&gt; 543                                   ‘_open’, req)<br>
544         if result:<br>
545             return result</p>
<p>/opt/conda/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)<br>
501         for handler in handlers:<br>
502             func = getattr(handler, meth_name)<br>
–&gt; 503             result = func(*args)<br>
504             if result is not None:<br>
505                 return result</p>
<p>/opt/conda/lib/python3.7/urllib/request.py in https_open(self, req)<br>
1360         def https_open(self, req):<br>
1361             return self.do_open(http.client.HTTPSConnection, req,<br>
-&gt; 1362                 context=self._context, check_hostname=self.<em>check_hostname)<br>
1363<br>
1364         https_request = AbstractHTTPHandler.do_request</em></p>
<p>/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)<br>
1319                           encode_chunked=req.has_header(‘Transfer-encoding’))<br>
1320             except OSError as err: # timeout error<br>
-&gt; 1321                 raise URLError(err)<br>
1322             r = h.getresponse()<br>
1323         except:</p>
<p>URLError: &lt;urlopen error [Errno -3] Temporary failure in name resolution&gt;</p>

username: tinger1234
cooked: <p>Please help me<br>
I have used the way of "model_urls[‘resnet18’] = model_urls[‘resnet18’].replace(‘https://’, ‘http://’)<br>
resnet18 = torchvision.models.resnet18(pretrained=True)” But  it is little use.I’m using the Windows system, and Google didn’t work when it was running on kaggle</p>

username: ptrblck
cooked: <p>Were you able to download the pretrained model before?<br>
If so, did you change anything in your current network setup?</p>
<aside class="quote no-group" data-username="tinger1234" data-post="2" data-topic="83303">
<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/t/76d3ee/48.png" class="avatar"> tinger1234:</div>
<blockquote>
<p>and Google didn’t work when it was running on kaggle</p>
</blockquote>
</aside>
<p>Could you explain this statement a bit?<br>
Are you running the code in a Kaggle notebook?<br>
If so, could you check, if Kaggle uses some internet connection limitations or settings?</p>

username: nato16
cooked: <p>I could not load the pretrained model from kaggle, but later i found out the Kaggle already download all the pretrained pytorch models, what you need to do is to add it to your list. First create the model without weight, then load it with the pretrained weight file.</p>