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

Fine-tune a small pretrained model

Hook

This part built a residual block that keeps gradient flowing across depth, and a fine-tuning trick that keeps a small target task cheap to solve. Put them together: freeze a residual "backbone" entirely, and fine-tune only a tiny task-specific head on top of it.

Intuition

Two raw inputs pass through the exact same frozen residual block from earlier in this part. The backbone itself never changes — only its output becomes the input to whatever small head gets trained next.

Formalize

A "pretrained model" here is just the residual recursion from earlier — hi=hi1+wσ(whi1)h_i = h_{i-1} + w\cdot\sigma(w h_{i-1}), weights fixed — reused as a frozen feature extractor:

feature=Backbone(x0)y^=wheadfeature+bhead\text{feature} = \text{Backbone}(x_0) \qquad \hat y = w_{\text{head}}\cdot\text{feature} + b_{\text{head}}
  • feature\text{feature} — the frozen backbone's output for a given input: the representation the head trains on.
  • Backbone\text{Backbone} — the frozen, pretrained residual network reused as a fixed feature extractor.
  • wheadw_{\text{head}} — the task-specific head's weight, applied to the backbone's feature.
  • bheadb_{\text{head}} — the task-specific head's bias — in this example, the only parameter still being learned.
  1. Fine-tuning leaves almost nothing to learn

    Fine-tuning freezes the backbone and, in this example, even freezes wheadw_{\text{head}} at its correct pretrained value — leaving only bheadb_{\text{head}} to learn.

  2. From scratch means finding both head parameters together

    Training from scratch instead has to find wheadw_{\text{head}} and bheadb_{\text{head}} together, using the same two backbone features and the same tiny dataset.

Play

Fine-tuning the head's one remaining parameter reaches an exact fit in a single step. Training both head parameters from scratch is still measurably behind after 10 steps, and only approaches — never exactly matches — that same result even after 50.

Worked example

Backbone inputs x0=1x_0=-1 and x0=1x_0=1, one frozen residual layer, head target y=2feature+5y=2\cdot\text{feature}+5:

  1. The frozen backbone produces two well-separated features

    With one frozen layer and w=3w=3, h=x0+3σ(3x0)h=x_0+3\sigma(3x_0):

    • Backbone(1)=1+3σ(3)1+3(0.0474)0.858\text{Backbone}(-1) = -1+3\sigma(-3) \approx -1+3(0.0474) \approx -0.858
    • Backbone(1)=1+3σ(3)1+3(0.9526)3.858\text{Backbone}(1) = 1+3\sigma(3) \approx 1+3(0.9526) \approx 3.858

    Different enough that the two-point target line is easy to recover, not a near-duplicate pair.

  2. Fine-tuning the head's bias: solved in one step

    With whead=2w_{\text{head}}=2 frozen at its correct value, η=0.5\eta=0.5 lands bhead=5b_{\text{head}}=5 exactly. MSE (short for Mean Squared Error): 00.

  3. From scratch: the same ideal rate explodes; a safe one crawls

    That same η=0.5\eta=0.5, applied to both head parameters jointly from (0,0)(0,0), explodes to w1059w\approx1059 within 3 steps. A safe η=0.05\eta=0.05 instead reaches MSE 3.33\approx3.33 after 10 steps and only MSE 0.011\approx0.011 after 50 — closer, but still not the exact 00 that freezing the backbone got in a single step.

Checkpoint

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

Pick a learning rate to try it
Summary
feature=Backbonefrozen(x0),y^=wheadfeature+bhead\text{feature} = \text{Backbone}_{\text{frozen}}(x_0), \qquad \hat y = w_{\text{head}}\,\text{feature} + b_{\text{head}}

Nothing in this capstone is new mechanically — it's the residual block from earlier in this part, and the exact fine-tuning math from a few chapters back, applied to features instead of raw inputs. That's the actual practice of transfer learning: someone else's frozen backbone plus a small trained head, and every optimization lesson from this entire course — ideal learning rates, coupled parameters, the cost of starting from nothing — still applies to whatever tiny piece is left to fine-tune. This closes Part X — Advanced Architectures. The next part turns back to explainability, this time for the deeper, less transparent models built here.