Chapter 08

CNNs — Transfer Learning & Data Scarcity

By the end you can decide — given how much data you have and how similar it is to ImageNet — whether to freeze, fine-tune, or train from scratch, and at what learning rate, plus how augmentation and receptive fields fit in.

Reading: ~50 min Interactive: 3 widgets Source: Stanford CS231n · Yosinski et al. (2014) transferability

01 · Receptive field, revisited

Why stacked 3×3 beats one big kernel

The receptive field (Chapter 07) is the input region a neuron can see. Stacking small filters grows it cheaply: two 3×3 convolutions reach the same 5×5 RF as one 5×5 conv, but with fewer parameters and an extra non-linearity.

🔲 2× Conv(3×3)

RF = 5×5 · ~18C params · 2 non-linearities.

🔲 1× Conv(5×5)

RF = 5×5 · ~25C params · 1 non-linearity.

This is the VGG principle (Chapter 09): prefer deep stacks of 3×3 filters. Re-derive the RF for any stack:

Hands-on 2

Receptive field calculator

Set each layer's kernel K and stride S. The receptive field grows by (K−1)·jump per layer, and every stride multiplies the jump — so pooling makes the RF balloon. Padding is irrelevant to the RF.

64
LayerKSOutputJumpRF
Conv 16213
Pool 23124
Conv 32928
Pool 414410
Final RF
10
Final output
14
Covers input?
No
Try thisReproduce the exam stack: Conv k3 → Pool k4 s4 → Conv k5 → Pool k3 s3 → Conv k7 → Pool k2 s2 → Conv k9, input 500. The RF walks 3 → 6 → 22 → 30 → 102 → 114 → 306. The big jumps come right after each pool.
TakeawayReceptive field grows slowly through convs but leaps after each stride/pool, because the stride multiplies the step of every later layer. That is how a deep stack "sees" the whole image without a giant kernel.
key

CNN anatomy — and equivariance ≠ invariance

A CNN bakes in three assumptions: sparse connectivity (local kernels), weight sharing (the same filter everywhere), and a growing receptive field. Weight sharing makes convolution translation-equivariant — shift the input and the feature map shifts the same way. It is pooling (and ultimately global pooling) that converts that equivariance into approximate translation invariance: the prediction stops caring where the feature was. Conflating the two is a classic exam slip.

02 · Data augmentation

Make more data without collecting it

The problem. Deep nets are data-hungry, but labels are scarce. Augmentation manufactures variety with label-preserving transformations — and it is how you build in invariance: to be invariant to a transformation, train on images undergoing it (recall the two-headed horse, Chapter 06).

🔄 Geometric

Flips, crops, rotations, scaling. Label-preserving for most classification.

🎨 Photometric

Colour jitter, brightness/contrast, noise, grayscale.

🔀 Mixup

A convex combination of two images and their one-hot labels.

🧪 TTA

Test-time augmentation: average predictions over augmented copies.

Mixup (image AND label)
x~=λxi+(1λ)xj,y~=λyi+(1λ)yj\tilde{x} = \lambda x_i + (1-\lambda)x_j, \qquad \tilde{y} = \lambda y_i + (1-\lambda)y_j

The same λ\lambda mixes the labels — not the dominant one. That symmetry is the whole point of Mixup.

×

Two augmentation traps

Mixup’s target is the same convex combination of the labels, not the dominant one (2024 Q6). And the transformation must be label-preserving — rotating a clock or an MNIST digit changes its class, and an augmentation applied to only one class becomes a spurious cue.

03 · Transfer learning

Standing on ImageNet’s shoulders

A CNN pre-trained on ImageNet has already learned a general feature hierarchy (edges → textures → parts → objects). Reuse it:

  1. Load the pre-trained model; remove its classification head.
  2. Attach a new head for your classes (randomly initialised).
  3. Feature extraction: freeze the backbone, train only the new head.
  4. Fine-tuning: unfreeze (some of) the backbone, continue at a much lower LR (~1/10, e.g. 1e-5).

