Search code examples
pythonkeras

ImportError: `load_model` requires h5py when loading hdf5


I saved Keras model in hdf5 format as follows:

from keras.callbacks import ModelCheckpoint
filepath="keras_ltsm_dep_model2.hdf5"
checkpointer = ModelCheckpoint(filepath, 
                               monitor='val_acc',
                               verbose=1,
                               save_best_only=True,
                               mode='max')

Then I tried to load this model in another program as follows:

from keras.models import load_model
model = load_model('keras_ltsm_arr_model_081.hdf5')

Then I got the following error:

ImportError: `load_model` requires h5py

How should I load my model saved in hdf5 format?


Solution

  • Did you install h5py lib?

    Try this:

    1. sudo apt-get install libhdf5
    2. sudo pip install h5py

    If it's not working, maybe you also need to install cython as well (you can check if you already have it). If it happens, do: sudo pip install cython