Foundations to Frontier
Tests
E. Deep Learning › E19 Continual, Multi-Task and Transfer Learning

Transfer Learning and Fine-Tuning Strategies

Transfer learning reuses a network trained on a large source task to solve a target task with fewer labels. The main strategies are feature extraction (freeze the pretrained body and train a new head: a linear probe), full fine-tuning, partial fine-tuning of the top layers, layer-wise learning rates, and parameter-efficient methods such as adapters and LoRA. This page covers when transfer helps, how to choose a strategy, and the risk of negative transfer. In the exercises you build freezing masks, discriminative learning rates and a linear probe. You then pretrain a small network on 3000 source examples and transfer it to a related and an unrelated target task. With 30 related labels, the linear probe scored 0.72 and fine-tuning 0.67, against 0.55 from scratch. With 300 labels all three were within 0.04. On the unrelated task, frozen features hurt badly (0.52 against 0.88 from scratch), and fine-tuning recovered most of the loss (0.83).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Don’t start from zero

Training a network from scratch needs lots of labelled data. Transfer learning starts instead from a network already trained on a big related task, such as ImageNet photos or web text, and adapts it to yours. You can freeze the pretrained part and train only a new final layer, or gently retrain everything. The demo compares three strategies as the number of target labels grows (illustrative curves).

Transfer and efficiency lab
With 30 target labels (illustrative curves): scratch 0.59, linear probe 0.74, fine-tuning 0.82. Transfer matters most when labels are scarce; the probe plateaus because its features are frozen.
Why engineers care

Labelled data is scarce in aerospace and robotics: defect images, rare failure modes, new sensors. Starting from pretrained models (ImageNet CNNs, foundation models) is the default way to get good results from a few hundred labels.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Transfer learning starts from…
  2. 2. Freezing the body and training a new head is called…
  3. 3. Transfer helps most when target labels are…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Feature extraction (linear probe): freeze all pretrained layers and train only a new head. A 2048 → 10 head has 2048·10 + 10 = 20,490 parameters.
  • Full fine-tuning: update everything, with a learning rate about 10× smaller than for pretraining, often with warm-up.
  • Partial fine-tuning: unfreeze only the top layers, which hold the most task-specific features. Gradual unfreezing (ULMFiT) unfreezes from the top down.
  • Discriminative learning rates: lower layers get smaller rates, for example lr / 2.6^(depth from the top).
  • Parameter-efficient fine-tuning: adapters, prefix tuning, or LoRA. LoRA adds a low-rank update BA to a frozen weight: rank 8 on a 4096 × 4096 matrix adds 8·(4096 + 4096) = 65,536 parameters (0.4%).
  • Negative transfer: if source and target are unrelated, pretrained features can be worse than training from scratch.
📝 Quick check (Level 1)
0/3 answered
  1. 1. LoRA rank-8 parameters for a 4096 × 4096 weight:
  2. 2. Lower layers in discriminative fine-tuning get…
  3. 3. Pretrained features worse than scratch is called…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Fine-tuning in code

Exercise 1.

  • Build freezing masks.
  • Compute ULMFiT-style layer-wise learning rates.
  • Fit a ridge linear probe on frozen features.

Practice.

  • In PyTorch, set requires_grad=False on frozen parameters and pass parameter groups with their own learning rates to the optimiser.
  • Keep batch-norm layers in eval mode when the target set is tiny.
  • Hugging Face peft provides LoRA and adapters; timm provides pretrained vision backbones.
  • Always compare against a linear probe and a from-scratch baseline. Use the same preprocessing (normalisation, resolution) as in pretraining.
model = timm.create_model("resnet50", pretrained=True, num_classes=5)
for p in model.parameters(): p.requires_grad = False
for p in model.get_classifier().parameters(): p.requires_grad = True       # linear probe
opt = torch.optim.AdamW([{"params": model.layer4.parameters(), "lr": 1e-4},   # or unfreeze the top block
                         {"params": model.get_classifier().parameters(), "lr": 1e-3}])
🐍 Exercise 1: freezing, layer-wise rates and linear probes
Build a freezing mask, discriminative learning rates and a ridge linear probe.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Frozen parameters in PyTorch have…
  2. 2. LoRA is provided by…
  3. 3. Baselines to always run:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why it works. Lower layers learn general features (edges, textures, syntax) that many tasks share. Higher layers become task-specific; Yosinski and colleagues measured transferability falling with depth. If the target is a simple function of the source features, a linear probe needs only enough data to fit the head: few parameters, low variance.

Probe versus fine-tune. Fine-tuning can adapt the features but, with few labels, can also distort them and overfit. Kumar and colleagues showed it can even underperform probing out of distribution, and proposed linear probing first, then fine-tuning (LP-FT). With more data, fine-tuning usually wins.

Negative transfer. If the target depends on information the source network discarded, frozen features cannot recover it. Fine-tuning must relearn it, starting from a possibly poor initialisation. Domain similarity and the amount of target data decide which strategy wins.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Transferability tends to fall with…
  2. 2. LP-FT means…
  3. 3. Frozen features fail when the source…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

When does transfer help, and when does it hurt?

History.

  • J. Yosinski, J. Clune, Y. Bengio and H. Lipson, “How transferable are features in deep neural networks?” (NeurIPS 2014).
  • J. Howard and S. Ruder, “Universal language model fine-tuning” (ACL 2018).
  • E. J. Hu et al., “LoRA” (ICLR 2022).

Exercise 2.

  • World: inputs x ∈ ℝ²⁰, with shared latent features z = tanh(2Ax), where z has 8 dimensions.
  • Tasks:
    • source: 10 classes from z;
    • related target: 3 classes from other directions of z;
    • unrelated target: 3 classes from directions of x orthogonal to A, which z ignores.
  • Network: a 20 → 32 → 32 MLP pretrained on 3000 source examples for 300 steps (source accuracy 0.758).
  • Strategies for each target and size: from scratch, linear probe (frozen body, new head), and full fine-tuning (learning rate 0.003 vs 0.01). All use Adam for 300 steps.
target, labels scratch linear probe fine-tune
related, 30 0.548 0.722 0.674
related, 300 0.798 0.794 0.831
unrelated, 30 0.586 0.357 0.454
unrelated, 300 0.877 0.524 0.826
  • Transfer helps when labels are scarce and the tasks are related: +0.17 for the probe at 30 labels.
  • The advantage shrinks with data: at 300 labels all three are within 0.04.
  • Frozen features cause negative transfer on an unrelated task: 0.524 against 0.877 from scratch, because the pretrained features threw away the needed directions.
  • Fine-tuning recovers most of it (0.826), but still trails scratch.
  • Seeds: in seeds 1 and 2 the related 30-label probe scored 0.674 and 0.720 against scratch 0.572 and 0.608. The unrelated 300-label probe scored 0.484 and 0.477 against scratch 0.842 and 0.858.
  • Settings were reduced for speed: an earlier version (20 → 64 → 64, 5000 source examples) took 52 s in the browser. It gave the same pattern, but a smaller probe advantage at 30 labels (+0.09).
🐍 Exercise 2 (research): when does transfer help, and when does it hurt?
Pretrain an MLP on a source task; compare scratch, linear probe and fine-tuning on related and unrelated targets with 30 and 300 labels.

Transfer learning in AI, robotics and aerospace

  • Inspection: fine-tuning ImageNet backbones on a few hundred defect images of turbine blades or composites.
  • Remote sensing: adapting pretrained models to new satellites or spectral bands.
  • Robotics: fine-tuning vision-language-action foundation models on a new robot with limited demonstrations.
  • Design lesson: try a linear probe first; fine-tune when you have enough labels or the domain differs.

References

  1. J. Yosinski, J. Clune, Y. Bengio and H. Lipson (2014). “How transferable are features in deep neural networks?” NeurIPS.
  2. J. Howard and S. Ruder (2018). “Universal language model fine-tuning for text classification.” Proc. ACL.
  3. A. Kumar et al. (2022). “Fine-tuning can distort pretrained features and underperform out-of-distribution.” Proc. ICLR.
  4. E. J. Hu et al. (2022). “LoRA: low-rank adaptation of large language models.” Proc. ICLR.