ResNet and Identity Shortcuts
Stack enough convolutional blocks and a plain network's forward signal can shrink toward nothing before it ever reaches the end. An identity shortcut makes that mathematically impossible.
Overview
The idea in brief
ResNet's headline idea is the identity shortcut: instead of a block computing x_{i+1} = f(x_i), it computes x_{i+1} = x_i + f(x_i), adding the block's own input back onto its output. The usual explanation is about gradients flowing backward through very deep networks. This module shows the forward-pass version of the same mechanism — what happens to the signal itself, going forward, as it passes through many stacked blocks.
Depth
same fixed weight matrix W applied at every block, ReLU after each one — a stand-in for a stack of identical conv blocks
Signal Norm by Depth
—Per-Block Readout
Final Norm
ResNet and Identity Shortcuts: A Practical Guide
The forward-pass half of the same story the backward-pass gradient module tells.
The degradation problem
Before ResNet, simply stacking more convolutional layers past a certain depth made plain networks harder to train, not just slower — a well-documented empirical finding known as the degradation problem. One real contributor: if each block's weights shrink the signal even slightly, a long enough plain stack keeps shrinking it, layer after layer, until by the far end there is barely any signal left carrying information forward. A shortcut connection breaks that: because relu(f(x)) can never be negative, adding it to x can never make the running signal smaller than x was — the identity path is a floor the plain stack simply doesn't have.
The problem ResNet solved
Before 2015 the assumption was that deeper networks would be better, and the evidence said otherwise. A 56-layer plain network scored worse than a 20-layer one — not just on test data, but on training data.
That is the crucial detail. Worse test accuracy would be overfitting. Worse training accuracy means the deeper network could not even fit what the shallower one could, despite being strictly more expressive: it could in principle copy the 20-layer network and make the remaining 36 layers do nothing.
The problem was optimisation, not capacity. Gradients degrade as they pass back through many layers, and learning an exact identity mapping through a stack of convolutions and non-linearities turns out to be surprisingly hard.
Learn the difference, not the whole thing
ResNet's answer is one line of arithmetic:
output = F(x) + x
Instead of asking a block to produce the desired output H(x) directly, ask it to produce the residual F(x) = H(x) − x, and add the input back.
Now "do nothing" is trivially available: drive the block's weights towards zero and the output is exactly x. A layer that has nothing useful to add can get out of the way, which is precisely what the plain deep network could not manage.
The gradient consequence is just as important. Differentiating F(x) + x with respect to x gives F'(x) + 1. That +1 is a path along which the gradient flows back unchanged, however many blocks it passes through. The chain rule's product of factors can no longer collapse to nothing, because every block contributes a term of exactly 1.
That single addition made 50, 101 and 152-layer networks trainable, and the same idea now appears in essentially every deep architecture, transformers included.
What is inside a block
The basic block, used in ResNet-18 and 34:
x → Conv3×3 → BN → ReLU → Conv3×3 → BN → (+x) → ReLU
The bottleneck block, used in ResNet-50 and deeper, sandwiches an expensive 3×3 between two cheap 1×1 convolutions that shrink and then restore the channel count:
x → Conv1×1 (reduce) → Conv3×3 → Conv1×1 (restore) → (+x)
The bottleneck exists for cost. Doing a 3×3 convolution on 256 channels is four times the work of reducing to 64, convolving, and expanding back — which is why deep ResNets use it everywhere.
Two details worth knowing. The addition happens before the final ReLU, so the identity path is not passed through a non-linearity. And when a block changes the channel count or the spatial size, the shortcut cannot be a plain identity — a 1×1 convolution with matching stride is used to project x to the right shape.
Why adding the input back makes depth trainable
ResNet's change is one addition per block, and the reason it works shows up in the gradient. This measures a 40-layer plain stack against the same weights with shortcuts, finds that the naive shortcut has a problem of its own, and arrives at why a real residual block always has a normalisation inside it.
Guided tour
- Read the norms at depth 10. The plain stack's signal has shrunk to a small fraction of where it started; the version with the shortcut is larger than where it started, not smaller.
- Push depth to 20. The plain stack keeps shrinking — by block 20 there is very little of the original signal left. The shortcut version keeps growing instead.
- Bring depth back down to 1 or 2. At shallow depth the two barely differ — this problem is specifically about what happens over many stacked layers, not about any single block.
- Read the per-block table. Every row is a real matrix-vector multiply and ReLU, not a smoothed illustration — you can check the arithmetic at any single block.
What this simplification doesn't show
Here the shortcut version's norm keeps growing with depth rather than settling — this fixed, unnormalized toy has no mechanism to stop it, which is exactly why real ResNets pair every shortcut with batch or layer normalization to keep the growing signal in a well-behaved range. The point this module demonstrates is narrower and still real: an identity shortcut with a ReLU'd residual branch mathematically cannot let the running signal fall below where it started, in a way a plain stack of contractive layers can and does.
In one line
A plain stack of layers with a contractive weight matrix shrinks its forward signal geometrically with depth — the same kind of multiplicative decay that causes vanishing gradients on the way back. An identity shortcut adds a nonnegative quantity back onto the running signal at every block, which makes shrinkage below the starting point mathematically impossible. It is the same one-line change, x + f(x) instead of f(x), showing up on both passes through the network.
Why it works, in more than one sense
Three explanations are offered, and they are complementary rather than competing.
Optimisation. Identity is easy to represent, so adding layers cannot make the achievable function set worse in practice, only in principle.
Gradient flow. The +1 in the derivative gives every block a direct path back to the loss, which is what makes 100-layer training stable.
Ensemble behaviour. A network with n residual blocks contains 2ⁿ possible paths from input to output, since each block can be taken or skipped. Empirically, removing a single block from a trained ResNet barely changes its accuracy — behaviour much more like an ensemble of many shallow networks than like one very deep one.
The loss-landscape view adds a fourth: visualisations of the loss surface show that skip connections turn a chaotic, spiky landscape into a much smoother one, which is a fairly direct explanation of why optimisation succeeds.
The family, and its descendants
| Model | Depth | Notes |
|---|---|---|
| ResNet-18 / 34 | Basic blocks | Fast; good default for small datasets |
| ResNet-50 | Bottleneck | The workhorse; the most common backbone in vision |
| ResNet-101 / 152 | Bottleneck | Better accuracy, materially slower |
| Pre-activation ResNet | BN–ReLU–Conv order | Cleaner identity path; trains deeper |
| ResNeXt | Grouped convolutions | More accuracy at the same cost |
| DenseNet | Concatenate instead of add | Every layer sees all previous ones |
| ConvNeXt | Modernised ResNet | Matches transformers on vision benchmarks |
The idea escaped computer vision entirely. Every transformer block is x + Attention(LayerNorm(x)) followed by x + FFN(LayerNorm(x)) — the same residual structure, which is what makes 100-layer language models trainable. U-Net's skip connections carry the same intuition into segmentation.
Practical notes
- ResNet-50 pretrained on ImageNet is the sensible default backbone for a new vision project. It is well-supported everywhere, and fine-tunes reliably.
- The shortcut must match shapes. When channels or stride change, use the 1×1 projection; frameworks do this automatically, but hand-written blocks frequently get it wrong.
- Do not put a ReLU on the identity path. The whole point is that the path is clean.
- Batch normalisation and residuals work together. Removing BN from a deep ResNet usually breaks training unless the initialisation is adjusted to compensate.
- Depth is not free. ResNet-152 is roughly three times the compute of ResNet-50 for a few points of accuracy; on most problems the smaller model plus better data wins.
Questions people ask
Why add rather than concatenate? Addition keeps the channel count constant and costs nothing. DenseNet concatenates instead, which reuses features more explicitly at the cost of growing width.
Does the shortcut have parameters? Not when it is a plain identity. It does when a projection is needed to change shape.
Can I add skip connections to any network? Yes, provided the shapes match, and it usually helps for anything more than a few layers deep.
Why does the identity make gradients flow? Because differentiating F(x) + x gives F'(x) + 1, and that constant term cannot vanish however many blocks it passes through.
Is ResNet still relevant? Very. It remains one of the most-used backbones in production, and ConvNeXt shows a modernised version still competes with vision transformers.
How deep can I go? ResNet-1000 has been trained as an experiment. Beyond about 150 layers the accuracy returns are small and the cost is not.
Recap in one screen
- Deep plain networks were worse on training data — an optimisation failure, not overfitting.
- A residual block learns
F(x)and outputsF(x) + x, so doing nothing is easy to represent. - The derivative gains a
+1, giving gradients a clean path back through any number of blocks. - Bottleneck blocks use 1×1 convolutions either side of the 3×3 to cut cost.
- The same shortcut idea underpins transformers, U-Net and almost every modern deep architecture.