0

I previously trained and saved a keras model for a Neural Network, but whenever I try to load it I get this error.

Traceback (most recent call last):
File "<input>", line 1, in <module>
  File "C:\Users\gio-c\PycharmProjects\NN\venv\lib\site-packages\keras\models.py", line 260, in load_model
    f = h5py.File(filepath, mode='r')
  File "C:\Users\gio-c\PycharmProjects\NN\venv\lib\site-packages\h5py\_hl\files.py", line 269, in __init__
    self._swmr_mode = True
  File "C:\Users\gio-c\PycharmProjects\NN\venv\lib\site-packages\h5py\_hl\files.py", line 99, in make_fid
    else:
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

In the code, I just load keras and import the file. I already tried to recreate the file and nothing happened. Any ideas on how to solve the problem?

  • 1
    Make sure the file name is correct and it's readable – Maxim May 14 '18 at 08:20
  • Please post your code. – Mihai Alexandru-Ionut May 14 '18 at 08:21
  • The file name is correct. The code is simply `import keras model = keras.models.load_model("NNSentiment.h5")` – Giovanni Carnovale May 14 '18 at 08:49
  • run the file command on your .h5 file and report back the results. – Dr. Snoopy May 14 '18 at 09:11
  • Welcome to Stackoverflow. Before asking questions, please first do some research (using a search engine or the search bar in stackoverflow) related to the problem or the error you have. This question has already been [asked and answered](https://stackoverflow.com/q/38089950/2099607) on SO. If the solution provided there does not solve your problem, then ask your question and add any additional information that helps other people to answer your question (e.g. what you have done, what you have checked, etc.). – today May 14 '18 at 09:16
  • I already saw that thread but it wasn't quite helpful. I spent the last two days looking for a solution online, sigh By the way, could you elaborate on the file command? I'm not entirely sure of what you mean – Giovanni Carnovale May 14 '18 at 09:41
  • Ah, you are running Windows. The file command analyzes a file and tells you what it is. The error just points that the HDF5 file is either corrupt or is not a HDF5 file, so I am not sure what kind of answer you are expecting. – Dr. Snoopy May 14 '18 at 11:41
  • I tried to run the file command on Ubuntu and the result was `NN_Sentiment.h5: data` – Giovanni Carnovale May 15 '18 at 00:01
  • The HDF5 file is corrupted or whatever, just delete it and make a new HDF5 file. – lambda Feb 08 '19 at 05:48

1 Answers1

1

Probably your *.h5 file format is wrong or not recognised by h5py

Cristea Bogdan
  • 116
  • 1
  • 11