-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Error deserializing saved model after Keras bump 3.6 -> 3.7 #20806
Comments
Hi @cloudbopper , Please try the below steps: 1.If you have custom loss function code then you can copy the code before reloading the model.
This should work probably. I don't think its related to the version. For example if you have a model with custom classes or functions then save the model and restart the session and try to reload the model in same version without adding code to custom object like mentioned above. The problem will be replicated. The root cause seems Keras not saving complete custom object implementation except class/function name and signature. For the function body/implementation it depends on the storage ID of this object locally. When a session restarted it will loose this storage. Hence we need to add the custom objects before reloading the model from May be providing option for serializing @mehtamansi29 , Correct me If I am mistaken in any thing I said. |
Yes, it works by adding I can confirm that saving the model with the function registered using the decorator You can see the responsible merge commit 0c2bdff and the associated pull request #20406 in the changelog for Keras 3.7: v3.6.0...v3.7.0. |
Hi @cloudbopper , Actually I have tested a custom model with Keras 3.6v, saved it and restarted the session and tried to reload the session. Got error in reloading the model if not added custom object code in new session. Please refer to attached colab gist.Same is true for other version also like 3.5v and 3.8v. So what I observed is without adding custom code I can't reload a saved model with custom objects(even with serialization registry), can't be reloaded in a new session or with a new version without explicitly adding the code for custom objects before reloading. Could you please verify the colab gist that I have attached and confirm whether you have not observed similar behavior? |
I'm encountering this error while loading a model saved with Keras 3.6 in Keras 3.7 and 3.8:
TypeError: Could not locate function 'attention_loss'. Make sure custom classes are decorated with `@keras.saving.register_keras_serializable()`. Full object config: {'module': 'builtins', 'class_name': 'function', 'config': 'attention_loss', 'registered_name': 'function'}
The decorator for the custom function:
I narrowed down the changes causing the error to 795df4e.
The function was serialized without the package name prior to 795df4e, so the removal of the fallback code means that the serialized function key can no longer be used to retrieve the registered object (key 'attention_loss>attention_loss')
The text was updated successfully, but these errors were encountered: