URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

Hi everyone!

What I’m doing

I am using restnet26d model to train 512 png images in RSNA Mammography Breast Cancer but it gives me “urlopen error”.

Error:

Downloading: “https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/resnet26d-69e92c46.pth” to /root/.cache/torch/hub/checkpoints/resnet26d-69e92c46.pth

gaierror Traceback (most recent call last)
/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1349 h.request(req.get_method(), req.selector, req.data, headers,
→ 1350 encode_chunked=req.has_header(‘Transfer-encoding’))
1351 except OSError as err: # timeout error

/opt/conda/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked)
1280 “”“Send a complete request to the server.”“”
→ 1281 self._send_request(method, url, body, headers, encode_chunked)
1282

/opt/conda/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1326 body = _encode(body, ‘body’)
→ 1327 self.endheaders(body, encode_chunked=encode_chunked)
1328

/opt/conda/lib/python3.7/http/client.py in endheaders(self, message_body, encode_chunked)
1275 raise CannotSendHeader()
→ 1276 self._send_output(message_body, encode_chunked=encode_chunked)
1277

/opt/conda/lib/python3.7/http/client.py in _send_output(self, message_body, encode_chunked)
1035 del self._buffer[:]
→ 1036 self.send(msg)
1037

/opt/conda/lib/python3.7/http/client.py in send(self, data)
975 if self.auto_open:
→ 976 self.connect()
977 else:

/opt/conda/lib/python3.7/http/client.py in connect(self)
1442
→ 1443 super().connect()
1444

/opt/conda/lib/python3.7/http/client.py in connect(self)
947 self.sock = self._create_connection(
→ 948 (self.host,self.port), self.timeout, self.source_address)
949 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

/opt/conda/lib/python3.7/socket.py in create_connection(address, timeout, source_address)
706 err = None
→ 707 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
708 af, socktype, proto, canonname, sa = res

/opt/conda/lib/python3.7/socket.py in getaddrinfo(host, port, family, type, proto, flags)
751 addrlist = []
→ 752 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
753 af, socktype, proto, canonname, sa = res

gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

URLError Traceback (most recent call last)
/tmp/ipykernel_23/3606048960.py in
----> 1 learn = vision_learner(dls, ‘resnet26d’, metrics=error_rate, pretrained=True)

/opt/conda/lib/python3.7/site-packages/fastai/vision/learner.py in vision_learner(dls, arch, normalize, n_out, pretrained, loss_func, opt_func, lr, splitter, cbs, metrics, path, model_dir, wd, wd_bn_bias, train_bn, moms, cut, init, custom_head, concat_pool, pool, lin_ftrs, ps, first_bn, bn_final, lin_first, y_range, **kwargs)
222 n_in = kwargs[‘n_in’] if ‘n_in’ in kwargs else 3
223 if isinstance(arch, str):
→ 224 model,cfg = create_timm_model(arch, n_out, default_split, pretrained, **model_args)
225 if normalize: _timm_norm(dls, cfg, pretrained, n_in)
226 else:

/opt/conda/lib/python3.7/site-packages/fastai/vision/learner.py in create_timm_model(arch, n_out, cut, pretrained, n_in, init, custom_head, concat_pool, pool, lin_ftrs, ps, first_bn, bn_final, lin_first, y_range, **kwargs)
181 concat_pool=True, pool=True, lin_ftrs=None, ps=0.5, first_bn=True, bn_final=False, lin_first=False, y_range=None, **kwargs):
182 “Create custom architecture using arch, n_in and n_out from the timm library”
→ 183 model = timm.create_model(arch, pretrained=pretrained, num_classes=0, in_chans=n_in, **kwargs)
184 body = TimmBody(model, pretrained, None, n_in)
185 nf = body.model.num_features

