Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
ResNet,
explained.
Everyone believed deeper networks should be smarter networks — until they weren't. Add too many layers and performance got worse, even on the training data, and nobody could say why. This 2015 paper found the culprit and fixed it with a one-line idea so simple it now sits inside nearly every deep model, Transformers included.
Contents 18 sections
The delta The degradation problem The insight: a deep net should never be worse than a shallow one The skip connection Why it fixes training Why it still matters How it works The math The evidence Worked example: counting a bottleneck block, and one residual add ResNet trade-offs: what the shortcut costs and buys Common mistakes when using or reproducing ResNet Where ResNet shows up in production Since then Solve it yourself Questions Check yourself Where this sitsWhat changes against rungs 1–3: depth stops being the limit
Everything below this rung makes a network of a given depth train better: dropout generalises it, batch norm conditions it, Adam steps it sensibly. ResNet changes what depths are reachable at all. The problem it names is not overfitting, and the paper is careful to establish that: stacking more layers made the network worse on the training set as well. A model that cannot fit the data it has seen is not overfitting; it is failing to optimise.
The argument is almost embarrassingly simple. A deeper network contains a shallower one as a special case — set the extra layers to the identity and you have exactly the shallow model — so a deeper network should never be worse. That it was worse means the optimiser could not find the identity. So make the identity the default: instead of asking a block to learn its output H(x), ask it to learn the residual F(x), and add the input back: H(x) = F(x) + x. Now doing nothing costs zero effort, and every layer only has to learn its own correction.
Stated in units the ladder can carry: before this, useful plain networks topped out around 20-odd layers, with deeper ones degrading. The paper trains 152 layers to win ImageNet and reports a 1,000-layer variant as trainable. The skip adds no parameters when the shapes match — it is an addition, not a layer — which is why it is the cheapest structural idea on this ladder by a wide margin.
The degradation problem
By 2015, depth was the frontier — more layers, more power. But the authors hit a wall that made no sense: a 56-layer plain network had higher error than a 20-layer one, and not just on test data — on the training data too.
That rules out overfitting, which would show up only at test time. The deeper network literally couldn't fit data the shallower one handled easily. The problem wasn't capacity; it was that very deep plain networks had become too hard to optimize. This was the degradation problem.
The insight: a deep net should never be worse than a shallow one
Here's the logic that cracked it. Suppose your best 20-layer network is great. A 56-layer network could match it exactly — just make the 36 extra layers do nothing, passing their input straight through. So more depth should never hurt; worst case, the extra layers learn to be invisible.
The trouble is that a stack of plain layers finds "do nothing" — the identity function — surprisingly hard to learn. So the authors changed the architecture to make doing nothing the easy, default option.
The skip connection
Their fix: add a shortcut that carries a block's input directly to its output, and let the layers add to it. Instead of computing a whole new output, the block computes output = input + F(input). The layers only have to learn F — the residual, the change to apply — not the entire mapping.
F(x) → + → x + F(x)
Now "do nothing" is trivial: the block just learns F = 0, and the shortcut passes the input through untouched. Extra depth can only help, never actively hurt.
Why it fixes training
Skip connections do two quiet, crucial things. They make each block's default behavior "do no harm," so optimization starts from a sane place. And they give gradients a clean highway straight back through the network during training. Be careful about why that mattered, because the paper is: its plain baselines already used batch normalization, and the authors checked that their gradients did not vanish. The deeper plain nets were simply harder to optimize — the paper calls it the degradation problem. The gradient-highway argument below was made precise in the follow-up paper, Identity Mappings in Deep Residual Networks (He et al., 2016).
The reason is one derivative. Backprop scales the gradient by each block's Jacobian; for y = x + F(x) that Jacobian is:
In a plain net the gradient is a bare product of the layer factors — a^L — and if each factor is below 1 it decays to nothing across a deep stack. The residual's +1 adds an identity path, so the gradient always contains a term that skips every layer untouched and arrives at full strength:
The gradient can't reach zero when one of its paths is the identity — depth stops being fatal. The runnable version below lets you watch it happen.
With residual connections, the authors trained a network 152 layers deep — eight times deeper than typical nets of the day — and it kept getting better. The degradation problem simply vanished.
Why it still matters
The residual connection escaped computer vision and went everywhere. Look inside a Transformer — the architecture behind every modern LLM — and each block wraps its attention and feed-forward layers in exactly this output = input + sublayer(input) pattern. It's a big reason deep Transformers train stably at all.
ResNet's lesson is one of the most reused in all of deep learning: don't force a block to reinvent its input from scratch — hand it the input for free and let it learn only what to change. A one-line idea that made "deep" learning actually deep.
How ResNet is built: blocks, shortcuts and stages
- Start from a plain VGG-style baseline. Mostly 3 × 3 convolutions with two rules: layers producing maps of the same size have the same number of filters, and when the map size halves the filter count doubles, so each layer's cost stays roughly constant. Stride-2 convolutions downsample, and the network ends in global average pooling and a 1,000-way softmax. The 34-layer plain net costs 3.6 billion multiply-adds, 18% of VGG-19's 19.6 billion.
- Add a shortcut around every pair of 3 × 3 layers. A block computes y = F(x) + x, where F is the two stacked layers; the addition is element-wise and the second ReLU comes after it. Where the shape is unchanged the shortcut is the identity: no parameters and negligible compute.
- Handle the stages where the shape changes. Three options were compared: (A) zero-pad the extra channels so every shortcut stays parameter-free; (B) use a 1 × 1 projection, with stride 2, only where dimensions increase; (C) make every shortcut a projection.
- Use bottlenecks for depth. For 50 layers and more, each two-layer block becomes three layers: a 1 × 1 convolution that reduces the channels (256 to 64, for example), a 3 × 3 convolution at the reduced width, and a 1 × 1 that restores them. This keeps the time cost close to that of a two-layer block. Identity shortcuts matter most here: a projection joining the two wide ends would double both the block's time and its size.
- Stack the stages. After a 7 × 7 stride-2 convolution and max pooling, four stages work on 56, 28, 14 and 7 pixel maps. ResNet-18 and ResNet-34 use 2-2-2-2 and 3-4-6-3 basic blocks; ResNet-50, -101 and -152 use 3-4-6-3, 3-4-23-3 and 3-8-36-3 bottleneck blocks, at 3.8, 7.6 and 11.3 billion multiply-adds, so even the 152-layer net is cheaper than VGG-19.
- Train with batch norm and plain SGD. Batch normalization follows every convolution, before the activation; weights use He initialization; there is no dropout. SGD with momentum 0.9, weight decay 0.0001 and mini-batches of 256 starts at a learning rate of 0.1, divided by 10 when the error plateaus, for up to 600,000 iterations.
- Augment and evaluate. Each training image is resized so its shorter side is a random length from 256 to 480, then a 224 × 224 crop or its mirror image is taken, with per-pixel mean subtraction and standard color augmentation. Comparisons use 10-crop testing; the best results average fully convolutional predictions over five scales, with shorter sides from 224 to 640.
The CIFAR-10 version
To study extreme depth cheaply, the paper uses a 6n + 2 layer network on 32 × 32 images: three stages of 2n layers with 16, 32 and 64 filters on 32, 16 and 8 pixel maps, all with option A shortcuts. n from 3 to 18 gives 20 to 110 layers, and n = 200 gives 1,202. The 110-layer net needed a brief warm-up at a learning rate of 0.01 until training error fell below 80%, about 400 iterations, before returning to 0.1.
What the shortcut is not credited with here
The paper does not present the shortcut as a cure for vanishing gradients. The plain networks it beats were already trained with batch norm, which keeps forward signals at non-zero variance, and the authors checked that their backward gradients had healthy norms. They call the degradation an optimization difficulty, conjecturing that deep plain nets may converge exponentially slowly. The argument that the identity path carries the gradient back undiminished, through a Jacobian of 1 + ∂F/∂x, comes from the follow-up paper, Identity Mappings in Deep Residual Networks (He and colleagues, 2016).
The residual block, as the paper writes it
x— the block's input; in this design it is the output of a ReLU, so every entry is non-negative.F(x, {Wi})— the residual the stacked layers learn: two 3 × 3 convolutions in a basic block, or 1 × 1, 3 × 3 and 1 × 1 in a bottleneck, each followed by batch norm.+ x— element-wise addition, channel by channel, with no parameters and almost no compute.Ws— a linear projection, a 1 × 1 convolution in practice, used only to match dimensions; the comparison of options A, B and C shows it is not what fixes degradation.σ— the ReLU, applied again after the addition.
At one extreme, if F outputs zero, y = x and σ(y) = x because x is already non-negative, so the block is exactly the identity and a deeper network can reproduce a shallower one. At the other, remove the shortcut and F must learn the whole mapping: that is the plain network. Trained ResNets sit near the first extreme. Measured on CIFAR-10, their layer responses, the standard deviations of each 3 × 3 layer's output after batch norm, are generally smaller than in plain nets, and smaller still in deeper ResNets, consistent with each block making a small correction to a near-identity map.
What ResNet's ImageNet and CIFAR runs showed
ImageNet 2012 classification, 1.28 million training images, error on the 50,000-image validation set with 10-crop testing:
| Model | Shortcuts | Top-1 error | Top-5 error |
|---|---|---|---|
| plain-18 | none | 27.94% | — |
| ResNet-18 | A | 27.88% | — |
| plain-34 | none | 28.54% | 10.02% |
| ResNet-34 | A, zero-pad | 25.03% | 7.76% |
| ResNet-34 | B, project when growing | 24.52% | 7.46% |
| ResNet-34 | C, project all | 24.19% | 7.40% |
| ResNet-50 / 101 / 152 | B | 22.85 / 21.75 / 21.43% | 6.71 / 6.05 / 5.71% |
The plain pair is the key ablation. Plain-34 is worse than plain-18 and has higher training error throughout training, so it is failing to optimize rather than overfitting; with shortcuts the order flips and ResNet-34 beats ResNet-18 by almost 3 points. At 18 layers, where the plain net shows no degradation, the shortcut barely changes accuracy but speeds up early convergence. Shortcut type matters little: B beats A slightly, which the authors attribute to the zero-padded channels having no residual learning, and C beats B marginally thanks to thirteen extra projections, so B is kept for its lower cost. VGG-16 scored 28.07% and 9.33% under the same protocol.
A single ResNet-152 reached 4.49% top-5 error on validation with multi-scale testing, and an ensemble of six models of different depths won the ILSVRC 2015 classification task with 3.57% top-5 error on the test set; ResNet-based entries also won ImageNet detection and localization and COCO detection and segmentation. Swapping VGG-16 for ResNet-101 in Faster R-CNN raised COCO mAP@[.5, .95] from 21.2% to 27.2%, a 28% relative gain. On CIFAR-10 the 110-layer net reached 6.43% test error. The 1,202-layer net trained to under 0.1% training error but tested worse, at 7.93%, which the authors attribute to overfitting: 19.4 million parameters is more than such a small data set needs.
Worked example: counting a bottleneck block, and one residual add
Weights only, with batch norm and biases left out:
| Block | Computation | Weights |
|---|---|---|
| Bottleneck on 256 channels: 1×1 reduce to 64, 3×3 at 64, 1×1 restore to 256 | 256×64 + 9×64×64 + 64×256 | 69,632 |
| Basic two-layer block on 64 channels | 2 × 9×64×64 | 73,728 |
| Basic two-layer block on 256 channels | 2 × 9×256×256 | 1,179,648 |
| 1×1 projection shortcut between the two 256-channel ends | 256×256 | 65,536 |
The bottleneck carries 256-channel maps with fewer weights than a basic block carries 64-channel ones, which is how ResNet-50 and deeper nets keep each block's time cost close to a two-layer block's. A basic block at full 256-channel width would need 16.9 times as many weights. The last row shows why identity shortcuts matter most here: a projection would add 65,536 weights, taking the block to 135,168, 1.94 times its size, and since every weight is applied at every position the multiply-adds nearly double too. At the 56×56 stage the bottleneck costs 69,632 × 3,136, about 218 million multiply-adds per block.
And the add itself, on three illustrative channels. The input x = (1.0, 0.0, 2.0) comes out of a ReLU, so it is non-negative. Suppose the stacked layers produce F(x) = (0.1, −0.3, −0.2). Then y = x + F(x) = (1.1, −0.3, 1.8), and the ReLU after the add gives (1.1, 0, 1.8): a small correction to what came in. If the layers output F = 0, the block returns x exactly, which is how a deeper network can reproduce a shallower one; the layer-response measurements on this page put trained blocks close to that identity.
ResNet trade-offs: what the shortcut costs and buys
An identity shortcut adds no parameters and one element-wise addition. What it costs is memory and flexibility: the block's input must stay alive until the addition, so peak activation memory is higher than in a plain chain, and both branches must agree in shape, which forces a projection at every stage change.
| Plain deep CNN | ResNet | Vision transformer | |
|---|---|---|---|
| Compute per 224×224 image | VGG-19: 19.6 billion multiply-adds | ResNet-50: 3.8 billion; ResNet-152: 11.3 billion | Attention grows with the square of the patch count |
| Trainable depth | Degrades past roughly 20 layers | 152 on ImageNet, over 1,000 on CIFAR-10 | Dozens of blocks, each residual |
| Built-in assumptions | Locality, translation equivariance | The same | Few; learned from data |
| Data needed | Moderate | Moderate; strong on ImageNet alone | Large pre-training sets or heavy augmentation to beat ResNets |
For small and medium data sets a ResNet remains a strong, cheap default; vision transformers pull ahead as pre-training data grows.
Common mistakes when using or reproducing ResNet
- Putting operations on the identity path
The follow-up paper tried scaling, gating, 1×1 convolutions and dropout on the shortcut, and each trained worse than a clean identity. Pre-activation blocks go further and move batch norm and ReLU into the residual branch, so nothing sits between one block's output and the next block's input.
- Starting blocks far from the identity
Initializing the last batch norm γ in each residual branch to zero makes every block begin as the identity, which helps large-batch training; torchvision exposes it as
zero_init_residual. - Comparing against the 2015 numbers
Modern recipes, with longer schedules, stronger augmentation, label smoothing and cosine learning-rate decay, lift the same ResNet-50 by several points of top-1 accuracy. A new model trained that way and compared with the 2015 results measures the recipe as much as the architecture.
- Mixing up ResNet-50 variants
torchvision's ResNet-50 puts the stride-2 downsampling on the bottleneck's 3×3 convolution rather than the first 1×1, a variant often called v1.5 that is slightly more accurate and slightly slower. Reproductions and latency comparisons should say which one they ran.
- Mismatched input preprocessing
Pretrained weights expect inputs prepared exactly as in training; for torchvision, RGB scaled to [0, 1] then normalized with a fixed per-channel mean and standard deviation. BGR images or raw 0–255 pixels degrade transfer without any error.
Where ResNet shows up in production
- Pretrained backbones
torchvision and timm ship ImageNet-pretrained ResNets, ResNet-50 is a standard transfer-learning backbone, and MLPerf Inference uses it as its image-classification benchmark model.
- Detection and segmentation
Faster R-CNN and Mask R-CNN are most often built on ResNet-50 or ResNet-101 with a feature pyramid network, as in torchvision's
fasterrcnn_resnet50_fpnand Detectron2's model zoo. - Inside every transformer
Each attention and feed-forward sublayer is written as x plus sublayer(x), the same identity shortcut, and interpretability work reads that running sum as the residual stream.
- In interviews
Expect to separate degradation from overfitting, explain why an identity default eases optimization, do the bottleneck weight count, and compare pre- and post-activation blocks.
What the authors admit, and what happened next
The paper reports a negative result it did not have to: the very deepest variant it trains, past a thousand layers, performs worse than the 110-layer CIFAR-10 network despite training successfully, and the authors attribute it to overfitting on a dataset that small rather than claiming depth scales without end. Naming the point where your own curve turns over is rarer than it should be.
The stated mechanism is again the contested part. The paper's framing is that residuals are easier to learn than full mappings. Later work offered different accounts — that skips keep gradients flowing to early layers almost undiminished, and, in Veit and colleagues' reading, that a residual network behaves less like one very deep network than like an ensemble of many shallower paths, since dropping individual blocks at test time barely hurts it. All three accounts predict that it works; they disagree about what it is.
How it held up: it is the most universally adopted idea on this ladder. Every transformer block on this site is a residual block — attention and the feed-forward network are both written as x plus something — and the "residual stream" that interpretability work reads, on the transformer ladder's top rung, is exactly this addition viewed as a channel that every layer reads from and writes to. Rung 5 is partly a story about where the normaliser sits relative to this skip.
Watch the gradient vanish — then get saved
Through a deep plain stack the backward signal is a product of per-layer factors, and a product decays exponentially; one identity path changes that. This propagates a gradient back through a deep stack: in a plain net it's a bare product that collapses toward zero as layers pile up; in a residual net the sum-over-paths always includes the all-shortcut path, worth exactly 1, so the signal never dies. Watch a plain 100-layer net's gradient hit 10⁻¹⁶ while the residual floor holds at 1. Change the per-layer factor or the depth.
Write the body of resid_grad. Everything else in the file is
already written; this is the function the paper is about. Press ▶ Run to check it against
the 5 assertions below — they start red.
- A plain net's gradient shrinks as it deepens
- A deep plain net's gradient effectively vanishes
- The residual sum always contains the identity path, so it never vanishes
- Residual keeps the gradient vastly larger than plain at depth
- A dead residual branch still carries gradient 1 while plain dies
Questions people ask about ResNet
How does a ResNet bottleneck block work, and why does it use 1×1 convolutions?
A bottleneck block replaces two 3×3 convolutions with three layers: a 1×1 convolution that reduces the channels, for example from 256 to 64, a 3×3 convolution at that reduced width, and a 1×1 convolution that restores 256 channels, with an identity shortcut added around all three. The 1×1 layers let the expensive 3×3 operate on a quarter of the channels. Counting weights, a 256-channel bottleneck has 69,632 against 73,728 for a basic block at only 64 channels, so it carries a four times wider signal at about the same cost. That is what made 50, 101 and 152 layers affordable: ResNet-152 needs 11.3 billion multiply-adds, below VGG-19's 19.6 billion.
How are the 50 layers of ResNet-50 counted, stage by stage?
ResNet-50 starts with a 7×7, 64-channel convolution with stride 2 and a 3×3 max pool. Four stages follow, with 3, 4, 6 and 3 bottleneck blocks working on 56, 28, 14 and 7 pixel feature maps and outputting 256, 512, 1,024 and 2,048 channels. Each bottleneck has three convolutions, so the stages contribute 16 × 3 = 48 layers; adding the first convolution and the final 1,000-way fully connected layer gives 50. The 1×1 projection shortcuts at the first block of each stage that changes shape are not counted. It costs 3.8 billion multiply-adds. ResNet-101 and ResNet-152 differ only in their stage counts: 3-4-23-3 and 3-8-36-3.
Did ResNet solve the vanishing gradient problem?
Not by its own account. The plain networks the paper improves on were trained with batch normalization, which keeps forward signals at non-zero variance, and the authors verified that their backward gradients had healthy norms, so neither forward nor backward signals vanished. They describe the degradation of deep plain nets as an optimization difficulty and conjecture that such nets converge exponentially slowly. The familiar gradient-highway explanation, that a residual block's Jacobian is the identity plus the residual's own Jacobian so the gradient always has an unobstructed path back, was developed in the follow-up paper Identity Mappings in Deep Residual Networks (2016). It is a later account, not the original paper's claim.
What are ResNet shortcut options A, B and C?
They are three ways to handle shortcuts when a stage increases the number of channels. Option A keeps every shortcut parameter-free and zero-pads the extra channels. Option B uses a 1×1 projection, with stride 2, only where dimensions increase, and identity shortcuts elsewhere. Option C makes every shortcut a projection. On ResNet-34 the top-1 errors were 25.03%, 24.52% and 24.19% with 10-crop testing, against 28.54% for the plain network. The small spread led the authors to conclude that projections are not essential for fixing degradation, so they skipped C for cost and used B in the deeper bottleneck networks, where identity shortcuts keep the blocks cheap.
How is ResNet different from highway networks?
Highway networks, introduced shortly before ResNet, also add shortcut connections, but each one is controlled by a gate that has its own parameters and depends on the input. When a gate closes, the layer stops being residual and behaves like a plain layer. ResNet's identity shortcuts have no parameters and are never closed, so all information always passes through and every block learns only a residual on top of it. The ResNet paper also notes that highway networks had not shown accuracy gains at extreme depth, beyond about 100 layers, while it reports improvements up to 152 layers on ImageNet and trains networks of 110 and 1,202 layers on CIFAR-10.
5 questions to test what you just read
Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.
How does a stage layout of 3, 4, 23 and 3 bottleneck blocks add up to ResNet-101's 101 layers?
Show answer
(3 + 4 + 23 + 3) = 33 blocks × 3 convolutions = 99, plus the 7 × 7 stem convolution and the final fully connected layer = 101 weighted layers. The projection shortcuts are not counted.
How many convolution weights does a bottleneck block at 256 channels have, compared with a basic block at 64 channels, ignoring biases and batch norm?
Show answer
Bottleneck: 256×64 + 64×64×9 + 64×256 = 16,384 + 36,864 + 16,384 = 69,632. Basic: 2 × 64×64×9 = 73,728. Similar cost, yet the bottleneck's input and output are four times wider, which is why the deeper ResNets use it.
How much would replacing that bottleneck's identity shortcut with a 1 × 1 projection from 256 to 256 channels add?
Show answer
The projection adds 256 × 256 = 65,536 weights to a block of 69,632, nearly doubling it, which matches the paper's warning that projections on bottleneck shortcuts double both the time complexity and the model size.
Plain-34 has higher training error than plain-18. Why does that rule out overfitting as the cause of its worse test error?
Show answer
Overfitting means fitting the training set better while generalizing worse. A deeper net that fits its own training data worse is failing to optimize: it contains plain-18 as a special case, with the extra layers set to the identity, and the solver did not find even that.
Why might option A, zero-padding, trail option B by about half a point on ResNet-34?
Show answer
In A the extra channels of a widened shortcut are zeros, so for those dimensions the block has no input to correct and no residual learning happens there. B's projection gives those channels a learned path, at the cost of a few parameters: 25.03% against 24.52% top-1.
Making deep nets train
Seven papers that turned "deeper is better in theory" into a network that actually converges. Every later architecture paper assumes all of them.
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Paper Breakdowns
- Attention Is All You NeedThe paper that introduced the Transformer — the architecture underneath GPT, BERT, Claude, and Gemini. Self-attention, Query/Key/Value, multi-head attention, positional encoding, and the real BLEU results, explained in depth with analogies and animated visuals, not just equations.Read →
- Word2VecHow words became math. Dense word vectors learned from the company a word keeps, so king − man + woman lands near queen. Skip-gram, CBOW, the distributional hypothesis, and the origin of every embedding model powering search and RAG.Read →
- Vision Transformer (ViT)When an image became 16×16 words. Cut a picture into patches, treat each patch as a token, and feed them to a plain Transformer — no convolutions. Patch embeddings, the class token, and why data scale lets attention beat the CNNs that ruled computer vision for a decade.Read →
- Latent DiffusionThe paper behind Stable Diffusion. Compress an image into a small latent space with a VAE, run the diffusion denoising there instead of on pixels for a tens-of-times efficiency win, and steer it with text via cross-attention. The architecture that put text-to-image generation on consumer GPUs.Read →
- DDPMThe original denoising diffusion math — the paper that made diffusion work. A fixed forward process adds Gaussian noise over many steps; a U-Net learns the reverse. The masterstroke: train the network to simply predict the added noise with a plain MSE loss. The foundation under every modern image generator.Read →
- GANsThe counterfeiter and the detective. Two networks locked in a game: a generator forging fakes from noise and a discriminator trying to catch them. The minimax objective that taught machines to imagine, its notorious instabilities and mode collapse, and how diffusion later overtook it.Read →