Skip to content

Latest commit

 

History

History
43 lines (38 loc) · 1.53 KB

keras.md

File metadata and controls

43 lines (38 loc) · 1.53 KB

1. Trainable parameter setting in layer

trainable=False

  • To "freeze" a layer means to exclude it from training, i.e. its weights will never be updated.
  • This is useful in the context of fine-tuning a model, or using fixed embeddings for a text input.
  • You can pass a trainable argument (boolean) to a layer constructor to set a layer to be non-trainable:
frozen_layer = Dense(32, trainable=False)
  • Additionally, you can set the trainable property of a layer to True or False after instantiation.
  • For this to take effect, you will need to call compile() on your model after modifying the trainable property.
  • Here's an example:
x = Input(shape=(32,))
layer = Dense(32)
layer.trainable = False
y = layer(x)

frozen_model = Model(x, y)
# in the model below, the weights of `layer` will not be updated during training
frozen_model.compile(optimizer='rmsprop', loss='mse')

layer.trainable = True
trainable_model = Model(x, y)
# with this model the weights of the layer will be updated during training
# (which will also affect the above model since it uses the same layer instance)
trainable_model.compile(optimizer='rmsprop', loss='mse')

frozen_model.fit(data, labels)  # this does NOT update the weights of `layer`
trainable_model.fit(data, labels)  # this updates the weights of `layer`

2. Issue with plot_model in keras and pydot

Error Massages

Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.

Solution

sudo apt-get install graphviz
pip install pydot pydotplus

added