After Training, I saved Both Keras whole Model and Only Weights using
model.save_weights(MODEL_WEIGHTS) and model.save(MODEL_NAME)
Models
This is probably due to a model saved from a different version of keras. I got the same problem when loading a model generated by tensorflow.keras (which is similar to keras 2.1.6 for tf 1.12 I think) from keras 2.2.6.
You can load the weights with model.load_weights
and resave the complete model from the keras version you want to use.
For me it was the version of h5py that was superior to my previous build.
Fixed it by setting to 2.10.0
.
For me the solution was downgrading the h5py
package (in my case to 2.10.0), apparently putting back only Keras and Tensorflow to the correct versions was not enough.
saved using TF format file and not h5py: save_format='tf'. In my case:
model.save_weights("NMT_model_weight.tf",save_format='tf')
I had the same problem, solved putting compile=False
in load_model
:
model_ = load_model('path to your model.h5',custom_objects={'Scale': Scale()}, compile=False)
sgd = SGD(lr=1e-3, decay=1e-6, momentum=0.9, nesterov=True)
model_.compile(loss='categorical_crossentropy',optimizer='sgd',metrics=['accuracy'])