Transfer learning vs fine-tuning: the difference and when to use each
Fine-tuning is one kind of transfer learning: it updates pretrained weights, while feature extraction freezes them. When to use each, with PyTorch code.
Transfer learning reuses a model trained on one task as the starting point for another. Fine-tuning is one way to do it: you keep training some or all of the pretrained weights on your new data. The other common way, feature extraction, freezes the pretrained model and trains only a new output layer on top of it. So transfer learning vs fine-tuning is not a choice between rival methods. The real decision is whether to freeze the pretrained weights or update them.
Many tutorials use "transfer learning" to mean the frozen version and "fine-tuning" for the updated one. This guide calls the frozen version feature extraction so the two stay clear. Our recommendation for a first project is to train a frozen-feature baseline, then fine-tune only if it improves a valid held-out evaluation by enough to justify the extra cost.
Transfer learning vs fine-tuning at a glance
| Question | Training from scratch | Feature extraction (frozen) | Fine-tuning |
|---|---|---|---|
| What changes in training? | Every parameter, from random starting values | Only the new output layer | The new layer plus some or all pretrained layers |
| Is it transfer learning? | No | Yes | Yes |
| Labelled data needed | The most | The least | More than feature extraction, far less than training from scratch |
| Compute and memory | The most | The least: gradients flow only into the new layer | Grows with the number of unfrozen layers |
| Risk of overfitting | High on a small dataset | Low | Rises with the number of unfrozen layers |
| Learning rate | The usual rate for the model | The usual rate, for the new layer | Smaller for the pretrained layers than for the new layer |
| Use it when | No suitable pretrained model exists | Data is small and similar to the pretraining data | You have more data, or it differs from the pretraining data |
Keras's transfer learning guide follows the same order: freeze the base model, train a new top layer, then unfreeze and continue at a very low learning rate. You may already have used transfer learning without seeing the name: Google's Teachable Machine trains your image and pose classes on top of a pretrained network in the browser, and its FAQ describes your classes as becoming the last layer of that network.
When to use feature extraction and when to fine-tune
Two questions decide most cases: how much labelled data you have, and how similar it is to the data the model was pretrained on. The Stanford CS231n notes on transfer learning give this rule of thumb:
| Your dataset | Similar to the pretraining data | Different from the pretraining data |
|---|---|---|
| Small | Freeze the model and train only a new classifier | Train a classifier on features from earlier layers, which are more general |
| Large | Fine-tune: there is enough data to adapt the weights without overfitting | Fine-tune the whole network; training from scratch also becomes an option |
It is a starting point, not a result. Measure the frozen baseline first, then check whether fine-tuning improves held-out performance enough to justify its extra cost.
The difference in code
In PyTorch the difference is which parameters have requires_grad switched on. This example uses ResNet-18, an image model, and a new task with five classes:
import torch
from torchvision import models
model = models.resnet18(weights=None) # use ResNet18_Weights.DEFAULT in a real project
# Feature extraction: freeze every pretrained parameter...
for param in model.parameters():
param.requires_grad = False
# ...then replace the classifier for 5 new classes. New layers are trainable.
model.fc = torch.nn.Linear(model.fc.in_features, 5)
def trainable(model):
return sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f"feature extraction: {trainable(model):,} trainable parameters")
# Fine-tuning: also unfreeze the last block, and train it with a smaller step.
for param in model.layer4.parameters():
param.requires_grad = True
optimizer = torch.optim.SGD(
[
{"params": model.fc.parameters(), "lr": 1e-2},
{"params": model.layer4.parameters(), "lr": 1e-3},
],
momentum=0.9,
)
print(f"fine-tuning: {trainable(model):,} trainable parameters")
print(f"whole model: {sum(p.numel() for p in model.parameters()):,} parameters")
feature extraction: 2,565 trainable parameters
fine-tuning: 8,396,293 trainable parameters
whole model: 11,179,077 parameters
Feature extraction trains only the new layer's 2,565 numbers (512 inputs × 5 classes, plus 5 biases). Fine-tuning the last block trains about three quarters of the network. The smaller learning rate on layer4 adjusts the pretrained weights gently instead of overwriting what they learned.
Common mistakes
Assuming a frozen model is fully frozen. requires_grad = False stops gradient updates, but batch-normalization layers still update their running statistics whenever the model is in training mode. Continuing the example above:
# bn1, the first batch-normalization layer, is still frozen.
before = model.bn1.running_mean.clone()
model.train()
with torch.no_grad():
model(torch.randn(8, 3, 224, 224))
print("train mode changed frozen statistics:", not torch.equal(before, model.bn1.running_mean))
before = model.bn1.running_mean.clone()
model.eval()
with torch.no_grad():
model(torch.randn(8, 3, 224, 224))
print("eval mode changed frozen statistics: ", not torch.equal(before, model.bn1.running_mean))
train mode changed frozen statistics: True
eval mode changed frozen statistics: False
For a truly fixed feature extractor, keep the pretrained part in evaluation mode while the new layer trains. Keras ties the two together: setting trainable = False on a BatchNormalization layer also runs it in inference mode. Our PyTorch train, eval and no_grad guide explains why the mode and gradient switches are separate.
Fine-tuning with a random head and a large learning rate. A newly initialised output layer produces large errors at first, and those gradients can damage pretrained features. Train the new layer on the frozen model first, then unfreeze and continue with a smaller learning rate.
Forgetting the preprocessing the weights expect. A pretrained model expects the image size and normalisation it was trained with. In torchvision, ResNet18_Weights.DEFAULT.transforms() returns them.
Changing trainable in Keras without recompiling. The Keras guide says to call compile() again after changing any trainable value, or the change has no effect on later fit calls.
Letting near-duplicate images cross the split. Several photos of the same object in both training and test data inflate the score. Split by object, as the data leakage guide explains.
Fine-tuning large language models
The same distinction applies to language models. Using a pretrained LLM through prompts changes nothing in the model. Full fine-tuning updates every parameter, which for a model with billions of parameters needs a great deal of memory. Parameter-efficient methods such as LoRA freeze the original weights and train a small added update instead: most of the model stays fixed, but its behaviour still adapts. LoRA vs full fine-tuning measures that trade-off on a small, checked example.
A first project: frozen features, then fine-tuning
Suppose you want to sort photographs of household objects into categories. This is a suggested learning project, not a completed SchoolWhool experiment. Choose images you are allowed to use, define the categories and record how each label was assigned. Group photographs by physical object before splitting them, and create a manifest listing each file, its category, its object group and its split. Keep the test split fixed while you develop.
Experiment 1: keep the pretrained weights frozen. Choose a pretrained image model with documented input requirements, replace its classifier and train only that layer. PyTorch's computer vision transfer learning tutorial demonstrates this alongside fine-tuning. Save the model identity, weight version, preprocessing, split manifest and classifier settings so the second experiment can be compared fairly.
Experiment 2: fine-tune selected layers. Starting from experiment 1, unfreeze the layers you intend to adapt and continue training at a lower learning rate. TensorFlow's transfer learning tutorial shows the same step and how to handle batch normalization. Fine-tuning can overfit a small or narrow dataset, so compare both models on the same validation examples before choosing one.
Record the evidence for each experiment side by side:
| Item to record | Frozen-feature experiment | Fine-tuning experiment |
|---|---|---|
| Dataset and split manifest | Exact version used | Same version |
| Starting weights | Model and checkpoint identity | Whether you start from experiment 1's trained model |
| Updated parameters | The classifier | The classifier plus named unfrozen layers |
| Selection evidence | Validation metric and error review | Same metric and review process |
| Training resources | Measured time and hardware | Measured time and hardware |
Include a simple baseline, such as always choosing the most common class, and inspect errors by category: overall accuracy can hide poor performance on a rare one. Use the final test only for the approach you select. If fine-tuning barely changes the outcome but costs more, the frozen model may be the better choice; either conclusion makes a useful portfolio report.
Common questions
Is fine-tuning a type of transfer learning?
Yes. Transfer learning is any reuse of a pretrained model for a new task. Fine-tuning does it by continuing to train the pretrained weights; feature extraction does it by keeping them frozen.
Is fine-tuning always better than frozen feature extraction?
No. It depends on the starting model, the size and similarity of your dataset, and the training procedure. Establish the frozen baseline and measure the change.
How many labelled images do I need?
There is no universal count. Coverage, category ambiguity, label consistency and similarity to the pretraining data all matter. Start with an evaluation plan and inspect which additional examples would help.
Is LoRA transfer learning or fine-tuning?
Both. LoRA is a parameter-efficient form of fine-tuning, and like all fine-tuning it is a kind of transfer learning: the pretrained weights stay frozen while a small added set of weights is trained.
Does changing a prompt count as fine-tuning?
No. A prompt changes the input, not the model's parameters. Fine-tuning uses training to update parameters.
Should I use PyTorch or TensorFlow for transfer learning?
Both have official image transfer learning tutorials. Choose the maintained example closest to your task; our PyTorch vs TensorFlow guide compares the beginner workflows.
Build the foundations
To understand what the weight updates do, study gradient descent and derivatives, and see what a neural network is. Array shapes and channel normalisation are easier after NumPy broadcasting rules, and entropy, cross-entropy and KL divergence explains the training loss. The portfolio project briefs show how to present an experiment like this one.
The Deep Learning course teaches transfer learning and fine-tuning in its computer vision and transformer modules, and the Generative AI course covers adapting large language models.
Primary references were checked on 12 October 2026; the Keras and Teachable Machine notes on 29 October 2026.