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.
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
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 it, going forward, as it passes through many stacked blocks. The shortcut connection means f(x) just needs to learn the *residual* — the gap between the desired output and the input — rather than the full mapping. If the best transformation at some layer is close to identity (which is common in deep networks), learning a near-zero residual is much easier than learning the identity function from scratch. This is why adding layers to a ResNet never hurts: a block that learns f(x) = 0 passes the input through unchanged. So extra depth at worst does nothing. Without shortcuts, deeper networks paradoxically do *worse* than shallower ones on both training and test data — the degradation problem that motivated the design. ResNet-50 uses "bottleneck" blocks (1x1 → 3x3 → 1x1 convolutions) to reduce computation. ResNet-18 and ResNet-34 use simpler two-layer blocks. When the shortcut crosses a dimension change (spatial downsampling or channel increase), a 1x1 convolution with stride 2 projects the input to the new shape. This page stacks blocks with and without shortcuts, shows the signal magnitude at each layer. And covers the degradation problem with a depth experiment.
Stack enough convolutional blocks and a plain network's forward signal can shrink toward nothing before it ever reaches the end.
In this guide
- The idea in brief
- The degradation problem
- The problem ResNet solved
- Learn the gap, not the whole thing
- What is inside a block
- Why adding the input back makes depth trainable
- Guided tour
- What this simplification doesn't show
- In one line
- Why it works, in more than one sense
- The family, and its descendants
- Real notes
- Questions people ask
- Recap in one screen
ResNet and Identity Shortcuts: A Practical Guide
The forward-pass half of the same story the backward-pass gradient module tells.
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 it, going forward, as it passes through many stacked blocks. The shortcut connection means f(x) just needs to learn the *residual* — the gap between the desired output and the input — rather than the full mapping. If the best transformation at some layer is close to identity (which is common in deep networks), learning a near-zero residual is much easier than learning the identity function from scratch. This is why adding layers to a ResNet never hurts: a block that learns f(x) = 0 passes the input through unchanged. So extra depth at worst does nothing. Without shortcuts, deeper networks paradoxically do *worse* than shallower ones on both training and test data — the degradation problem that motivated the design. ResNet-50 uses "bottleneck" blocks (1x1 → 3x3 → 1x1 convolutions) to reduce computation. ResNet-18 and ResNet-34 use simpler two-layer blocks. When the shortcut crosses a dimension change (spatial downsampling or channel increase), a 1x1 convolution with stride 2 projects the input to the new shape. This page stacks blocks with and without shortcuts, shows the signal magnitude at each layer. And covers the degradation problem with a depth experiment.
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 is signal decay. If each block's weights shrink the signal still 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. Since relu(f(x)) can never be negative, adding it to x can never make the running signal less than x was. The identity path is a floor the plain stack simply does not 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 key detail. Worse test accuracy would be overfitting. Worse training accuracy means the deeper network could not still fit what the shallower one could, despite being strictly more expressive. It could in principle copy the 20-layer network and make the left 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 gap, not the whole thing
ResNet's answer is one line of arithmetic.
output = F(x) + x
Instead of asking a block to give the desired output H(x) right, ask it to give the residual F(x) = H(x) − x. And add the input back.
Now "do nothing" is trivially on hand: drive the block's weights towards zero and the output is just x. A layer that has nothing useful to add can get out of the way. It is precisely what the plain deep network could not manage.
The gradient consequence is just as key. 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, since each block adds a term of just 1.
That single addition made 50, 101 and 152-layer networks trainable. And the same idea now appears in in effect each deep design, 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 costly 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 all over.
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. It 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.
Building on the same setup, the next block shows the left cases.
The next block covers the left steps.
The next block continues with the left demonstrations.
Building on the same setup, the next block shows the left cases.
The next block covers the left steps.
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 more than where it started, not less.
- Push depth to 20. The plain stack keeps shrinking — by block 20 there is very little of the first 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 namely about what happens over many stacked layers, not about any single block.
- Read the per-block table. Each 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. It is just why real ResNets pair each shortcut with batch or layer normalization to keep the growing signal in a well-behaved range. The point this module shows 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 each block. It 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, just in principle.
Gradient flow. The +1 in the derivative gives each block a direct path back to the loss. It is what makes 100-layer training stable.
Ensemble behaviour. A network with n residual blocks holds 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. It 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 fully. Each transformer block is x + Attention(LayerNorm(x)) followed by x + FFN(LayerNorm(x)) — the same residual structure. It is what makes 100-layer language nets trainable. U-Net's skip connections carry the same intuition into segmentation.
Real notes
- ResNet-50 pretrained on ImageNet is the sensible default backbone for a new vision project. It is well-supported all over, 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 often 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 often 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 less net 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 clearly at the cost of growing width.
Does the shortcut have params? 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 often helps for anything more than a few layers deep.
Why does the identity make gradients flow? Since 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 stays 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 count 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 each modern deep design.