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.

Input3 × 224 × 224Stem7×7 conv, s=2BN + ReLU3×3 maxpool, s=264 × 56 × 56Stage 1 / conv2_x3 × bottleneck256 × 56 × 56Stage 2 / conv3_x4 × bottleneck512 × 28 × 28Stage 3 / conv4_x6 × bottleneck1024 × 14 × 14Stage 4 / conv5_x3 × bottleneck2048 × 7 × 7HeadGlobal AvgPoolFC → 1000-d logits(drop for U-Net)Zoom: a single bottleneck block ⑧1×1 convreduce C/4BN + ReLU3×3 convspatial mixBN + ReLU1×1 convexpand 4CBNaddReLUoutputidentity / 1×1 projection ⑨Skip-tap points ⑩after every stage's last bottleneck→ feeds U-Net decoder at matching resolution→ enables fine localization→ defeats vanishing gradient (Lecture 1)
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
  1. Input1Stem2S13S24S35S46Head7
    ① 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.
  2. Input1Stem2S13S24S35S46Head7
    ② 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).
  3. Input1Stem2S13S24S35S46Head7
    ③ 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").
  4. Input1Stem2S13S24S35S46Head7
    ④ 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).
  5. Input1Stem2S13S24S35S46Head7
    ⑤ 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.
  6. Input1Stem2S13S24S35S46Head7
    ⑥ 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").
  7. Input1Stem2S13S24S35S46Head7
    ⑦ 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.
  8. Input1Stem2S13S24S35S46Head7Zoom: bottleneck1×1→3×3→1×1 ⊕residual ⊕skip-tap
    ⑧ Bottleneck block (zoom panel) — the Lego brick repeated 16 times in total. Step by step: 1×1 conv shrinks channels by 4× (so the next conv is cheap) → 3×3 conv mixes 9 neighbours → 1×1 conv expands channels back up. BN + ReLU sit between each conv.
  9. Input1Stem2S13S24S35S46Head7Zoom: bottleneck1×1→3×3→1×1 ⊕residual ⊕skip-tap
    ⑨ 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.
  10. Input1Stem2S13S24S35S46Head7Zoom: bottleneck1×1→3×3→1×1 ⊕residual ⊕skip-tap
    ⑩ 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
StageLayersOutputParamsRole
Stem7×7 conv, BN, pool64 × 56 × 56~9.5kedges, colour
conv2_x3 × bottleneck256 × 56 × 56~215klocal textures
conv3_x4 × bottleneck512 × 28 × 28~1.2Mobject parts
conv4_x6 × bottleneck1024 × 14 × 14~7.1Mmid-level semantics
conv5_x3 × bottleneck2048 × 7 × 7~14.9Mhigh-level features
Head (FC)GAP + FC 10001000~2.0Mclassification

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.