keras icon indicating copy to clipboard operation
keras copied to clipboard

Error on tf.keras.applications.EfficientNetB7() seems serverside

Open swupel opened this issue 1 year ago • 1 comments

Running tf 2.13.0 and the follwoing code:

vgg = tf.keras.applications.EfficientNetB7(input_shape=IMG_SHAPE,include_top=False,weights='imagenet')

This being under normal conditions (~50 mbit up/download speed and no other DNS related issues) throws this error:

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)
File /opt/conda/lib/python3.10/site-packages/keras/utils/data_utils.py:346, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    345 try:
--> 346     urlretrieve(origin, fpath, DLProgbar())
    347 except urllib.error.HTTPError as e:

File /opt/conda/lib/python3.10/site-packages/keras/utils/data_utils.py:85, in urlretrieve(url, filename, reporthook, data)
     83             break
---> 85 response = urlopen(url, data)
     86 with open(filename, "wb") as fd:

File /opt/conda/lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    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)
    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

File /opt/conda/lib/python3.10/urllib/request.py:536, in OpenerDirector._open(self, req, data)
    535 protocol = req.type
--> 536 result = self._call_chain(self.handle_open, protocol, protocol +
    537                           '_open', req)
    538 if result:

File /opt/conda/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    495 func = getattr(handler, meth_name)
--> 496 result = func(*args)
    497 if result is not None:

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)
   1350 except OSError as err: # timeout error
-> 1351     raise URLError(err)
   1352 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)
Cell In[7], line 4
      1 IMG_SHAPE = IMG_SIZE + (3,)
      3 # Creating the VGG16 model with the specified configuration.
----> 4 vgg = tf.keras.applications.EfficientNetB7(input_shape=IMG_SHAPE,include_top=False,weights='imagenet')
      6 # Set the layers in between to not train
      7 for layer in vgg.layers:

File /opt/conda/lib/python3.10/site-packages/keras/applications/efficientnet.py:815, in EfficientNetB7(include_top, weights, input_tensor, input_shape, pooling, classes, classifier_activation, **kwargs)
    801 @keras_export(
    802     "keras.applications.efficientnet.EfficientNetB7",
    803     "keras.applications.EfficientNetB7",
   (...)
    813     **kwargs,
    814 ):
--> 815     return EfficientNet(
    816         2.0,
    817         3.1,
    818         600,
    819         0.5,
    820         model_name="efficientnetb7",
    821         include_top=include_top,
    822         weights=weights,
    823         input_tensor=input_tensor,
    824         input_shape=input_shape,
    825         pooling=pooling,
    826         classes=classes,
    827         classifier_activation=classifier_activation,
    828         **kwargs,
    829     )

File /opt/conda/lib/python3.10/site-packages/keras/applications/efficientnet.py:457, in EfficientNet(width_coefficient, depth_coefficient, default_size, dropout_rate, drop_connect_rate, depth_divisor, activation, blocks_args, model_name, include_top, weights, input_tensor, input_shape, pooling, classes, classifier_activation)
    455         file_hash = WEIGHTS_HASHES[model_name[-2:]][1]
    456     file_name = model_name + file_suffix
--> 457     weights_path = data_utils.get_file(
    458         file_name,
    459         BASE_WEIGHTS_PATH + file_name,
    460         cache_subdir="models",
    461         file_hash=file_hash,
    462     )
    463     model.load_weights(weights_path)
    464 elif weights is not None:

File /opt/conda/lib/python3.10/site-packages/keras/utils/data_utils.py:350, in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
    348         raise Exception(error_msg.format(origin, e.code, e.msg))
    349     except urllib.error.URLError as e:
--> 350         raise Exception(error_msg.format(origin, e.errno, e.reason))
    351 except (Exception, KeyboardInterrupt):
    352     if os.path.exists(fpath):

Exception: URL fetch failure on https://storage.googleapis.com/keras-applications/efficientnetb7_notop.h5: None -- [Errno -3] Temporary failure in name resolution```

swupel avatar Dec 21 '23 17:12 swupel

Hi,

Could you please try in the Keras 3 version, You can install Keras 3 using !pip install -U keras and import keras directly.

If you are still facing the issue, could you please provide the reproducible code as well. Thanks!

sachinprasadhs avatar Dec 26 '23 23:12 sachinprasadhs

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Apr 26 '24 01:04 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

github-actions[bot] avatar May 10 '24 01:05 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar May 10 '24 01:05 google-ml-butler[bot]