CSC3104 Β· Module 4 of 9

Transfer Learning

Adapt pretrained models to a new problem

~56 min to study properly

Training a big vision model from scratch needs millions of labelled images. Transfer learning reuses a network already trained on a large dataset like ImageNet, and adapts it to your task.

Checkpoint Β· the examiner asks

What is catastrophic forgetting during fine-tuning, and under what dataset conditions would you freeze the backbone versus fine-tune the whole network?

In one minute

Reuse a backbone pretrained on a big dataset: early layers learn general edges and textures, only the head is task-specific. Small, similar data β†’ freeze the backbone and train a linear probe. More or different data β†’ fine-tune gently with small (discriminative) learning rates, unfreezing top-down, to avoid catastrophic forgetting.

Traps examiners look for
  • Fine-tuning everything with a large learning rate and wiping out pretrained features.
  • Forgetting to set requires_grad=False (or to exclude frozen params from the optimiser).
  • Assuming ImageNet features transfer to very different domains (e.g. X-rays) without fine-tuning.
Read

Study notes

01Why reuse a pretrained network

Training a modern vision model from scratch needs millions of labelled images and days of GPU time. Most projects have hundreds or a few thousand. Transfer learning starts from a network already trained on a large dataset (ImageNet: 1.2 M images, 1,000 classes) and adapts it.

It works because features are hierarchical: early layers learn edges, colours and textures that are useful for almost any image; middle layers learn patterns and parts; only the last layers are specific to the original 1,000 classes. So we keep the general part (the backbone) and replace the specific part (the head).

02Feature extraction vs fine-tuning

Feature extraction / linear probe β€” freeze the backbone and train only a new head:

model = resnet50(weights="IMAGENET1K_V2")
for p in model.parameters():
    p.requires_grad = False
model.fc = nn.Linear(2048, num_classes)        # the only trainable layer

Fast, needs little data, can't overfit much β€” but limited if your images differ a lot from ImageNet.

Fine-tuning β€” unfreeze some or all of the backbone and keep training with a small learning rate, so the features adapt to your domain.

Your dataSimilar to ImageNetDifferent (X-rays, satellite)
Smallfreeze backbone, train headtrain head, then gently fine-tune top blocks
Largefine-tune everythingfine-tune everything with discriminative LRs (or a domain-pretrained model)

03Catastrophic forgetting and how to fine-tune gently

If you fine-tune with a large learning rate, the first batches produce large, noisy gradients (the new head is random), which overwrite the useful pretrained features β€” catastrophic forgetting. Validation accuracy can end up worse than the linear probe.

Good practice:

  1. Train the head first with the backbone frozen until it is reasonable.
  2. Unfreeze from the top down β€” last block first, earlier blocks later if needed.
  3. Use discriminative learning rates: small for early layers (1e-5), larger for later layers and the head (1e-4 to 1e-3).
  4. Use warm-up, weight decay and strong augmentation; keep BatchNorm layers in eval mode when batches are tiny.

04Domain shift and foundation models

Domain shift β€” when your images look different from the pretraining data (grayscale X-rays, multispectral satellite tiles, microscope slides) β€” reduces how much transfers. The further the domain, the more layers you need to fine-tune, and the more a domain-specific pretrained model helps (e.g. one pretrained on medical images).

Today's backbones are foundation models trained with self-supervision on huge unlabelled collections β€” e.g. DINOv2, or CLIP's image encoder. Their features are general enough that a simple linear head often matches full fine-tuning for classification, and the same features serve segmentation and depth estimation. Always try a linear probe on a foundation model as a strong, cheap baseline.

Watch it done

Worked examples

Worked example 1

Counting trainable parameters

ResNet-50 has ~23.5 M backbone parameters and outputs 2,048 features. For a 12-class head, how many parameters train with (a) a linear probe and (b) full fine-tuning?

    Worked example 2

    Choosing a strategy

    You have 900 labelled chest X-rays for 3 classes. Which strategy, and what learning rates?

      Vocabulary

      Key terms

      DINOv2 β†’ DINOv3

      Meta's DINOv2 (2023) learned from 142M curated images with no labels at all; its features support segmentation and depth with simple linear heads. DINOv3 (2025) scaled self-supervised training to about 1.7 billion images and a 7-billion-parameter model.

      Practise

      Quick check

      0 of 8 correct so far. Wrong answers come with an explanation β€” and the buddy can unpack them.

      Q1You have 300 labelled bird photos. Best starting strategy?

      Q2Why use a smaller learning rate for early layers?

      Q3Which layers of a pretrained CNN transfer best to new tasks?

      Q4How do you freeze a layer in PyTorch?

      Q5What is catastrophic forgetting?

      Q6Discriminative learning rates means…

      Q7Small dataset of natural photos β€” best first strategy?

      Q8Why is DINOv2 a strong backbone choice?

      Exam-style

      Written practice

      Short answer6 marks

      Explain why transfer learning works and when you would freeze the backbone versus fine-tune.

      Short answer5 marks

      What is catastrophic forgetting, and list three techniques to prevent it.

      Long answer12 marks

      A cooperative wants to classify cassava leaf diseases (5 classes) from 2,000 phone photos. Design the full transfer-learning approach: backbone choice, staged training plan, learning rates, augmentation, evaluation, and what you would do if validation accuracy stalls.

      Watch

      Videos

      Fresh picks are chosen by AI every day.
      Hands-on

      Freeze or fine-tune?

      4 guided tasks: predict, experiment, explain β€” then challenge yourself. Plus 2 coding exercises you run right in the browser.

      Start the lab