The two-phase recipe, step by step
The last three lessons gave you the pieces; this one is the order to use them in. The proven workflow is two phases, run in sequence:
- Freeze the base. Set
base_model.trainable = Falseso only your new head can learn. - Train the head for ~5–10 epochs at a normal learning rate (~1e-3). This is the feature-extraction baseline.
- Unfreeze the top layers of the base — typically the last block or last ~20 layers — and re-compile.
- Fine-tune everything trainable at a very low learning rate (~1e-5) for ~10–20 more epochs.
- Compare and decide. Did phase 2 actually beat phase 1 on validation? If not, ship the simpler feature-extraction model.
Why the order is non-negotiable
The sequence exists to prevent catastrophic forgetting. Your new head starts with random weights. If you unfreeze the base and train from the start, that random head produces huge early gradients — and those gradients flow back into the pretrained layers and scramble the very features you came here to reuse. Training the head first gets it to a sensible state, so by the time you unfreeze the base, the gradients reaching it are small and well-behaved. The tiny phase-2 learning rate is the second guardrail on the same risk.