Transfer Learning and Pre-trained CNNs
Related: 8. Convolutional Neural Networks | 9. CNNs Part II — Improving Generalisability | 4. Deep Learning and FCNs | Artificial Intelligence
What is a Pre-trained Model?
A saved network previously trained on a large dataset (e.g., ImageNet with 1.4M images, 1000 classes). Useful when you have a small dataset — improves accuracy and saves training time.
Examples: VGG-16, GoogLeNet/Inception, ResNet, MobileNet, BERT, GPT.
Using a Pre-trained Model
Feature Extraction (Shallow Mode)
- Load pre-trained convolutional base without the top classifier
- Freeze all convolutional layers (
trainable = False) - Add new custom dense layers on top for your specific task
- Train only the new dense layers
Why not reuse the classifier? The original classifier was trained for 1000 ImageNet classes — not your task.
Fine-Tuning (Deep Mode)
Two approaches:
- Full fine-tuning: Set entire model as trainable (
conv_base.trainable = True), train end-to-end with a low learning rate - Partial fine-tuning: Freeze early layers, only unfreeze later layers (e.g., from
block5_conv1onwards)
Rationale: Early layers learn generic features (edges, textures) transferable across tasks. Later layers learn task-specific features. This connects to how 8. Convolutional Neural Networks extract hierarchical features — shallow layers capture edges and textures, while deeper layers capture complex patterns specific to the training task.