What to do depends on how much data you have and how similar it is to ImageNet:

Hands-on 2

Freeze, fine-tune, or train from scratch?

The choice is set by two questions: how much data do you have, and how similar is it to the source domain (ImageNet)? Pick both and read off the strategy, the learning rate, and which layers stay frozen.

🔒 Early conv
🔒 Mid conv
🔒 Deep conv
Head
Strategy
Feature extraction
Learning rate
normal (head only)

Freeze the whole backbone and train just a linear head. With little data, fine-tuning the backbone would overfit — the pretrained features already fit a similar domain.

Try thisCompare Little + Similar (freeze everything, train a head) with Lots + Similar(fine-tune all at a low LR). More data is what earns you the right to unfreeze the backbone without overfitting.
TakeawayAlways do transfer learning (frozen backbone, train the head) before fine-tuning, and fine-tune at ~1/10 the learning rate — a high rate overwrites the pretrained features (catastrophic forgetting).
×

Why the low LR — and do TL before fine-tuning

A high LR makes large updates that overwrite the pre-trained features — catastrophic forgetting. Do transfer learning (head only) before fine-tuning, so the head is sensible before you unfreeze the backbone (2024 Q6). A low LR is precisely what enables fine-tuning without erasing knowledge (2026 Q2).

Q

Exam · 2024 Q6 — transfer learning, Mixup, max-pool

The true statements:

  • VGG transfer recipe: keep only the dense (MLP) head trainable, freeze the conv backbone, train a few epochs.
  • Transfer learning before fine-tuning (given enough data) — warm up the head, then unfreeze.
  • Max-pool backprop routes the gradient only to the argmax location (you must track it).
  • ✗ “Mixup’s target is the dominant label” — it is the same convex combination of both labels.
  • ✗ “Augmentation layers must be removed at inference” — they are simply inactive, still in the graph.
  • ✗ “Any transform is beneficial” — some break label semantics or are unrealistic.
  • ✗ “Fine-tune before transfer learning” — the order is reversed.

04 · Measuring performance

Confusion matrix, ROC and AUC

Why accuracy lies. Consider the course’s industrial case study — classifying silicon-wafer defect maps, where genuine defects are rare. A model that predicts “no defect” every time scores 99% accuracy and is completely useless. With imbalanced or asymmetric-cost problems we need richer measures.

Everything starts from the confusion matrix, which tallies predictions against truth for the positive (“defect”) class:

✅ TP / TN

Correctly flagged defects (TP) and correctly cleared good wafers (TN).

⚠️ FP (false alarm)

A good wafer flagged as defective — wasted inspection.

❌ FN (miss)

A real defect passed as good — usually the costly error.

The metrics that matter under imbalance
Precision=TPTP+FP,Recall (TPR)=TPTP+FN,F1=2PRP+R\text{Precision}=\frac{TP}{TP+FP}, \quad \text{Recall (TPR)}=\frac{TP}{TP+FN}, \quad F_1=\frac{2\,PR}{P+R}

Precision: “of the wafers I flagged, how many were really defective?” Recall: “of the real defects, how many did I catch?”

They trade off as you move the decision threshold — and that trade-off curve is the ROC:

Hands-on 3

Why accuracy lies — precision, recall, ROC/AUC

Slide the decision threshold and watch the confusion matrix and the ROC point move. Turn on class imbalance (rare positives, like wafer defects): accuracy stays high even for a useless model, while recall and AUC expose it.

0.50
FPR →TPRAUC 0.87
Pred +Pred −
Actual +3812
Actual −743
Accuracy
81%
Precision
0.84
Recall
0.76
F1
0.80
AUC
0.87
Try thisSwitch to Imbalanced and push the threshold to 1.0: the model predicts "negative" for everything, accuracy stays around 94%, but recall collapses to 0 — it catches no defects at all. AUC (threshold-independent) is unmoved by this trick.
TakeawayUnder imbalance, accuracy is misleading. Use precision/recall/F1 for the operating point you care about, and report AUC — the probability a random positive outranks a random negative (0.5 = chance), which is threshold-independent.
key