/opt/conda/lib/python3.7/site-packages/timm/models/factory.py in create_model(model_name, pretrained, pretrained_cfg, checkpoint_path, scriptable, exportable, no_jit, **kwargs)
69 create_fn = model_entrypoint(model_name)
70 with set_layer_config(scriptable=scriptable, exportable=exportable, no_jit=no_jit):
—> 71 model = create_fn(pretrained=pretrained, pretrained_cfg=pretrained_cfg, **kwargs)
72
73 if checkpoint_path:

/opt/conda/lib/python3.7/site-packages/timm/models/resnet.py in resnet26d(pretrained, **kwargs)
811 “”"
812 model_args = dict(block=Bottleneck, layers=[2, 2, 2, 2], stem_width=32, stem_type=‘deep’, avg_down=True, **kwargs)
→ 813 return _create_resnet(‘resnet26d’, pretrained, **model_args)
814
815

/opt/conda/lib/python3.7/site-packages/timm/models/resnet.py in _create_resnet(variant, pretrained, **kwargs)
734
735 def _create_resnet(variant, pretrained=False, **kwargs):
→ 736 return build_model_with_cfg(ResNet, variant, pretrained, **kwargs)
737
738

/opt/conda/lib/python3.7/site-packages/timm/models/helpers.py in build_model_with_cfg(model_cls, variant, pretrained, pretrained_cfg, model_cfg, feature_cfg, pretrained_strict, pretrained_filter_fn, pretrained_custom_load, kwargs_filter, **kwargs)
555 in_chans=kwargs.get(‘in_chans’, 3),
556 filter_fn=pretrained_filter_fn,
→ 557 strict=pretrained_strict)
558
559 # Wrap the model in a feature extraction module if enabled

/opt/conda/lib/python3.7/site-packages/timm/models/helpers.py in load_pretrained(model, pretrained_cfg, num_classes, in_chans, filter_fn, strict)
247 _logger.info(f’Loading pretrained weights from url ({pretrained_loc})‘)
248 state_dict = load_state_dict_from_url(
→ 249 pretrained_loc, map_location=‘cpu’, progress=_DOWNLOAD_PROGRESS, check_hash=_CHECK_HASH)
250 elif load_from == ‘hf-hub’:
251 _logger.info(f’Loading pretrained weights from Hugging Face hub ({pretrained_loc})’)

/opt/conda/lib/python3.7/site-packages/torch/hub.py in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash, file_name)
589 r = HASH_REGEX.search(filename) # r is Optional[Match[str]]
590 hash_prefix = r.group(1) if r else None
→ 591 download_url_to_file(url, cached_file, hash_prefix, progress=progress)
592
593 if _is_legacy_zip_format(cached_file):

/opt/conda/lib/python3.7/site-packages/torch/hub.py in download_url_to_file(url, dst, hash_prefix, progress)
455 file_size = None
456 req = Request(url, headers={“User-Agent”: “torch.hub”})
→ 457 u = urlopen(req)
458 meta = u.info()
459 if hasattr(meta, ‘getheaders’):

/opt/conda/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
→ 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):

/opt/conda/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
523 req = meth(req)
524
→ 525 response = self._open(req, data)
526
527 # post-process response

/opt/conda/lib/python3.7/urllib/request.py in _open(self, req, data)
541 protocol = req.type
542 result = self._call_chain(self.handle_open, protocol, protocol +
→ 543 ‘_open’, req)
544 if result:
545 return result

/opt/conda/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
501 for handler in handlers:
502 func = getattr(handler, meth_name)
→ 503 result = func(*args)
504 if result is not None:
505 return result

/opt/conda/lib/python3.7/urllib/request.py in https_open(self, req)
1391 def https_open(self, req):
1392 return self.do_open(http.client.HTTPSConnection, req,
→ 1393 context=self._context, check_hostname=self.check_hostname)
1394
1395 https_request = AbstractHTTPHandler.do_request

/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1350 encode_chunked=req.has_header(‘Transfer-encoding’))
1351 except OSError as err: # timeout error
→ 1352 raise URLError(err)
1353 r = h.getresponse()
1354 except:

URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

Any one please tell me why this happen and how to fix it.

Regards!
Salma