`save_model` requires h5py with keras


I'm using Keras with Tensorflow backend. I've tried to save with:'my_model'). I received an error message:

save_model requires h5py

I've read in StackOverflow, but I have h5py preinstalled.

Do you have any idea, how to solve the problem?

Are you sure you have it installed in the version of Python that you are running it with?

First I tried this:

# serialize model to JSON
model_json = model.to_json()
with open("model.json", "w") as json_file:
# serialize weights to HDF5
model.save_weights("model")  # !!!!!!
print("Saved model to disk")

And it doesn't work.

Then I tried this

# serialize model to YAML
model_yaml = model.to_yaml()
with open("model.yaml", "w") as yaml_file:
# serialize weights to HDF5
print("Saved model to disk")

And it started to function, but also the first code lines. I don't see any difference, but now is working.

just to double check- where did you install h5py to? and how are you running this?

Like glenn said- perhaps you installed it into a version of python that is not the version of python that you are running?

I didn't install anything. The only difference is that first saved the model to yaml, then to h5. I tested later saving model to json and it started working. There may be some little bug in the function calling sequence.

Could it be that in one code example above you have "model" and in the other, you have "model.h5"?