I attempted to migrate name-based Keras 2.x weights in .h5 format to Keras 3 by loading the .h5 weights into the model and subsequently saving them as either .weights.h5 or .keras files using model.save().

The resulting weight files were successfully loaded and functioned correctly in Keras 2.15.

However, upon transitioning to Keras 3, these weights failed to load or operate as expected.

I am currently investigating this issue by analyzing the source code. If you have any useful suggestions, I would appreciate your input.

Comment From: dhantule

Hi @edwardyehuang, thanks for reporting this. Could you please refer this issue #20081 and let me know if it helps?

Comment From: innat

https://github.com/keras-team/keras/issues/19060

Comment From: edwardyehuang

@dhantule This may be related to the trackable weights. See my latest comments in #21078

Comment From: edwardyehuang

It appears that implementing a straightforward name-based weight loading mechanism, without batch loading, is necessary to ensure compatibility of .h5 weight files between Keras 2.x and Keras 3. I will handle that

Comment From: monicadsong

Hi @edwardyehuang -

The Keras team would like to learn more about your Keras usage. Please thumbs up this comment if you are open to speaking with us and we'll reach out to you over email.

Thank you so much! Monica, Keras Product Manager

Comment From: edwardyehuang

Hi @edwardyehuang -

The Keras team would like to learn more about your Keras usage. Please thumbs up this comment if you are open to speaking with us and we'll reach out to you over email.

Thank you so much! Monica, Keras Product Manager

Yes, it is an honor to have the opportunity to engage directly with the Keras team in efforts to further enhance Keras.

Comment From: georgeneedles60-hub

thank you

Comment From: dhantule

Hi @edwardyehuang, can you provide some reproducible code to reproduce the issue ?

Comment From: edwardyehuang

https://github.com/edwardyehuang/iSeg/blob/master/saver/h5_saver.py

The above is my implementation of name-based weight loading, which assumes that the order of the h5 weights and symbolic_weights differs. It compares the similarity of names between the h5 weights and symbolic_weights.

Comment From: edwardyehuang

I am now able to perform inference on all my previous models trained with TensorFlow 2.15 and Keras 2.15 using the Keras 3.10 environment, yielding correct inference results. However, training remains unsuccessful, producing anomalous outputs (e.g. loss) even in the first step, and the issue is currently under investigation.

Currently found:

  • Mixed precision training exhibits incorrect behavior when compared to Keras 2.15.