Everything works fine, except when I want to use transfer learning, please anyone background help me it would save so much time.

I tried to leverage the help of ChatGPT, but it wasn't of much help, and even the solutions didn't work. I also tried to to use different model instead of Resnet18, like efficient and others.

Thank you in advance

The error:

Downloading: "https://download.pytorch.org/models/resnet18-f37072fd.pth" to /root/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth --------------------------------------------------------------------------- `gaierror Traceback (most recent call last) File /opt/conda/lib/python3.10/urllib/request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1347 try: -> 1348 h.request(req.get_method(), req.selector, req.data, headers, 1349 encode_chunked=req.has_header('Transfer-encoding')) 1350 except OSError as err: # timeout error File /opt/conda/lib/python3.10/http/client.py:1283, in HTTPConnection.request(self, method, url, body, headers, encode_chunked) 1282 """Send a complete request to the server.""" -> 1283 self._send_request(method, url, body, headers, encode_chunked) File /opt/conda/lib/python3.10/http/client.py:1329, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked) 1328 body = _encode(body, 'body') -> 1329 self.endheaders(body, encode_chunked=encode_chunked) File /opt/conda/lib/python3.10/http/client.py:1278, in HTTPConnection.endheaders(self, message_body, encode_chunked) 1277 raise CannotSendHeader() -> 1278 self._send_output(message_body, encode_chunked=encode_chunked) File /opt/conda/lib/python3.10/http/client.py:1038, in HTTPConnection._send_output(self, message_body, encode_chunked) 1037 del self._buffer[:] -> 1038 self.send(msg) 1040 if message_body is not None: 1041 1042 # create a consistent interface to message_body File /opt/conda/lib/python3.10/http/client.py:976, in HTTPConnection.send(self, data) 975 if self.auto_open: --> 976 self.connect() 977 else: File /opt/conda/lib/python3.10/http/client.py:1448, in HTTPSConnection.connect(self) 1446 "Connect to a host on a given (SSL) port." -> 1448 super().connect() 1450 if self._tunnel_host: File /opt/conda/lib/python3.10/http/client.py:942, in HTTPConnection.connect(self) 941 sys.audit("http.client.connect", self, self.host, self.port) --> 942 self.sock = self._create_connection( 943 (self.host,self.port), self.timeout, self.source_address) 944 # Might fail in OSs that don't implement TCP_NODELAY File /opt/conda/lib/python3.10/socket.py:824, in create_connection(address, timeout, source_address) 823 err = None --> 824 for res in getaddrinfo(host, port, 0, SOCK_STREAM): 825 af, socktype, proto, canonname, sa = res File /opt/conda/lib/python3.10/socket.py:955, in getaddrinfo(host, port, family, type, proto, flags) 954 addrlist = [] --> 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 956 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) Cell In[6], line 8 5 resnet_variant = models.resnet18 7 # Instantiate the ResNet model with pre-trained weights ----> 8 model = resnet_variant(pretrained=True) 10 # Access the state dictionary of the model, which contains the weights 11 model_weights = model.state_dict() File /opt/conda/lib/python3.10/site-packages/torchvision/models/_utils.py:142, in kwonly_to_pos_or_kw..wrapper(*args, **kwargs) 135 warnings.warn( 136 f"Using {sequence_to_str(tuple(keyword_only_kwargs.keys()), separate_last='and ')} as positional " 137 f"parameter(s) is deprecated since 0.13 and may be removed in the future. Please use keyword parameter(s) " 138 f"instead." 139 ) 140 kwargs.update(keyword_only_kwargs) --> 142 return fn(*args, **kwargs) File /opt/conda/lib/python3.10/site-packages/torchvision/models/_utils.py:228, in handle_legacy_interface..outer_wrapper..inner_wrapper(*args, **kwargs) 225 del kwargs[pretrained_param] 226 kwargs[weights_param] = default_weights_arg --> 228 return builder(*args, **kwargs) File /opt/conda/lib/python3.10/site-packages/torchvision/models/resnet.py:705, in resnet18(weights, progress, **kwargs) 685 """ResNet-18 from `Deep Residual Learning for Image Recognition `__. 686 687 Args: (...) 701 :members: 702 """ 703 weights = ResNet18_Weights.verify(weights) --> 705 return _resnet(BasicBlock, [2, 2, 2, 2], weights, progress, **kwargs) File /opt/conda/lib/python3.10/site-packages/torchvision/models/resnet.py:301, in _resnet(block, layers, weights, progress, **kwargs) 298 model = ResNet(block, layers, **kwargs) 300 if weights is not None: --> 301 model.load_state_dict(weights.get_state_dict(progress=progress)) 303 return model File /opt/conda/lib/python3.10/site-packages/torchvision/models/_api.py:89, in WeightsEnum.get_state_dict(self, progress) 88 def get_state_dict(self, progress: bool) -> Mapping[str, Any]: ---> 89 return load_state_dict_from_url(self.url, progress=progress) File /opt/conda/lib/python3.10/site-packages/torch/hub.py:746, in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash, file_name) 744 r = HASH_REGEX.search(filename) # r is Optional[Match[str]] 745 hash_prefix = r.group(1) if r else None --> 746 download_url_to_file(url, cached_file, hash_prefix, progress=progress) 748 if _is_legacy_zip_format(cached_file): 749 return _legacy_zip_load(cached_file, model_dir, map_location) File /opt/conda/lib/python3.10/site-packages/torch/hub.py:611, in download_url_to_file(url, dst, hash_prefix, progress) 609 file_size = None 610 req = Request(url, headers={"User-Agent": "torch.hub"}) --> 611 u = urlopen(req) 612 meta = u.info() 613 if hasattr(meta, 'getheaders'): File /opt/conda/lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context) 214 else: 215 opener = _opener --> 216 return opener.open(url, data, timeout) File /opt/conda/lib/python3.10/urllib/request.py:519, in OpenerDirector.open(self, fullurl, data, timeout) 516 req = meth(req) 518 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method()) --> 519 response = self._open(req, data) 521 # post-process response 522 meth_name = protocol+"_response" File /opt/conda/lib/python3.10/urllib/request.py:536, in OpenerDirector._open(self, req, data) 533 return result 535 protocol = req.type --> 536 result = self._call_chain(self.handle_open, protocol, protocol + 537 '_open', req) 538 if result: 539 return result File /opt/conda/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args) 494 for handler in handlers: 495 func = getattr(handler, meth_name) --> 496 result = func(*args) 497 if result is not None: 498 return result File /opt/conda/lib/python3.10/urllib/request.py:1391, in HTTPSHandler.https_open(self, req) 1390 def https_open(self, req): -> 1391 return self.do_open(http.client.HTTPSConnection, req, 1392 context=self._context, check_hostname=self._check_hostname) File /opt/conda/lib/python3.10/urllib/request.py:1351, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args) 1348 h.request(req.get_method(), req.selector, req.data, headers, 1349 encode_chunked=req.has_header('Transfer-encoding')) 1350 except OSError as err: # timeout error -> 1351 raise URLError(err) 1352 r = h.getresponse() 1353 except: URLError: ``

More Jaber H. Jaradat's questions See All
Similar questions and discussions