ModelCheckpoint loses .h5 save support, breaking retrocompatibility

Title: ModelCheckpoint Callback Fails to Save Models in .h5 Format in TensorFlow 2.17.0+

Description:

I’m experiencing an issue with TensorFlow’s tf.keras.callbacks.ModelCheckpoint across different TensorFlow versions on different platforms.

Background:

With versions up to TensorFlow 2.15.0, I was able to save models in .h5 format using tf.keras.callbacks.ModelCheckpoint with the save_weights_only=False parameter. This allowed for easy cross-platform loading of saved models.

Problem: Since TensorFlow 2.17.0, tf.keras.callbacks.ModelCheckpoint appears unable to save models in .h5 format, breaking backward compatibility. Models can only be saved in the .keras format, which versions prior to 2.17.0 cannot load, creating a compatibility issue for users maintaining models across different TensorFlow versions.

Steps to Reproduce:

  1. Use TensorFlow 2.17.0 or later.
  2. Try saving a model with tf.keras.callbacks.ModelCheckpoint using save_weights_only=False and specifying .h5 as the file format.
  3. Load the model in a previous version, such as TensorFlow 2.10.0 or earlier.

Expected Behavior: The model should be saved in .h5 format without error, maintaining backward compatibility with earlier versions.

Actual Behavior: The model cannot be saved in .h5 format, only in .keras format, making it incompatible with TensorFlow versions prior to 2.17.0.

Question: Is there a workaround to save models in .h5 format in TensorFlow 2.17.0+? Or, is there a plan to restore .h5 support in future updates for backward compatibility?

Environment:

  • TensorFlow version: 2.17.0+
  • Operating systems: Windows, Linux (Docker)

Thank you for your help and for maintaining this project!

Hi @TeoCavi, when using tensorflow version > 2.15 by default the keras3 will be used. In keras3 the supported format for saving the model is .keras format, it does not support .h5 format for saving the model. If you want to save the model in the .h5 format it is recommended to tf_keras which allows you to save the model in the .h5 format. please refer to this gist for working code example. Thank You.