Transfer learning: freeze, fine-tune and compare baselines
In this article (5 sections)
Transfer learning initializes a target model from parameters learned on a source task. Freezing retains the source feature extractor and trains a new head. Fine-tuning updates some or all transferred weights, usually with a smaller learning rate. Both should be compared with training from scratch under a declared target-data budget.
A small related-source experiment
The local lab pretrains its NumPy convolutional model on 180 clean stripe images. The target task has heavier noise and only 60 training images.
| Target candidate | Validation accuracy |
|---|---|
| Train from scratch | 50% |
| Freeze transferred convolution filters | 100% |
| Fine-tune transferred model | 100% |
from deep_learning_cases import transfer_case
result = transfer_case()
scores = result["validation_accuracy"]
assert result["target_training_rows"] == 60
assert set(scores) == {"scratch", "frozen_features", "fine_tuned"}
print(scores)This large gap is expected in an intentionally related, simple authored fixture. It demonstrates reuse of learned filters; it is not a benchmark for a public pretrained model or real images. Frozen and fine-tuned candidates tie, so the cheaper frozen option is sufficient under this validation result.
Establish source compatibility
Record the source dataset, task, preprocessing, license and model version. Check input channels, resolution and normalization. A source model trained on unrelated imagery or restricted data may provide little value or create governance problems.
Train a fresh task-specific head first. Then unfreeze a declared block, lower the learning rate and monitor validation. If batch-normalization statistics are present, decide whether they update. Changing every layer immediately can erase useful features on a small target set.
Compare fairly
Give scratch, frozen and fine-tuned candidates comparable tuning budgets. Report trainable parameters, elapsed resources and several seeds. Keep source-related duplicates out of target test; public datasets can overlap unexpectedly.
Inspect errors by target slice. Transfer may improve the average while preserving a source bias. A perfect validation score on a small set has wide uncertainty and warrants a harder, independent test.
The Data Science course treats transfer learning as an evaluated initialization choice with provenance and operating costs.
Exercise
Vary target training size and unfreeze zero, one or all blocks. Plot validation distribution, trainable parameter count and fit time. Select on validation, then assess once on an untouched source-disjoint test.
Continue learning
This article is part of the Deep learning and computer vision sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Image augmentation that preserves the label meaning.
- Continue with Detect near-duplicate images across train and test sets.
Reference: PyTorch transfer-learning tutorial.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.
Explore Data Science