3.4.9 · D3Convolutional Neural Networks

Worked examples — ResNet and skip connections

1,958 words9 min readBack to topic

This page is the "throw everything at it" companion to the ResNet topic note. We will not introduce a single new idea without a picture and a plain-word reason. If you have never seen a "channel" or a "gradient" before, start here at line one.

What a residual block does, in one picture

Before any example, let us fix the vocabulary so no symbol is ever used cold.

Figure — ResNet and skip connections

Look at the figure. The orange wire is the residual path (it does work). The blue wire is the skip — it copies across untouched. The little green circle is element-wise addition: sheet-by-sheet, pixel-by-pixel, the two stacks are summed. For that green to even be legal, the two stacks arriving must be the same shape. That single requirement — "shapes must match at the " — generates almost every case below.

The scenario matrix

Every situation a residual block can face reduces to one of these cells. Our examples cover all of them.

Cell Scenario What is special Example
A Shapes already match Identity skip, plain add Ex 1
B Channels grow + spatial shrinks Need projection Ex 2
C (degenerate) Block passes input through Ex 3
D Gradient flow, deep stack The "+1" highway Ex 4
E Vanishing-gradient limit Ex 5
F Bottleneck FLOP count Word problem, cost Ex 6
G Exam twist: does depth ever hurt? Concept trap Ex 7
H Numeric add on tiny tensor Sanity of "element-wise" Ex 8

Example 1 — Cell A: shapes already match


Example 2 — Cell B: channels grow, space shrinks


Example 3 — Cell C: the degenerate block


Example 4 — Cell D: the gradient highway


Example 5 — Cell E: the vanishing limit


Example 6 — Cell F: word problem, FLOP cost of a bottleneck


Example 7 — Cell G: exam twist, "does depth ever hurt?"


Example 8 — Cell H: numeric element-wise add


Recall Quick self-test

When can the skip be a bare identity? ::: When and share the exact same shape (channels, height, width). What survives backprop even if the residual path's slope is 0? ::: The full arriving gradient , thanks to the "+1" from the skip. Why is a bottleneck's conv 16× cheaper here? ::: Channels are cut 4×, and cost scales with , so . What does turn a residual block into? ::: The identity map .