I was not able to import resnet50 as mentioned in the video on kaggle so I used the following code:
from tensorflow.keras.applications.resnet50 import resnet50
But when I try to use it later I am getting the following error:
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)
/opt/conda/lib/python3.7/site-packages/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
273 try:
–> 274 urlretrieve(origin, fpath, dl_progress)
275 except urllib.error.HTTPError as e:
/opt/conda/lib/python3.7/site-packages/keras/utils/data_utils.py in urlretrieve(url, filename, reporthook, data)
81
—> 82 response = urlopen(url, data)
83 with open(filename, ‘wb’) as fd:
/opt/conda/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
221 opener = _opener
–> 222 return opener.open(url, data, timeout)
223
/opt/conda/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
524
–> 525 response = self._open(req, data)
526
/opt/conda/lib/python3.7/urllib/request.py in _open(self, req, data)
542 result = self._call_chain(self.handle_open, protocol, protocol +
–> 543 ‘_open’, req)
544 if result:
/opt/conda/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
502 func = getattr(handler, meth_name)
–> 503 result = func(*args)
504 if result is not None:
/opt/conda/lib/python3.7/urllib/request.py in https_open(self, req)
1392 return self.do_open(http.client.HTTPSConnection, req,
-> 1393 context=self._context, check_hostname=self._check_hostname)
1394
/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1351 except OSError as err: # timeout error
-> 1352 raise URLError(err)
1353 r = h.getresponse()
URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
/tmp/ipykernel_33/2683515839.py in
----> 1 model = ResNet50(weights = “imagenet”, input_shape =(224,224,3))
2 model.summary()
/opt/conda/lib/python3.7/site-packages/keras/applications/resnet.py in ResNet50(include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs)
457
458 return ResNet(stack_fn, False, True, ‘resnet50’, include_top, weights,
–> 459 input_tensor, input_shape, pooling, classes, **kwargs)
460
461
/opt/conda/lib/python3.7/site-packages/keras/applications/resnet.py in ResNet(stack_fn, preact, use_bias, model_name, include_top, weights, input_tensor, input_shape, pooling, classes, classifier_activation, **kwargs)
203 BASE_WEIGHTS_PATH + file_name,
204 cache_subdir=‘models’,
–> 205 file_hash=file_hash)
206 model.load_weights(weights_path)
207 elif weights is not None:
/opt/conda/lib/python3.7/site-packages/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
276 raise Exception(error_msg.format(origin, e.code, e.msg))
277 except urllib.error.URLError as e:
–> 278 raise Exception(error_msg.format(origin, e.errno, e.reason))
279 except (Exception, KeyboardInterrupt) as e:
280 if os.path.exists(fpath):
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/keras-applications/resnet/resnet50_weights_tf_dim_ordering_tf_kernels.h5: None – [Errno -3] Temporary failure in name resolution