Error in load a model saved by callbakcs.ModelCheckpoint() in Keras

I hit a similar problem that yields the same error message, but the cause might be different than yours:

Code: (Tensorflow 1.11 and tf.keras.version: 2.1.6-tf)

 if load_model_path.endswith('.h5'):
        model = tf.keras.models.load_model(load_model_path)

Error message:

  File "...../lib/python3.6/site-packages/tensorflow/python/keras/engine/saving.py", line 251, in load_model
    training_config['weighted_metrics'])
KeyError: 'weighted_metrics'

And I found out it's because the model was saved in an older Keras version. I had to comment out the code related to weighted_metrics to be able to load the model. However, it's just a workaround before I can find a sustainable solution to the mismatching problem. Interestingly, @fchollet just added weighted_metrics to the latest Keras version recently (Oct 2018).
https://github.com/keras-team/keras/blob/master/keras/engine/saving.py#L136 I hope this will help the people who hit the same problem as I did.


If you haven't figured out the answer to this yet, I think I've got it.

I haven't dug into the code to exactly figure out why, but basically the model checkpoint callback can only be loaded with the load_weights() function, which is then used for evaluation.

If you want to save a model that you can load to train again later you need to use model.save and model.load_model. Hopefully helpful to someone who wanders upon this.