-
Notifications
You must be signed in to change notification settings - Fork 19.6k
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
Serialization with activation layer does not work #21088
Comments
I wanted to add that the following code runs without problems and allows serialization / deserialization with a layer class as activation. The simple fix, as I hinted in my initial post, is to use
|
Most Keras layer support an activation function. While it is possible to use string identifiers like "relu", we can also use actual activation layers like layers.ReLU().
When using a layer, the deserialization is broken, since the activations.deserialize(activation) in the
from_config()
method does not support an instance of class layers.Layer. This significantly reduces the flexibility, because using, e.g., LeakyReLU with a negative slope of 0.1 is not possible when you rely on loading the trained model later on.An easy fix would be to use
saving.serialize_keras_object(self.activation)
inget_config()
andsaving.deserialize_keras_object(activation_cfg)
in thefrom_config()
method.The last line throws the following exception (tested on Keras 3.6.0 and 3.9.0)
"Exception encountered: Could not interpret activation function identifier: {'module': 'keras.layers', 'class_name': 'ReLU', 'config': {'name': 're_lu', 'trainable': True, 'dtype': {'module': 'keras', 'class_name': 'DTypePolicy', 'config': {'name': 'float32'}, 'registered_name': None}, 'max_value': None, 'negative_slope': 0.0, 'threshold': 0.0}, 'registered_name': None}"
The text was updated successfully, but these errors were encountered: