归功于Ritchie
Ng对这个Github问题的评论。
# 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())
请记住,保存和还原模型时必须导入此功能。请参阅keras-
contrib的注释。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)