Feature extraction and fine-tuning
What it is
Transfer learning reuses pretrained weights instead of asking a small target dataset to discover every useful feature from random noise. In feature extraction, the backbone remains frozen and only a new classification or regression head learns; in fine-tuning, some or all backbone layers are unfrozen with a smaller learning rate to adapt representations to the target domain. Which layers to unfreeze depends on data volume and domain distance: generic early visual features often transfer widely, while later task-specific features may need more adaptation. The validation set decides whether additional unfreezing helps rather than merely overfits.
Why it matters
Pretraining supplies useful visual or linguistic features before your small dataset can. It is often faster, cheaper, and more accurate than training from random initialization, particularly when labels are scarce. It also changes the experiment plan: compare a frozen baseline first, then progressively unfreeze while measuring whether the added trainable capacity improves held-out performance enough to justify its cost.
In the real world: Building a defect detector from 2,000 factory photos by starting from a model trained on millions of general images.
Visual example
Deep learningA pretrained backbone supplies general features; the target task changes only what it needs.
import torch.nn as nn
from torchvision import models
model = models.resnet18(weights=models.ResNet18_Weights.DEFAULT)
for param in model.parameters():
param.requires_grad = False # freeze the backbone
model.fc = nn.Linear(model.fc.in_features, n_classes) # fresh, trainable headFine-tuning every layer at the same large learning rate used for a fresh head. It can erase useful pretrained features in a few updates; use discriminative or smaller rates.