Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModelCheckpoint loses .h5 save support, breaking retrocompatibility #20490

Open
TeoCavi opened this issue Nov 13, 2024 · 2 comments
Open

ModelCheckpoint loses .h5 save support, breaking retrocompatibility #20490

TeoCavi opened this issue Nov 13, 2024 · 2 comments
Assignees
Labels
type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@TeoCavi
Copy link

TeoCavi commented Nov 13, 2024

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:

  • Platform 1: Windows with TensorFlow 2.10.0 (GPU-enabled).
  • Platform 2: Docker container on Linux using TensorFlow 2.3.0 (nvcr.io/nvidia/tensorflow:20.09-tf2-py3).

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!

@mehtamansi29
Copy link
Collaborator

Hi @TeoCavi -

Thanks for reporting the issue.
Here for ModelCheckpoint callbacks API, for keras2(TensorFlow 2.10.0), model checkpoint can save with '.h5' extension.

And here for ModelCheckpoint callbacks API, for keras3(TensorFlow 2.17.0), model checkpoint can save with '.keras' extension.

@mehtamansi29 mehtamansi29 added type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. stat:awaiting response from contributor labels Nov 13, 2024
@fchollet
Copy link
Member

Yeah that's a bug, we should support both file types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

3 participants