If you like what you see here, please post this website on other sites. Message me directly on Twitter with any comments.
Freezing a layer in Keras
To freeze a layer in Keras, use:
model.layers.trainable = False
- Typically, the freezing of layers will be done so that weights which are learned in prior stages are not forgotten in later layers of the model.
- For example, if you have BERT as one part of a Keras TensorFlow model, that layer might need to be frozen so that large changes in gradient that occur during fine tuning do not distrupt the weights that have been learned in BERT.