Model Pipeline - Freezing and unfreezing layers
This pipeline shows how a model uses frozen layers to keep learned features fixed, then unfreezes layers to fine-tune and improve accuracy.
This pipeline shows how a model uses frozen layers to keep learned features fixed, then unfreezes layers to fine-tune and improve accuracy.
Epoch 1: ************ (loss=1.2) Epoch 2: ******** (loss=0.9) Epoch 3: ******* (loss=0.7) Epoch 4: ****** (loss=0.65) Epoch 5: **** (loss=0.5) Epoch 6: *** (loss=0.45)
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.55 | Training classifier layers with frozen base |
| 2 | 0.9 | 0.68 | Accuracy improves as classifier learns |
| 3 | 0.7 | 0.75 | Stable improvement with frozen base |
| 4 | 0.65 | 0.78 | Unfreeze some layers for fine-tuning |
| 5 | 0.5 | 0.85 | Fine-tuning improves feature extraction |
| 6 | 0.45 | 0.88 | Model converges with unfreezing |
layer in TensorFlow before compiling the model?trainable attribute to allow or prevent training on layers.trainable = False freezes the layer so it won't update during training.model.layers[0].trainable after compiling?model.layers[0].trainable = False model.compile(optimizer='adam', loss='mse') print(model.layers[0].trainable)
trainable = False before calling compile.trainable attribute remains as set before compile; it does not change automatically.AttributeError: 'Sequential' object has no attribute 'unfreeze'
model.unfreeze() model.compile(optimizer='adam', loss='mse')
Sequential model has no unfreeze attribute, meaning calling model.unfreeze() is invalid.trainable attribute; set it to True for all layers to unfreeze.trainable = False for all layers except last two.trainable = True for the last two layers to allow training.Pass the test and this pattern moves unknown