@@ -19,12 +19,12 @@ class SerializableCustomTransform(ElementwiseTransform):
1919
2020 Parameters
2121 ----------
22- serializable_forward_fn : function, no lambda
22+ forward : function, no lambda
2323 Registered serializable function to transform the data in the forward pass.
2424 For the adapter to be serializable, this function has to be serializable
2525 as well (see Notes). Therefore, only proper functions and no lambda
2626 functions can be used here.
27- serializable_inverse_fn : function, no lambda
27+ inverse : function, no lambda
2828 Function to transform the data in the inverse pass.
2929 For the adapter to be serializable, this function has to be serializable
3030 as well (see Notes). Therefore, only proper functions and no lambda
@@ -47,28 +47,27 @@ class SerializableCustomTransform(ElementwiseTransform):
4747 def __init__ (
4848 self ,
4949 * ,
50- serializable_forward_fn : Callable [[np .ndarray , ...], np .ndarray ],
51- serializable_inverse_fn : Callable [[np .ndarray , ...], np .ndarray ],
50+ forward : Callable [[np .ndarray , ...], np .ndarray ],
51+ inverse : Callable [[np .ndarray , ...], np .ndarray ],
5252 ):
5353 super ().__init__ ()
5454
55- self ._check_serializable (serializable_forward_fn , label = "serializable_forward_fn " )
56- self ._check_serializable (serializable_inverse_fn , label = "serializable_inverse_fn " )
57- self ._forward = serializable_forward_fn
58- self ._inverse = serializable_inverse_fn
55+ self ._check_serializable (forward , label = "forward " )
56+ self ._check_serializable (inverse , label = "inverse " )
57+ self ._forward = forward
58+ self ._inverse = inverse
5959
6060 @classmethod
6161 def _check_serializable (cls , function , label = "" ):
62- GENERAL_EXAMPLE_CODE = f"""The example code below shows the structure of a correctly decorated function:
63-
64- ```
65- import keras
66-
67- @keras.saving.register_keras_serializable('custom')
68- def my_{ label } (...):
69- [your code goes here...]
70- ```
71- """
62+ GENERAL_EXAMPLE_CODE = (
63+ "The example code below shows the structure of a correctly decorated function:\n \n "
64+ "```\n "
65+ "import keras\n \n "
66+ "@keras.saving.register_keras_serializable('custom')\n "
67+ f"def my_{ label } (...):\n "
68+ " [your code goes here...]\n "
69+ "```\n "
70+ )
7271 if function is None :
7372 raise TypeError (
7473 f"'{ label } ' must be a registered serializable function, was 'NoneType'.\n { GENERAL_EXAMPLE_CODE } "
@@ -132,7 +131,7 @@ def from_config(cls, config: dict, custom_objects=None) -> "SerializableCustomTr
132131 raise TypeError (
133132 "\n \n PLEASE READ HERE:\n "
134133 "-----------------\n "
135- "The forward function that was provided as `serializable_forward_fn ` "
134+ "The forward function that was provided as `forward ` "
136135 "is not registered with Keras, making deserialization impossible. "
137136 f"Please ensure that it is registered as '{ config ['forward' ]['config' ]} ' and identical to the original "
138137 "function before loading your model."
@@ -147,7 +146,7 @@ def from_config(cls, config: dict, custom_objects=None) -> "SerializableCustomTr
147146 raise TypeError (
148147 "\n \n PLEASE READ HERE:\n "
149148 "-----------------\n "
150- "The inverse function that was provided as `serializable_inverse_fn ` "
149+ "The inverse function that was provided as `inverse ` "
151150 "is not registered with Keras, making deserialization impossible. "
152151 f"Please ensure that it is registered as '{ config ['inverse' ]['config' ]} ' and identical to the original "
153152 "function before loading your model."
@@ -156,8 +155,8 @@ def from_config(cls, config: dict, custom_objects=None) -> "SerializableCustomTr
156155 forward = deserialize (config ["forward" ], custom_objects )
157156 inverse = deserialize (config ["inverse" ], custom_objects )
158157 return cls (
159- serializable_forward_fn = forward ,
160- serializable_inverse_fn = inverse ,
158+ forward = forward ,
159+ inverse = inverse ,
161160 )
162161
163162 def get_config (self ) -> dict :
0 commit comments