ROC curve and AUC

A classifier outputs a score; sweeping the threshold from strict to lenient traces the ROC curve of true-positive rate vs false-positive rate. The Area Under the Curve (AUC) summarises it in one number: AUC = the probability that a random positive is ranked above a random negative. AUC = 1.0 is perfect, 0.5 is random guessing, and — unlike accuracy — it is threshold-independent and robust to class imbalance.

The takeaway for any deployed classifier: pick the metric that matches the cost structure (a missed defect is not a false alarm), and report ROC/AUC rather than a single accuracy number when classes are imbalanced.

05 · Exam intel

What the exam actually tests

Transfer learning and augmentation come as multi-select true/false; metrics come as “why is accuracy the wrong measure here?”.

Q1

Transfer learning recipe & order

Freeze the conv backbone and train only the dense head (feature extraction); do this before fine-tuning; fine-tune at a low LR (~1/10) to avoid catastrophic forgetting. Pick freeze vs fine-tune vs scratch by dataset size × similarity to the source.

Q2

Augmentation subtleties

Mixup mixes the labels too (same λ\lambda), not the dominant one. Augmentation layers are inactive at inference, not removed. Not every transform helps — it must be label-preserving.

Q3

Metrics under imbalance

Accuracy is misleading when one class is rare. Use precision/recall/F1 at your operating point, and report ROC/AUC — AUC is the probability a random positive outranks a random negative, 0.5 = chance, and it is threshold-independent.

06 · Common mistakes

Where students get this wrong

×

"Convolution is translation invariant"

Convolution is translation equivariant — shift the input, the feature map shifts. Pooling (and global pooling) is what turns equivariance into approximate invariance. The two are not the same.

×

"Mixup uses the dominant image's label"

The target is the same convex combination of both one-hot labels, with the same λ\lambda used for the images. Using the dominant label defeats the purpose.

×

"Augmentation layers must be removed at test time"

They stay in the graph and are simply inactive at inference. And not every transform is safe — label-breaking or unrealistic ones can hurt.

×

Fine-tuning first, or at a high learning rate

Do transfer learning (frozen backbone, train head) first, then fine-tune at ~1/10 the LR. A high rate overwrites the pretrained features — catastrophic forgetting.

×

"High accuracy means a good classifier"

Under class imbalance, predicting the majority class alone can score very high accuracy while catching none of the rare positives. Look at recall, F1, and AUC instead.

07 · Self-check

Can you answer these?

Four questions in the exact shapes the exam uses. Click an option for instant feedback.

Why prefer two stacked 3×3 convolutions over one 5×5 convolution?

Mixup forms x̃ = λx_i + (1−λ)x_j. What target ỹ does it use?

When adapting a pretrained CNN to a new task, you should…

On a dataset with 2% positives, a model predicts 'negative' for everything, scoring 98% accuracy. What does AUC reveal?

08 · Recap

One-screen summary

Chapter 08 — load-bearing ideas

  1. Stacked 3×3 convs reach the same receptive field as a bigger kernel with fewer parameters and more non-linearities (the VGG principle).
  2. Augmentation manufactures label-preserving variety and builds in invariance; Mixup interpolates images and labels (not just the dominant one).
  3. Transfer learning: freeze the backbone + train the head (feature extraction), then optionally fine-tune at a much lower LR (~1/10).
  4. Choose freeze vs fine-tune vs scratch by dataset size × similarity to the source domain.
  5. A high fine-tuning LR causes catastrophic forgetting; do transfer learning before fine-tuning.
  6. Under class imbalance accuracy lies; use the confusion matrix (precision/recall/F1) and report ROC/AUC — AUC = P(random positive ranked above random negative), 0.5 = chance, threshold-independent.
  7. Equivariance ≠ invariance: convolution is translation-equivariant; pooling makes it approximately invariant.