本文整理汇总了Python中keras.layers.Dense.trainable方法的典型用法代码示例。如果您正苦于以下问题:Python Dense.trainable方法的具体用法?Python Dense.trainable怎么用?Python Dense.trainable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.layers.Dense
的用法示例。
在下文中一共展示了Dense.trainable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_layer_trainability_switch
# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import trainable [as 别名]
def test_layer_trainability_switch():
# with constructor argument, in Sequential
model = Sequential()
model.add(Dense(2, trainable=False, input_dim=1))
assert model.trainable_weights == []
# by setting the `trainable` argument, in Sequential
model = Sequential()
layer = Dense(2, input_dim=1)
model.add(layer)
assert model.trainable_weights == layer.trainable_weights
layer.trainable = False
assert model.trainable_weights == []
# with constructor argument, in Model
x = Input(shape=(1,))
y = Dense(2, trainable=False)(x)
model = Model(x, y)
assert model.trainable_weights == []
# by setting the `trainable` argument, in Model
x = Input(shape=(1,))
layer = Dense(2)
y = layer(x)
model = Model(x, y)
assert model.trainable_weights == layer.trainable_weights
layer.trainable = False
assert model.trainable_weights == []
示例2: Input
# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import trainable [as 别名]
recog_right=recog
recog_right.add(Dense(64,input_shape=(64,),activation='relu'))
recog_right.add(Lambda(lambda x: x + K.exp(x / 2) * K.random_normal(shape=(1, 64), mean=0.,
std=epsilon_std), output_shape=(64,)))
recog_right.add(Highway())
recog_right.add(Activation('sigmoid'))
recog1=Sequential()
recog1.add(Merge([recog_left,recog_right],mode = 'ave'))
recog1.add(Dense(784))
#### HERE***
recog11=Sequential()
layer=Dense(64,init='glorot_uniform',input_shape=(784,))
layer.trainable=False
recog11.add(layer)
layer2=Dense(784, activation='sigmoid',init='glorot_uniform')
layer2.trainable=False
recog11.add(layer2)
recog11.layers[0].W.set_value(np.ones((784,64)).astype(np.float32))
recog11.compile(loss='mean_squared_error', optimizer=sgd,metrics = ['mae'])
recog11.get_weights()[0].shape
gan_input = Input(batch_shape=(1,784))
gan_level2 = recog11(recog1(gan_input))
GAN = Model(gan_input, gan_level2)
示例3: pop_layer
# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import trainable [as 别名]
model.add(Dense(10,trainable='False'))
model.add(Activation('softmax',trainable='False'))
# LOADING WEIGHTS TO FINE-TUNNE THEM
model.load_weights(weights_path)
pop_layer(model)
pop_layer(model)
# for layer in model.layers:
# layer.trainable= False
nb_classes=13
layer_last=Dense(nb_classes)
layer_last.trainable=True
layer_last2=Activation('softmax')
layer_last2.trainable=True
model.add(layer_last)
model.add(layer_last2)
print(model.summary())
# let's train the model using SGD + momentum (how original).
#sgd = SGD(lr=0.001, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
optimizer="sgd",
metrics=['accuracy'])
示例4: Input
# 需要导入模块: from keras.layers import Dense [as 别名]
# 或者: from keras.layers.Dense import trainable [as 别名]
recog_right=recog
recog_right.add(Dense(64,input_shape=(64,),activation='relu'))
recog_right.add(Lambda(lambda x: x + K.exp(x / 2) * K.random_normal(shape=(1, 64), mean=0.,
std=epsilon_std), output_shape=(64,)))
recog_right.add(Highway())
recog_right.add(Activation('sigmoid'))
recog1=Sequential()
recog1.add(Merge([recog_left,recog_right],mode = 'ave'))
recog1.add(Dense(784))
recog1.add(Activation('relu'))
#### GATE***
recog11=Sequential()
layer=Dense(2,init='glorot_uniform',input_shape=(784,))
layer.trainable=False
recog11.add(layer)
layer2=Dense(784, activation='sigmoid',init='glorot_uniform')
layer2.trainable=True
recog11.add(layer2)
recog11.layers[0].W.set_value(np.ones((784,2)).astype(np.float32))
recog11.compile(loss='mean_squared_error', optimizer=sgd,metrics = ['mae'])
recog11.get_weights()[0].shape
gan_input = Input(batch_shape=(1,784))
gan_level2 = recog11(recog1(gan_input))
GAN = Model(gan_input, gan_level2)