tensorflow: tf.keras.models.load_model does not load optimizer's weigths

System information Tensorflow: 2.5.0

Describe current behaviour When using tf.keras.models.load_model() on a savedmodel containing a keras model saved using tf.keras.Model.save(include_optimizer=True), the optimizer’s weights are NOT loaded

Describe expected behaviour The reconstructed model should contain the optimizer’s weights to be able to resume training.

Standalone code to reproduce issue https://colab.research.google.com/drive/1Y0y-pvE2QDw1Wj68XnbpLaUggXAXyzcx?usp=sharing

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

@alvaro-garcia-carrasco

model.save_weights method will help you to extract weights from saved model format .Please find the gist.Thanks

@alvaro-garcia-carrasco

I saved model in hdf5 format and could be able to see the optimizer’s weights loaded in the reconstructed model.Please find the gist.Thanks

@UsharaniPagadala

The internals of how the graph and the variables are stored is not relevant. I am trying to load a SavedModel following the instructions in the documentation https://www.tensorflow.org/guide/keras/save_and_serialize#savedmodel_format and the optimizer’s weights are not being loaded, as shown in the standalone code I provided to reproduce the issue.