Transfer learning adapts a model trained on a large source dataset to a related target task. Reusing learned weights can reduce labeled-data, compute, and training-time requirements while improving accuracy. It works best when the source and target domains share useful structure, such as the local relationships common to images. section 13.0 section 13.1
A practical transfer-learning workflow is:
- Start with a pretrained architecture and replace its task-specific output layer. For a ResNet-18 classifier, use the existing input width: model.fc = nn.Linear(model.fc.in_features, 2). section 13.2
- Match preprocessing to the pretrained model. ImageNet-trained ResNet expects channel normalization with mean [0.485, 0.456, 0.406] and standard deviation [0.229, 0.224, 0.225]. section 13.2.2
- Choose between warm and frozen weights. Warm starting updates pretrained parameters during training; freezing sets requires_grad=False for the original layers and trains the replacement layer. section 13.2.3 section 13.2.4
- Use frozen weights when the labeled dataset is extremely small and warm weights when adapting more parameters is justified. Frozen models are generally more stable, while warm models can be more accurate. section 13.2.4 section 13.3
Adapting an ImageNet ResNet
model = torchvision.models.resnet18(pretrained=True) model.fc = nn.Linear(model.fc.in_features, 2) model = NormalizeInput(model) The convolutional filters retain features such as edges, colors, sharpening, and blurring, while the new fully connected layer learns the cat-versus-dog decision. Train the resulting model with the usual loss and optimizer. For frozen transfer, disable gradients before replacing fc. section 13.2.1 section 13.2.2 section 13.2.4
The same pattern applies to text. A pretrained transformer supplies broadly learned language representations, while a task-specific classifier is trained on the target labels. BERT-style models require their original tokenizer and encoding process; DistilBERT provides a smaller, faster transfer-learning option. section 13.4 section 13.4.1
Figure 13.1 Training a big model on a big dataset. It is a one-time cost, because we can reuse the big model by transferring it to many different smaller tasks. This is done by editing the model but keeping almost all of the original architecture and weights θ intact. Then we train the modified model on the new dataset.
Shows the one-time cost of training a large source model and the reuse pattern: modify a small part while preserving most architecture and weights for multiple target tasks. section 13.1










