Skip to content

Commit db409ff

Browse files
authored
Improve deserialization error about @register_keras_serializable. (#21590)
There is a confusing case when a user has decorated their class or function with `@keras.saving.register_keras_serializable()`, but gets the error message: "Make sure custom classes are decorated with `@keras.saving.register_keras_serializable()`". This happens if the decorated function or class has not been imported/loaded and the decorator has not been run. This augments the error message to explain this case.
1 parent 13d52ce commit db409ff

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

keras/src/saving/serialization_lib.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,9 @@ def _retrieve_class_or_fn(
834834
)
835835

836836
raise TypeError(
837-
f"Could not locate {obj_type} '{name}'. "
838-
"Make sure custom classes are decorated with "
839-
"`@keras.saving.register_keras_serializable()`. "
840-
f"Full object config: {full_config}"
837+
f"Could not locate {obj_type} '{name}'. Make sure custom classes and "
838+
"functions are decorated with "
839+
"`@keras.saving.register_keras_serializable()`. If they are already "
840+
"decorated, make sure they are all imported so that the decorator is "
841+
f"run before trying to load them. Full object config: {full_config}"
841842
)

0 commit comments

Comments
 (0)