Pre-trained Model
Trained on ImageNet
25M parameters
ā
Fine-Tuning Strategy
ā
Your Task
1000 images
2 classes
Layer Freezing
Training
Data Augmentation
Network Layers (Frozen vs Trainable)
Conv Block 1 (Early Features)āļø Frozen
Conv Block 2āļø Frozen
Conv Block 3āļø Frozen
Conv Block 4āļø Frozen
Conv Block 5 (Late Features)š„ Trainable
Classifier Headš„ Trainable
20M
Frozen Parameters
5M
Trainable Parameters
0%
Validation Accuracy
0
Epochs Trained
Understanding Transfer Learning
Transfer learning leverages knowledge from pre-trained models to solve new tasks with limited data. Instead of training from scratch, you start with weights learned on large datasets (ImageNet, Wikipedia) and adapt them to your specific problem.
Why Transfer Learning?
- Limited Data: Works with 100s instead of millions of examples
- Faster Training: Hours instead of days/weeks
- Better Performance: Pre-trained features generalize well
- Lower Computational Cost: No need for massive GPU clusters
- Proven Architectures: Start with tested designs
Transfer Learning Strategies
- Feature Extraction (Freeze All):
- Freeze all pre-trained layers
- Only train new classifier head
- Fastest, works when domains very similar
- Example: ImageNet ā other natural images
- Fine-tune Top Layers:
- Freeze early layers (general features)
- Train later layers + classifier
- Balanced approach, most common
- Adapts high-level features to new domain
- Fine-tune All Layers:
- Train entire network
- Use very low learning rate
- Best when have sufficient data (1000+ per class)
- Risk overfitting with small datasets
- Gradual Unfreezing:
- Start frozen, gradually unfreeze layers
- Train classifier first, then unfreeze top layers, etc.
- Discriminative learning rates (different LR per layer)
- Often gives best results
Popular Pre-trained Models
- Computer Vision:
- ResNet (18, 34, 50, 101, 152) - Deep residual networks
- VGG (16, 19) - Simple, deep architecture
- EfficientNet (B0-B7) - State-of-the-art efficiency
- MobileNet - For mobile/edge devices
- Vision Transformer (ViT) - Transformer for images
- NLP:
- BERT - Bidirectional encoder
- GPT-2/3 - Autoregressive decoder
- RoBERTa - Optimized BERT
- T5 - Text-to-text framework
- DistilBERT - Smaller, faster BERT
When Transfer Learning Works Best
- Similar Domains:
- ImageNet ā other natural images (excellent)
- English text ā other languages (good with multilingual models)
- Small Target Dataset:
- 100-10,000 examples
- Pre-trained features provide strong baseline
- Limited Compute:
- Training from scratch needs GPUs for days
- Fine-tuning: hours on single GPU
Domain Adaptation Challenges
- Domain Shift:
- Natural images ā Medical scans (significant shift)
- News text ā Social media (different vocabulary/style)
- Solution: More extensive fine-tuning
- Task Mismatch:
- Classification ā Detection/Segmentation
- May need architecture modifications
Fine-Tuning Best Practices
- Learning Rate:
- Use lower LR than training from scratch
- Typical: 1e-4 to 1e-5
- Discriminative LR: Lower for early layers
- Data Augmentation:
- Essential with small datasets
- Use domain-appropriate augmentations
- Don't use augmentations that change semantics
- Batch Size:
- Often use smaller batches (16-32)
- Limited by dataset size
- Epochs:
- Fewer epochs than training from scratch
- 10-50 epochs typical
- Monitor validation to prevent overfitting
Implementation Steps
- 1. Load Pre-trained Model: Download weights from model zoo
- 2. Modify Architecture: Replace classifier head for your classes
- 3. Freeze Layers: Decide which layers to freeze
- 4. Prepare Data: Match pre-training preprocessing
- 5. Train: Fine-tune with low learning rate
- 6. Gradually Unfreeze: Optionally unfreeze more layers
- 7. Evaluate: Test on validation set
Common Pitfalls
- Using wrong preprocessing (must match pre-training)
- Learning rate too high (destroys pre-trained features)
- Not freezing any layers with small dataset
- Freezing too many layers when domain very different
- Forgetting to set model to train/eval mode
Advanced Techniques
- Multi-task Learning: Fine-tune on multiple related tasks
- Meta-Learning: Learn to adapt quickly to new tasks
- Self-Supervised Pre-training: Create your own pre-trained models
- Domain Adversarial Training: Align source and target domains
Applications
- Medical Imaging: Pre-trained on natural images ā X-rays, CT scans
- Satellite Imagery: ImageNet ā land use classification
- Text Classification: BERT ā sentiment, topic classification
- Object Detection: COCO-trained ā specific object types
- Style Transfer: Use VGG features
Experiment with the Studio
Use the interactive tool above to:
- Select different pre-trained models
- Try various fine-tuning strategies
- Freeze/unfreeze layers and see effects
- Understand trainable vs frozen parameters
- Simulate transfer learning on different tasks
Transfer learning is the most practical approach to deep learning. It democratizes AI by making powerful models accessible without massive compute!