Part X — Computer Vision: CNNs, ResNets, Object Detection & Segmentation · Chapter 6

Transfer learning & feature extraction

Hook

Every model in this course has started from scratch — random or zero weights, learning everything from its own training data. What if a huge chunk of the problem was already solved by someone else's model, and only a small piece was actually specific to your task?

Intuition

Two points, one shared slope. One approach starts from a pretrained slope and only has to learn where to shift it; the other has to rediscover the slope and the shift together, from nothing, using the exact same two points.

Formalize

Transfer learning freezes parameters already learned on a large source task and fine-tunes only the remainder on a small target task:

wfrozenfrom pretraining,bfine-tunedargminb  L(wfrozen,b;  target data)\underbrace{w_{\text{frozen}}}_{\text{from pretraining}}, \qquad b_{\text{fine-tuned}} \leftarrow \arg\min_b \; \mathcal{L}(w_{\text{frozen}}, b; \; \text{target data})
  • wfrozenw_{\text{frozen}} — the pretrained weight, kept fixed during fine-tuning.
  • bfine-tunedb_{\text{fine-tuned}} — the one remaining parameter, updated to fit the target task.
  1. From scratch means every parameter, coupled together

    Training from scratch instead optimizes every parameter jointly, starting from nothing.

  2. Freezing simplifies the optimization problem itself

    Freezing turns a coupled, multi-parameter optimization problem into a much simpler one — often, as here, a single parameter with an easy, well-behaved loss curve.

Play

The learning rate that solves transfer's one-parameter problem exactly, in a single step, sends the joint two-parameter problem into an explosive spiral within 3 steps. The same underlying data, the same starting point conceptually — but coupling two unknowns together changes what "safe" even means.

Worked example

Pretrained slope w=2w=2; target task y=2x+5y=2x+5, observed at just two points, (1,7)(1,7) and (3,11)(3,11):

  1. Freezing turns two unknowns into one

    With ww fixed at 22, the loss in bb alone is exactly 2(b5)22(b-5)^2-shaped — the same quadratic form from the hyperparameter-tuning chapter, whose gradient with respect to bb is 2(b5)2(b-5). Starting from b=0b=0: gradient =2(05)=10=2(0-5)=-10, so one step at η=0.5\eta=0.5 gives b00.5(10)=5b \leftarrow 0 - 0.5(-10) = 5 exactly. MSE (short for Mean Squared Error): 00.

  2. The same rate wrecks the joint problem

    Training ww and bb together from (0,0)(0,0) at that same η=0.5\eta=0.5, using the joint gradient (L/w,L/b)(\partial\mathcal{L}/\partial w,\partial\mathcal{L}/\partial b) each step:

    • Step 1: (w,b)(0,0)0.5(40,18)=(20,9)(w,b) \leftarrow (0,0) - 0.5(-40,-18) = (20, 9)
    • Step 2: (w,b)(20,9)0.5(196,80)=(78,31)(w,b) \leftarrow (20,9) - 0.5(196,80) = (-78, -31)
    • Step 3: (w,b)(78,31)0.5(944,392)=(394,165)(w,b) \leftarrow (-78,-31) - 0.5(-944,-392) = (394, 165)

    Overshooting further each step, nowhere near the target (2,5)(2,5).

  3. Even a safe rate is slow when there's more to learn

    At a stable η=0.1\eta=0.1, from-scratch training reaches (w,b)(3.24,2.01)(w,b)\approx(3.24, 2.01) after 5 steps — MSE 1.80\approx1.80. After 20 steps, 4x the budget, it's only improved to (w,b)(2.73,3.23)(w,b)\approx(2.73, 3.23) — MSE 0.63\approx0.63, still far from the transfer model's exact 00.

Checkpoint

Find the learning rate, among the three candidates, that makes from-scratch training explode after just 3 steps.

Pick a learning rate to try it
Summary
transfer: 1 unknown, closed-form-simplevsscratch: 2 coupled unknowns, slower and more fragile\text{transfer: 1 unknown, closed-form-simple} \qquad\text{vs}\qquad \text{scratch: 2 coupled unknowns, slower and more fragile}

Freezing pretrained weights doesn't just save compute — it changes the shape of the optimization problem itself, often turning a fragile, coupled search into something closer to the single-parameter toy problems from early in this course. That's the real reason transfer learning works so well with so little target-task data: there's simply less left to learn, and what's left tends to be far better-behaved. The next chapter turns from classification and reconstruction to a task with its own coordinates entirely: not just naming what's in an image, but drawing a box around exactly where it is.