Lecture L4 · Encoder
ResNet-50 — the encoder backbone
A 50-layer residual CNN that turns a 224×224 RGB image into a 7×7 grid of 2048-channel features. Used as the shared encoder for our Siamese pre/post damage model and the contracting path of the U-Net decoder.
In plain English — read this first
Think of ResNet-50 as a 5-floor factory that turns a photo into a meaning. The photo (a 224×224 RGB image) enters at floor 1. At each floor, the image gets smaller in width & height but thicker in channels — i.e. fewer pixels, but each pixel now carries more information about what is there, not just what colour it is.
- Channel = one "feature detector" output (edge detector, roof detector, rubble detector…). 64 channels = 64 such maps stacked.
- Convolution = a small sliding window (3×3 or 1×1) that mixes nearby pixels. Learned weights decide how.
- BN (Batch Norm) = re-centres values so training stays stable. ReLU = "keep positives, zero the rest" — adds non-linearity.
- Stride 2 = the window jumps 2 pixels at a time → output is half the size. That is how we go 224 → 112 → 56 → 28 → 14 → 7.
- Residual / skip (the ⊕ in the zoom panel) = "if this block can't improve things, just pass the input through". This single trick is what lets us stack 50 layers.
Figure walkthrough — each step beside its place in the pipeline
- ① Input image (3 × 224 × 224) — your RGB photo. 3 = red/green/blue channels. 224 × 224 = pixel height × width. Each number is a brightness in [0, 1] after ImageNet normalisation.
- ② Stem — the factory lobby. A 7×7 conv sweeps the whole image, BN+ReLU clean it up, then 3×3 max-pool keeps only the strongest signal in each 3×3 patch. Output:
64 × 56 × 56— 16× fewer pixels, but now we have 64 simple feature maps (edges, colour blobs). - ③ Stage 1 / conv2_x — 3 identical bottleneck blocks (see ⑧). Spatial size stays at 56×56, channels jump to 256. Learns local textures ("this looks like roof tiles", "this looks like grass").
- ④ Stage 2 / conv3_x — 4 blocks; the first halves the size (stride 2) →
512 × 28 × 28. Each "pixel" of this map now summarises an 8×8 region of the original photo. Learns object parts (window, wall, car door). - ⑤ Stage 3 / conv4_x — 6 blocks →
1024 × 14 × 14. Each "pixel" sees roughly a 16×16 chunk of the photo. This is where the strongest "is this a building / is it damaged" signal lives. - ⑥ Stage 4 / conv5_x — 3 blocks →
2048 × 7 × 7. Only 49 spatial positions left, but each carries 2048 abstract numbers ("kind of looks like a roof", "kind of looks like rubble"). - ⑦ Head — the classification exit. Global Average Pool turns each 7×7 map into one number (2048 numbers total), then a fully-connected layer outputs the 1000 ImageNet labels. We throw this part away for U-Net — we don't want a single label, we want a pixel map.
- ⑧ Bottleneck block (zoom panel) — the Lego brick repeated 16 times in total. Step by step:
1×1 convshrinks channels by 4× (so the next conv is cheap) →3×3 convmixes 9 neighbours →1×1 convexpands channels back up. BN + ReLU sit between each conv. - ⑨ Residual / shortcut (dashed orange arrow + ⊕) — the block's input is added back to its output. If the 3-conv stack discovers something useful, great. If not, the addition means the block effectively does nothing — and gradients still flow through the shortcut. This is the He et al. 2015 insight that made 50+ layer training possible.
- ⑩ Skip-tap points (the four green vertical lines) — we save a copy of the feature map at the end of each stage (56², 28², 14², 7²). In the next lecture the U-Net decoder will use these four maps to recover where things are when it paints the full-resolution damage map.
Layer-by-layer parameter count
| Stage | Layers | Output | Params | Role |
|---|---|---|---|---|
| Stem | 7×7 conv, BN, pool | 64 × 56 × 56 | ~9.5k | edges, colour |
| conv2_x | 3 × bottleneck | 256 × 56 × 56 | ~215k | local textures |
| conv3_x | 4 × bottleneck | 512 × 28 × 28 | ~1.2M | object parts |
| conv4_x | 6 × bottleneck | 1024 × 14 × 14 | ~7.1M | mid-level semantics |
| conv5_x | 3 × bottleneck | 2048 × 7 × 7 | ~14.9M | high-level features |
| Head (FC) | GAP + FC 1000 | 1000 | ~2.0M | classification |
Total ≈ 25.6M trainable parameters. The deepest stage holds the most weights but the cheapest 1×1 + 1×1 sandwich keeps FLOPs reasonable (~4.1 GFLOPs).
How this hooks into the rest of the pipeline
In our Siamese damage model, two copies of this encoder (sharing weights) process the pre- and post-disaster images. The four skip-tap feature maps from each branch are subtracted to produce difference features, which are then upsampled by the U-Net decoder (next lecture) into a pixel-accurate damage map.
Acronyms & jargon — quick reference
- CNN
- — Convolutional Neural Network; uses sliding filters instead of fully-connected layers.
- ResNet-50
- — 50-layer CNN with residual skips, He et al. 2015.
- Conv 3×3 / 1×1
- — a learned 3×3 (or 1×1) sliding window that mixes nearby pixels/channels.
- Stride
- — step size of the sliding window. Stride 2 halves H and W.
- BN
- — Batch Normalization; re-centres activations to mean 0 / variance 1 per batch.
- ReLU
- —
max(0,x)non-linearity. - MaxPool
- — keeps the strongest value in each window (downsampling).
- GAP
- — Global Average Pooling: average each channel into one number.
- FC
- — Fully-Connected (a.k.a. linear / dense) layer.
- Bottleneck
- — 1×1 → 3×3 → 1×1 sandwich that cuts compute by shrinking channels in the middle.
- Residual / Skip ⊕
- — add the block's input to its output so gradients always have a path home.
- Channel
- — one feature-detector map. 256 channels = 256 stacked maps.
- Feature map
- — a single H×W grid produced by one channel.
- FLOPs
- — Floating-point Operations; rough compute cost per forward pass.
- ImageNet
- — 1.3 M-image classification dataset used to pre-train the backbone.