Hızlı yanıt: kod örneği
Credits to this Github issue comment by Ritchie Ng.Please keep in mind that you have to import this function when you save and restore the model. See the note of keras-contrib.
# Creating a modelfrom keras.models import Sequentialfrom keras.layers import Dense# Custom activation functionfrom keras.layers import Activationfrom keras import backend as Kfrom keras.utils.generic_utils import get_custom_objectsdef custom_activation(x): return (K.sigmoid(x) * 5) - 1get_custom_objects().update({'custom_activation': Activation(custom_activation)})# Usagemodel = Sequential()model.add(Dense(32, input_dim=784))model.add(Activation(custom_activation, name='SpecialActivation'))print(model.summary())