3.4.9 · D2Convolutional Neural Networks

Visual walkthrough — ResNet and skip connections

2,900 words13 min readBack to topic

We are going to follow one number as it travels forward through a stack of layers and then travels backward as a correction signal. Everything else — identity, residual, gradient highway — falls out of watching that one number.


Step 1 — What is a "layer", really?

WHAT. We draw the box as an arrow-fed cylinder. A value goes in on the left, comes out changed on the right.

WHY. Before we can talk about "adding back", we must be crystal clear that a plain network is only the right-hand output — the original is thrown away the instant the box finishes. That thrown-away is the whole story.

PICTURE. In the figure the orange arrow is the input ; the magenta arrow leaving the box is . Notice there is no copy of the orange arrow surviving past the box.


Step 2 — What we secretly want the box to compute

WHAT. We split the target into two possibilities and draw them side by side:

  • Sometimes the perfect answer is very different from the input.
  • Very often — especially deep in a network where features are already good — the perfect answer is almost the input itself: .

WHY. Ask the real question: which is easier to learn, the whole answer or just the change? If the best thing a layer can do is "leave the numbers nearly alone", then forcing it to rebuild exactly through multiplications and ReLU bends is wasteful and fragile. This is the seed of the whole idea.

PICTURE. The left panel shows far from (a big magenta jump). The right panel shows sitting almost on top of (a tiny nudge). The tiny nudge is what we want to make easy.


Step 3 — Give its job: learn only the change

WHAT. Rearrange that one equation by adding to both sides:

WHY. Now the box no longer has to invent the whole answer. It only has to describe how much to change . If no change is needed, the box can output — and is the easiest thing on earth for weights to produce (just push them toward zero). Compare: making a stack of nonlinear layers reproduce exactly is genuinely hard.

PICTURE. The orange input arrow now survives around the box (the curved shortcut). The box only produces the short magenta "change" arrow. The two arrows meet at a ⊕ and sum to the tall answer arrow.


Step 4 — The residual block, fully assembled

Inside the box there are, in order, two Conv layers (the weight multiplications), each followed by a BatchNorm step, with a ReLU bend between them.

WHAT. So the full inner function , written as one formula, is a Conv (weights , bias ), then a ReLU bend, then a second Conv (weights , bias ):

  • ::: weight matrices of the two Conv layers (the tunable numbers, collectively )
  • ::: biases — constant offsets added inside each Conv layer
  • ::: the bend that keeps positives, zeroes negatives — the source of nonlinearity

The BN steps are folded silently into the two Convs here (BN is a fixed rescale, so it merges into the surrounding and ); the diagram spells them out as separate boxes so the picture matches a real ResNet, while the formula keeps only the parts that carry weights.

Then we add the skip and only afterwards apply the final ReLU:

WHY. The final ReLU is applied after the addition so the identity path passes through the ⊕ completely unmodified — if we bent it first, the "keep the input alive" guarantee would break.

PICTURE. Follow the two roads: the long residual road (Conv → BN → ReLU → Conv → BN, matching the formula above) and the short skip road (a straight wire). They rejoin at ⊕, then one last ReLU.


Step 5 — Edge case: what if the two roads don't line up?

WHAT. We put a conv (with stride 2 and 128 filters, say) on the shortcut so it produces exactly the shape produces.

WHY. Without matching shapes the ⊕ is undefined — you cannot add a block to a block. The projection is the minimum fix: a conv is the cheapest possible reshaper, so the skip road stays almost free.

PICTURE. The clash is drawn as two mismatched grids (orange 56×56 vs magenta 28×28). The box on the skip road resizes the orange grid down so both grids match before ⊕.


Step 6 — Now run it backward: why the "+x" is a gradient highway

WHAT — first look at the sum before the final ReLU. Call the pre-activation sum (the value that enters the last ReLU). Differentiate with respect to the input using the chain rule:

  • ::: the sum , the number fed into the final ReLU
  • ::: how that sum moves when the input moves
  • the ::: comes from the skip road and can never disappear

WHY this tool. We use the derivative because a derivative answers exactly one question: "if I wiggle the input a little, how much does the output wiggle?" That wiggle-ratio is precisely what training multiplies down the chain. No other tool measures sensitivity.

WHAT — now include the final ReLU honestly. The true block output is . So the full slope carries one extra factor, the ReLU's own slope , which is where and where :

  • ::: the gate — if this unit is active (), if it is switched off ()
  • the bracket ::: still carries the protective whenever the gate is open

WHY this matters (the honest highway). The highway is real, but it is gated by the final ReLU: on units that are switched off () the whole thing is multiplied by and nothing flows through that unit. So why does ResNet still work? Because ReLU passes roughly half its units on average, and — crucially — the gate is a per-unit on/off switch, not a shrinking factor. An open gate multiplies by exactly (no shrinkage), whereas a plain deep network multiplies every unit by a fractional slope at every layer. Across the units that stay active, the bracket delivers its full with no attenuation, so the signal reaches early layers intact. (In the popular pre-activation ResNet the ReLU is moved off the main sum entirely, making the highway perfectly ungated — which is exactly why it trains even deeper networks.)

PICTURE. Two backward-pointing arrows. The magenta one crawls back through , getting shorter (multiplied by a small slope). The orange one shoots straight back along the skip with a fixed strength of — untouched, as long as the final ReLU gate is open.


Step 7 — Stacking many blocks: the highway spans the whole network

WHAT. Chain the brackets from Step 6 across all blocks. The signal from the deepest output back to the earliest output is the product of every block's bracket:

  • ::: signal reaching the earliest block's output
  • ::: signal at the deepest block's output
  • ::: multiply the brackets of blocks through together
  • each bracket ::: still carries its own protective

WHY. Expand the product and one term is : a direct path from the last block to the first that skips every nonlinearity. Even across 100 blocks, that path never shrinks. Contrast the plain network, whose product has no terms — every factor can be , so the whole product collapses.

PICTURE. Left: the plain-network product of small slopes fading to black by the bottom. Right: the ResNet product with a bright orange spine that reaches all the way down at full brightness.


The one-picture summary

Everything above — forward split, residual, skip, backward , stacked highway — compressed into a single diagram.

skip wire

input x

residual road F of x

add

final ReLU

output y equals ReLU of F of x plus x

Recall Feynman retelling — say it back in plain words

A plain layer throws your input away and must rebuild the whole answer from scratch. That is hard, and worse, the correction signal that teaches it has to squeeze back through every layer, shrinking each time until the early layers learn nothing.

ResNet does one small, brilliant thing: it keeps a copy of the input and carries it around the layers on a straight wire, then adds it back. Now the layers only have to learn the change — and if no change is best, they just output zero, which is easy.

The magic shows up when we teach the network backward. Because the sum is "change + input", its slope is "(slope of the change) + 1". That is a wire the correction signal rides with full strength. There is one honest caveat: the final ReLU gates each unit — where a unit is switched off, its signal is blocked — but where it is open, the gate multiplies by exactly , never a shrinking fraction. So across the active units the highway carries the signal to layer one at full brightness. That single is the whole trick.

Recall Quick self-check

Why is learning easier than learning the identity ? ::: Producing zero just means pushing weights toward zero; reproducing exactly through nonlinear ReLU layers is a precise, fragile target. In the backward pass, what is for the sum ? ::: — the is the skip road. What extra factor does the final ReLU add to the block's gradient? ::: , which is where and where — a per-unit open/shut gate. When do you need the projection ? ::: Only when and have different shapes (channel count or spatial size changed). In Step 7, what does denote? ::: The output of block (the input handed to block ).


Parent: this page expands the derivation in the topic note.