Error when cloning amodel with custom activation function
See original GitHub issueHello,
While I was trying to clone a model I faced the following error:
Traceback (most recent call last):
File “<ipython-input-69-598bf1638a5a>”, line 10, in <module> model_RMSE = clone_model(model)
File “/usr/local/lib/python3.5/dist-packages/keras/models.py”, line 1523, in clone_model if layer not in layer_map:
File “/usr/local/lib/python3.5/dist-packages/keras/models.py”, line 1378, in _clone_functional_model merge_config = self.layers[0].get_config()
File “/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py”, line 1252, in from_config # Returns
File “/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py”, line 87, in wrapper return func(*args, **kwargs)
File “/usr/local/lib/python3.5/dist-packages/keras/layers/core.py”, line 808, in init super(Dense, self).init(**kwargs)
File “/usr/local/lib/python3.5/dist-packages/keras/activations.py”, line 95, in get if identifier is None:
File “/usr/local/lib/python3.5/dist-packages/keras/activations.py”, line 87, in deserialize def deserialize(name, custom_objects=None):
File “/usr/local/lib/python3.5/dist-packages/keras/utils/generic_utils.py”, line 159, in deserialize_keras_object if fn is None:
ValueError: Unknown activation function:exp Here is a minimal reproducible example:
from keras.models import Model,clone_model
from keras.layers import Input, Dense
from keras.optimizers import Adam
from keras import backend as K
inputs = Input(name='input1', shape=(1,))
model = Dense(15, activation='relu') (inputs)
outputs = Dense(1, activation=K.exp) (model)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='poisson',optimizer=Adam(lr=5e-3))
model_clone = clone_model(model)
When replacing
outputs = Dense(1, activation=K.exp) (model)
to
outputs = Dense(1, activation=None) (model)
error is vanishing.
Any idea how to solve this problem?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
I still have this bug
x = keras.layers.Activation(my_custom_activation_function)(x)
is not working. I have to usex = keras.layers.Lambda(my_custom_activation_function)(x)
insteadwhy this strange behaviour?
This is a little more pressing now, as
clone_model
is used inmulti_gpu_model
whencpu_relocation
isTrue
.