From bb3f577751aa7ec79c35a4864b34a88341f8a7f0 Mon Sep 17 00:00:00 2001 From: SuryanarayanaY <116063290+SuryanarayanaY@users.noreply.github.com> Date: Wed, 2 Aug 2023 18:44:19 +0530 Subject: [PATCH] Update custom_object documentation and __init__() arguments serialization_and_saving.py In the example of a CustomLayer class its __init__ method passed argument sublayer whereas while assigning to self it is using the variable layer instead of sublayer. Hence corrected the same. Also please check the documentation below. If the arguments passed to the constructor (`__init__()` method) of the custom object aren't Python objects (anything other than base types like ints, strings, etc.), then you **must** also explicitly deserialize these arguments in the `from_config()` class method. Actually we need to also add the statement like you must explicitly serialize the non_python arguments in get_config() method also so that it can be deserialized in from_config() method. As it is explicitly mentioned for from_config() it should be explicitly mentioned for get_config() also. This makes users well aware of this. Because without serializing non_python object in get_config() , it is not possible to reload that back into model. --- guides/serialization_and_saving.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/serialization_and_saving.py b/guides/serialization_and_saving.py index c998a0e6b1..2f00deeb2d 100644 --- a/guides/serialization_and_saving.py +++ b/guides/serialization_and_saving.py @@ -133,8 +133,8 @@ def get_model(): you **must** define a `get_config()` method on the object class. If the arguments passed to the constructor (`__init__()` method) of the custom object aren't Python objects (anything other than base types like ints, strings, -etc.), then you **must** also explicitly deserialize these arguments in the `from_config()` -class method. +etc.), then you **must** serialize these arguments in `get_config()` method and +also explicitly deserialize these arguments in the `from_config()` class method. Like this: @@ -142,7 +142,7 @@ class method. class CustomLayer(keras.layers.Layer): def __init__(self, sublayer, **kwargs): super().__init__(**kwargs) - self.sublayer = layer + self.sublayer = sublayer def call(self, x): return self.sublayer(x)