Skip to content
AI360XpertBeta
Core ML

Visual explainer

Transfer Learning

Reuse a learned representation, fit a target head and decide what to adapt using held-out predictions, while checking missing features and forgetting.

A source decision rule can mislabel target examples.
A source decision rule can mislabel target examples.

Transfer learning reuses a representation learned on a source task for a target task. You can fit a new head on fixed features or adapt some of the feature extractor too. Reuse is useful when the representation and training procedure suit the target; parameter count alone does not guarantee generalization.

Our synthetic feature space has two coordinates, z1,z2z_1,z_2. Circles have target label 0 and squares label 1, determined by whether z1>0z_1>0. The source head instead predicts from z2>0z_2>0, the dashed horizontal cut. It mislabels two of these four target examples, marked with crosses. These are constructed points, not a benchmark or an estimate of real transfer performance.

Reuse Features, Change The Head

The same features can support a different classification head.
The same features can support a different classification head.

For selected feature vector (1,−1)(1,-1), the source head ws=(0,1)w_s=(0,1) produces score −1, while target head wt=(1,0)w_t=(1,0) produces score +1. The projections show which coordinate each head reads; scores above zero predict class 1. The representation did not change. A new head can use information the source classifier did not need.

Yosinski et al. investigate which learned features transfer and how specialization and co-adaptation affect reuse. Their results do not establish universal transferability indices or a rule that early features must always stay frozen. The two-coordinate example here is an explanatory construction rather than a model of every visual hierarchy.

Freeze The Body Parameters

Feature extraction updates the head while holding body parameters fixed.
Feature extraction updates the head while holding body parameters fixed.

The toy body computes z=Axz=Ax with A=IA=I and input (1,−1)(1,-1); head w=(1,0)w=(1,0) yields score 1. Forward computation still passes through the body. The update loop selects only the head parameters, while the dashed body remains fixed. In practical fixed feature extraction, exclude frozen parameters from the optimizer and configure gradient tracking appropriately. Freezing a parameter does not make its mathematical derivative zero or automatically remove every previously allocated optimizer state.

The PyTorch transfer workflow demonstrates fixed feature extraction separately from fine-tuning. If gradients are needed for trainable modules before a frozen module, backward computation may still need to pass through its operations. The drawing specifies parameter update scope, not a universal gradient-stopping rule.

Adapt The Representation

Fine-tuning a feature transform can move target representations.
Fine-tuning a feature transform can move target representations.

For this controlled variant, old features have z1=±.2,z2=±1z_1=\pm.2,z_2=\pm1. A changed top transform multiplies the first coordinate by 5, moving them to z1=±1z_1=\pm1 while leaving the second coordinate fixed. Open markers are old positions; filled markers are new positions. The decision cut stays at z1=0z_1=0. This constructs a larger geometric margin without claiming a measured accuracy gain. Head-only training cannot move fixed body features; fine-tuning can. Choosing trainable blocks and learning rates requires validation, not a universal layer count or guaranteed safe rate.

Count What Is Trainable

A small head reduces the trainable parameter set.
A small head reduces the trainable parameter set.

The countable toy body and two-output head are each affine 2→22\to2 maps. Each grid has four weights and the two circles are biases, giving six parameters per module. Fixing the body leaves six of twelve parameters trainable. This two-output count illustration differs from the earlier single-score head; it demonstrates accounting, not a second benchmark.

For a larger shape example, a linear 512→10512\to10 head has 512(10)+10=5,130512(10)+10=5{,}130 trainable parameters with bias. Training fewer parameters can reduce update storage and computation, but does not eliminate overfitting, forward cost or the need for held-out data. There is no parameter-per-example threshold that proves a model cannot memorize.

Compare Held-Out Predictions

Held-out predictions can distinguish adaptation choices.
Held-out predictions can distinguish adaptation choices.

This separate synthetic validation set has feature values (−.8,−.2,.2,.8)(-.8,-.2,.2,.8) and labels (0,0,1,1)(0,0,1,1). Suppose head-only adaptation yields a cutoff .5 and another adaptation yields cutoff 0. Predicting 1 strictly above the cutoff gives (0,0,0,1)(0,0,0,1) versus (0,0,1,1)(0,0,1,1): three correct versus four. Both rows keep the samples and scale fixed. The numbers are deliberately constructed candidate outputs, not evidence that fine-tuning always wins.

Use validation data to compare training choices, including a suitable scratch baseline when needed, while reserving an independent test set for final evaluation. Repeated tuning against a small validation set can itself overfit. Dataset size and domain similarity inform experiments; they do not provide fixed universal decision thresholds.

Check What Features Discard

A frozen representation can discard a target distinction.
A frozen representation can discard a target distinction.

Change the target to depend on coordinate bb. Inputs (a,b)=(0,−1)(a,b)=(0,-1) and (0,1)(0,1) have opposing labels, but a frozen extractor f(a,b)=(a,0)f(a,b)=(a,0) maps both to the same vector. The overlaid circle and square show the collision. A deterministic head receiving only that representation cannot separate them, however many parameters it has. Adapting the representation or adding a useful input signal may be necessary. Apparent domain distance alone does not prove negative transfer; the retained information and comparative target performance matter.

Cache Fixed Features

Caching fixed features avoids repeated body evaluation.
Caching fixed features avoids repeated body evaluation.

The table stores four corner vectors from a fixed extractor. Once computed for fixed inputs, those rows can train a head repeatedly without reevaluating the body. The loop denotes repeated head training on stored features. This trades storage for saved computation. The cache must match the intended preprocessing and model state: random augmentation, changing normalization buffers or fine-tuned weights can make it stale. A frozen body alone does not make every feature deterministic.

Freeze Parameters And State Separately

Frozen parameters do not freeze batch-normalization statistics.
Frozen parameters do not freeze batch-normalization statistics.

Suppose BN scale and shift stay fixed at γ=1,β=0\gamma=1,\beta=0, but the body is in training mode and tracks running moments. With running mean 0, current batch mean 10 and momentum .1, the buffer becomes .9(0)+.1(10)=1.9(0)+.1(10)=1. The arrow shows that state change even though the affine parameters are frozen. Gradient flags and train/eval mode control different things. Check batch normalization when deciding which running statistics to adapt or preserve.

Where It Breaks

Adapting to the target can damage a source prediction.
Adapting to the target can damage a source prediction.

Use scalar model y=wxy=wx at input x=1x=1. The source wants output +1 and the target wants −1, giving Ls=12(w−1)2L_s=\tfrac12(w-1)^2 and Lt=12(w+1)2L_t=\tfrac12(w+1)^2. Start at w=1w=1: source loss is zero and target loss is 2. A target gradient step with derivative 2 and illustrative learning rate 1 moves to w=−1w=-1. Target loss becomes zero, but source loss becomes 2 and the source prediction flips sign. Both curves share the same weight and loss axes.

This objective conflict shows forgetting can occur even while target optimization succeeds. It does not claim that every fine-tuning step destroys source knowledge or that a smaller rate removes an underlying conflict. Evaluate any behavior that must be retained; transfer offers an initialization and representation, not a guarantee that all previous behavior survives.

The Quick Version

  • A new head can reuse fixed features for a new task.
  • Fine-tuning changes features as well as classifier parameters.
  • Count biases and distinguish frozen parameters from model state.
  • Compare adaptation choices using held-out predictions.
  • A head cannot recover a distinction absent from its input.
  • Target adaptation can conflict with source behavior.