简体   繁体   中英

Cannot open keras model file as h5

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.

Ps: you could try yourself getting the model from here

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM