Home > Enterprise >  Cannot open keras model file as h5
Cannot open keras model file as h5

Time:01-25

I have a .h5 file in the following path, it is a model file regarding a pre-trained CNN (model weights).

>>> import os
>>> os.path.isfile('/home/me/my_env_project/attack/models/model_keras.h5')
True

The source code above says the model file exists, so I could obviously load it with TensorFlow. However, after running the below commands

>>> import tensorflow
>>> model=tensorflow.keras.models.load_model('/home/me/my_env_project/attack/models/model_keras.h5')

I have the following error:

  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/me/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py", line 186, in load_model
    loader_impl.parse_saved_model(filepath)
  File "/home/me/.local/lib/python3.6/site-packages/tensorflow/python/saved_model/loader_impl.py", line 113, in parse_saved_model
    constants.SAVED_MODEL_FILENAME_PB))
OSError: SavedModel file does not exist at: /home/me/my_env_project/attack/models/model_keras.h5/{saved_model.pbtxt|saved_model.pb}

Is this something related to the version I am using? my Tensorflow version is 2.3.0.

P.s: you could try yourself getting the model from here

CodePudding user response:

I can imagine the problem is that the model you are downloading is corrupt. If you look into the file, you see the following content:

<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>

I do not think it is correct. It is definitely not the h5 format.

  •  Tags:  
  • Related