ResNet
Deep Residual Learning for Image Recognition
Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
7
Concepts
10
Formulas
7
Demos
Paper Overview
ResNet (Residual Networks) introduced skip connections that allow training of much deeper networks than previously possible. Before ResNet, networks beyond ~20 layers suffered from the degradation problem -- deeper networks had higher training error, not due to overfitting, but due to optimization difficulties. He et al. demonstrated this empirically: a 56-layer plain network had higher training AND test error than its 20-layer counterpart on CIFAR-10, proving the problem was not capacity-related but optimization-related.
The key insight is deceptively simple: instead of asking a stack of layers to learn a desired mapping H(x) directly, let them learn the residual F(x)=H(x)−x. The output becomes H(x)=F(x)+x. If the optimal transformation is close to identity (which is common in deep networks where later layers refine rather than transform), pushing F(x) toward zero is far easier than learning an identity mapping through a stack of nonlinear layers. This is because the zero mapping is a natural attractor for weight decay and initialization near zero, whereas learning identity through conv-BN-ReLU stacks requires precise weight coordination.
ResNet won 1st place in the ILSVRC 2015 classification task with a 152-layer network achieving 3.57% top-5 error (surpassing human-level performance of ~5.1%). The same architecture also won 1st place in ImageNet detection, ImageNet localization, COCO detection, and COCO segmentation -- a clean sweep across all five tracks. The 152-layer ResNet has 60M parameters and 11.3B FLOPs, yet trains stably with standard SGD and batch normalization.
Chapter Roadmap
Click any topic to jump in
Residual Learning: The Core Idea
Learn the residual $F(x) = H(x) - x$ instead of $H(x)$ directly — small perturbations from identity.
Gradient Flow and Vanishing Gradients
Skip connections turn a multiplicative gradient chain into an additive one — a highway that cannot vanish.
Bottleneck Architecture
1×1 → 3×3 → 1×1 squeeze-expand pattern — ~17× cheaper than basic blocks at matched width.
Network Depth and Performance
Plain nets degrade past ~20 layers; ResNets keep improving to 152+ — optimization was the bottleneck, not capacity.
Pre-Activation ResNet (Identity Mappings)
Moving ReLU/BN inside $F$ keeps the skip path a pure identity — enables 1000-layer training.
ResNeXt: Aggregated Residual Transformations
Aggregated transformations via grouped convs — cardinality as a new scaling axis beyond depth and width.
Squeeze-and-Excitation Networks (SE-Net)
Channel attention via GAP → MLP → sigmoid reweighting — a near-free accuracy boost.
Concept by concept
7 sections, in reading order.
Skip connections allow the network to learn residual functions with reference to the layer inputs, instead of learning unreferenced functions. This reformulation does not add any parameters or computational complexity, yet fundamentally changes the optimization landscape.
The Problem
As networks get deeper, they become harder to train -- but not for the reason you might expect:
- A 56-layer plain network has higher training error than a 20-layer one on CIFAR-10. This is not overfitting -- the training loss itself is worse.
- This is the degradation problem: the optimization landscape becomes so complex that SGD cannot find a good solution, even though a solution provably exists (the 20-layer solution + identity layers).
- Batch normalization solved the vanishing/exploding gradient problem for ~20-30 layers, but degradation persists beyond that because the issue is not gradient magnitude but the difficulty of the loss surface.
- Mathematically, if you have a good 20-layer network and add 36 identity layers, the 56-layer network should be at least as good. But plain networks cannot learn these identity mappings through their nonlinear layer stacks -- the conv-BN-ReLU sequence makes identity a non-trivial function to represent.
- Experiments on ImageNet showed a 34-layer plain net had 28.54% top-1 error vs 25.74% for an 18-layer plain net -- adding layers made it worse.
The Solution
Residual Learning fundamentally changes what the network learns:
Instead of asking layers to learn H(x) directly, we reformulate: learn F(x)=H(x)−x, then reconstruct H(x)=F(x)+x.
Why this reformulation is so powerful:
-
Zero initialization advantage: If the optimal output is close to the input (common in deep networks where later layers make small refinements), F(x) only needs to be close to zero. With standard weight initialization (near zero) and weight decay pushing weights toward zero, the residual branch naturally starts near identity. A plain network must learn identity through conv-BN-ReLU, which is highly non-trivial.
-
Gradient highway: The addition y=F(x)+x means ∂x∂y=∂x∂F+I. The identity matrix I provides an unconditional gradient path that does not decay with depth.
-
Loss surface smoothing: Li et al. (2018) later showed that skip connections make the loss landscape significantly smoother -- the loss surface of a ResNet has fewer local minima and saddle points compared to an equivalent plain network.
-
Ensemble interpretation: Veit et al. (2016) showed ResNets behave like ensembles of shallow networks. Removing any single residual block has minimal effect, suggesting the network learns a collection of paths of varying depth rather than a single deep pipeline.
Basic residual block (used in ResNet-18/34):
- Input: x with C channels at spatial size H×W
- Conv 3x3 (C→C) → BN → ReLU → Conv 3x3 (C→C) → BN
- Add x (element-wise), then ReLU
- Output: same shape H×W×C
When spatial dimensions change (e.g., stride-2 downsampling from 56x56 to 28x28), a projection shortcut uses a 1x1 conv with stride 2 to match dimensions: y=F(x)+Wsx where Ws is a learned projection.
Key Points
- 1
Output: y=F(x,{Wi})+x -- element-wise addition with zero extra parameters
- 2
Skip connection provides an identity mapping that costs nothing in compute or memory
- 3
When dimensions change (stride-2), a 1x1 projection shortcut Ws matches spatial/channel dims
- 4
Residual blocks make identity the default -- the network only needs to learn deviations from identity
- 5
Empirically, learned residual responses F(x) have small magnitudes, confirming that layers learn small perturbations rather than complete transformations
- 6
ResNets behave as implicit ensembles of many shallow paths (Veit et al., 2016)
Mathematical Formulation
Residual Block Output
y=F(x,{Wi})+x
F(x) represents the residual mapping learned by stacked layers. When F has 2 layers: F = W₂ * ReLU(BN(W₁ * x)). The dimensions of F(x) and x must match for element-wise addition.
Projection Shortcut (dimension mismatch)
y=F(x,{Wi})+Wsx
W_s is a 1x1 convolution that adjusts channels and/or spatial dimensions. Used when stride > 1 or input/output channels differ. Adds parameters but only at stage boundaries.
Mathematical Intuition
Instead of learning H(x) directly, a residual block learns F(x)=H(x)−x, so the output is y=F(x)+x. If the optimal mapping is near-identity (common in very deep nets), F only needs to learn a small perturbation — much easier than learning identity from scratch. The gradient becomes ∂x∂y=1+∂x∂F, with a guaranteed +1 baseline.
Skip connections provide a direct path for gradients during backpropagation, creating a 'gradient highway' that ensures every layer receives a meaningful learning signal regardless of network depth.
The Problem
In deep networks without skip connections, gradients during backpropagation face compounding attenuation:
- At each layer l, the gradient is multiplied by the local Jacobian ∂hl−1∂hl, which depends on the weight matrix and activation function derivative.
- For a network of depth L, the gradient at layer 1 involves a product of L Jacobian matrices: ∂h1∂L=∏l=2L∂hl−1∂hl.
- If each Jacobian has spectral norm < 1 (common with sigmoid/tanh activations), gradients decay exponentially: after 50 layers, a factor of 0.950≈0.005 -- effectively zero.
- ReLU helped by having gradient exactly 1 for positive inputs, but dead ReLU units (gradient = 0) create "holes" in the gradient path.
- Batch normalization stabilized gradient magnitudes within individual layers but could not prevent the multiplicative decay across many layers.
- The practical consequence: in a 56-layer plain network, the first 20 layers receive gradients so small that their learning rate is effectively zero -- they stop contributing to the network's representation.
The Solution
Skip connections create gradient highways with a guaranteed minimum gradient magnitude:
For a single residual block with output y=F(x)+x, the backpropagated gradient is:
∂x∂L=∂y∂L⋅∂x∂y=∂y∂L⋅(1+∂x∂F)
The +1 term is the critical insight. It means:
-
Even if the residual branch gradient ∂x∂F vanishes completely (equals 0), the gradient through the skip path is exactly the upstream gradient -- no attenuation at all.
-
For a chain of L residual blocks, the gradient from loss L to the input x0 can be decomposed as a sum over all possible paths through the network. One of those paths is the "direct path" through all skip connections, which has gradient magnitude 1 regardless of depth.
Formally, for a chain of residual blocks:
xL=x0+∑i=0L−1Fi(xi)
∂x0∂L=∂xL∂L⋅(1+∂x0∂∑i=0L−1Fi(xi))
The "1" term ensures the gradient signal from the loss reaches every layer without multiplicative decay. The residual terms ∂x0∂Fi provide additional gradient signal but are not required for training to work.
Practical impact: He et al. showed that a 1202-layer ResNet trains successfully on CIFAR-10 (though it slightly overfits due to the small dataset). A 1202-layer plain network would be completely untrainable.
Key Points
- 1
Plain networks: gradient magnitude decays exponentially as O(γL) where γ<1 and L is depth
- 2
ResNet: gradient has additive +1 term from the identity path, guaranteeing non-zero gradient at every layer
- 3
The gradient decomposes into 2L paths of varying lengths -- short paths dominate learning, providing an implicit ensemble effect
- 4
Batch normalization within residual blocks keeps the residual branch gradients well-scaled, while the skip path handles the baseline signal
- 5
A 1202-layer ResNet trains successfully on CIFAR-10; equivalent plain networks cannot train beyond ~60 layers
- 6
The gradient highway also accelerates convergence: ResNet-34 converges faster than an 18-layer plain net despite being nearly 2x deeper
Mathematical Intuition
In a plain L-layer net, ∂x0∂L=∏l=1L∂xl−1∂xl — a product that vanishes exponentially. ResNet gives ∂x0∂L=∂xL∂L∏l(1+∂xl−1∂Fl), and expanding yields a sum containing a direct ∂xL∂L term. Gradients literally cannot vanish — they have a highway back to the input.
For deeper networks (ResNet-50 and beyond), bottleneck blocks use 1x1 convolutions to create a channel compression-expansion pattern that reduces computational cost by ~17x while maintaining representational power. This design is what makes 100+ layer networks practical.
The Problem
Scaling basic residual blocks (two 3x3 convs) to 50+ layers creates a computational wall:
- At the deepest stage (conv5_x), feature maps have 512 channels at 7x7 spatial resolution.
- A single basic block at this stage: two 3x3 convolutions with 512 input and 512 output channels.
- Parameters per block: 2×(512×512×3×3)=4.72M parameters.
- With 3 blocks at this stage alone: 14.16M parameters just for the final stage.
- FLOPs per block at 7x7: 2×(512×512×3×3×7×7)=231M FLOPs.
- For a 50-layer network with basic blocks, total parameters would exceed 80M and FLOPs would be impractical.
- The 3x3 convolution is the bottleneck: it scales as O(C2) in parameters, making wide networks expensive.
The Solution
The bottleneck block uses a 3-layer design that squeezes channels through a narrow "bottleneck" before expanding back:
Layer-by-layer data flow (for the conv4_x stage with 1024-channel input):
-
1x1 conv (reduce): 1024→256 channels. Parameters: 1024×256=262K. This is a learned dimensionality reduction -- it projects the high-dimensional feature into a compact representation.
-
3x3 conv (transform): 256→256 channels. Parameters: 256×256×3×3=590K. The expensive spatial convolution now operates on only 256 channels instead of 1024, reducing cost by 16×.
-
1x1 conv (expand): 256→1024 channels. Parameters: 256×1024=262K. Restores the original channel dimension so the skip connection addition works.
Total parameters per bottleneck block: ~1.11M vs ~18.87M for equivalent basic blocks (1024×1024×9×2). That is a ~17x reduction.
The expansion ratio r=4 is used throughout: the bottleneck width is always C/4 where C is the output channels. At each stage:
| Stage | Output Channels | Bottleneck Width | Spatial Size |
|---|---|---|---|
| conv2_x | 256 | 64 | 56x56 |
| conv3_x | 512 | 128 | 28x28 |
| conv4_x | 1024 | 256 | 14x14 |
| conv5_x | 2048 | 512 | 7x7 |
Each BN layer follows each conv layer, and ReLU follows each BN (in the original post-activation design). The skip connection adds the input directly to the output of the third BN layer, followed by a final ReLU.
Why 1x1 convolutions work: Despite having no spatial extent, 1x1 convolutions perform cross-channel feature recombination. They act as learned linear projections across the channel dimension, enabling the network to discover which channel combinations are informative before the expensive 3x3 spatial processing.
Key Points
- 1
The 1x1-3x3-1x1 pattern reduces parameters by ~17x compared to two stacked 3x3 convolutions at the same channel width
- 2
Expansion ratio r=4 is used consistently: bottleneck width = output_channels / 4
- 3
Each bottleneck block contains 3 conv layers, so ResNet-50 with [3,4,6,3] blocks has 3×(3+4+6+3)=48 conv layers + 1 initial conv + 1 FC = 50 layers
- 4
At the conv5_x stage, bottleneck operates at 512 channels instead of 2048, saving 16× FLOPs on the spatial convolution
- 5
1x1 convolutions enable cross-channel feature recombination with no spatial overhead, functioning as learned linear projections
- 6
The bottleneck design made it practical to build ResNet-152 at 11.3B FLOPs -- without it, the same depth would require ~60B FLOPs
Mathematical Formulation
Bottleneck Block Parameters
Pbottleneck=Cin⋅rCout+rCout⋅rCout⋅9+rCout⋅Cout
With r=4 and C_in = C_out = 1024: P = 1024256 + 2562569 + 2561024 = 262K + 590K + 262K = 1.11M. Compare with basic block: 2 * 1024 * 1024 * 9 = 18.87M.
FLOPs Savings at conv4_x (14x14 spatial)
FLOPsbottleneck=142×(1024×256+2562×9+256×1024)≈218M
Equivalent basic block FLOPs: 14² * 2 * 1024² * 9 = 3.7B. Bottleneck is ~17x cheaper.
Mathematical Intuition
A basic block has 2 conv3×3 layers with C channels: cost ≈2⋅9C2. The bottleneck replaces this with 1×1→3×3→1×1 at C/4: cost ≈C2/4+9C2/16+C2/4≈1.06C2 — roughly 17× cheaper than the basic block at matched channel width. This is what makes ResNet-50/101/152 tractable.
ResNet enables systematic scaling of network depth from 18 to 152 layers (and beyond), with consistent performance improvements. The architecture defines a family of models with shared design principles but different depth-accuracy-compute tradeoffs.
The Problem
Before ResNet, the relationship between depth and performance was broken:
- VGG-16/19 (2014) achieved 7.3% top-5 error on ImageNet with 138M parameters, but attempts to go deeper than 19 layers consistently failed.
- A 34-layer plain network scored 28.54% top-1 error vs 25.74% for an 18-layer version -- 3.8% degradation from adding layers.
- GoogLeNet/Inception used 22 layers but relied on complex multi-branch topology rather than simple stacking.
- No principled way existed to scale depth: each architecture was hand-designed and tuning deeper versions required extensive engineering.
- The fundamental question was unresolved: is there a depth beyond which adding layers always hurts, or is it purely an optimization failure?
The Solution
ResNet answered definitively: depth degradation is an optimization problem, not a capacity problem, and skip connections solve it. The family of ResNet models demonstrates smooth, predictable scaling:
Complete ResNet architecture specifications:
| Model | Layers | Block Type | Stage Config [conv2-5] | Params | FLOPs | Top-1 | Top-5 |
|---|---|---|---|---|---|---|---|
| ResNet-18 | 18 | Basic | [2, 2, 2, 2] | 11.7M | 1.8B | 69.8% | 89.1% |
| ResNet-34 | 34 | Basic | [3, 4, 6, 3] | 21.8M | 3.6B | 73.3% | 91.4% |
| ResNet-50 | 50 | Bottleneck | [3, 4, 6, 3] | 25.6M | 3.8B | 76.1% | 93.0% |
| ResNet-101 | 101 | Bottleneck | [3, 4, 23, 3] | 44.5M | 7.6B | 77.4% | 93.5% |
| ResNet-152 | 152 | Bottleneck | [3, 8, 36, 3] | 60.2M | 11.3B | 78.3% | 94.2% |
Shared architecture skeleton (all variants):
- conv1: 7x7 conv, 64 filters, stride 2 → output: 112x112x64
- pool: 3x3 max pool, stride 2 → output: 56x56x64
- conv2_x: Blocks at 56x56 with 64/256 channels
- conv3_x: Blocks at 28x28 with 128/512 channels (first block stride 2)
- conv4_x: Blocks at 14x14 with 256/1024 channels (first block stride 2)
- conv5_x: Blocks at 7x7 with 512/2048 channels (first block stride 2)
- Global average pool: 7x7 → 1x1
- FC layer: 2048 (or 512 for basic) → 1000 classes
Key observations from the results:
- ResNet-34 vs ResNet-18: +3.5% top-1 with 2x depth -- residual learning makes this gain reliable.
- ResNet-50 vs ResNet-34: switching to bottleneck blocks gains +2.8% while only adding 3.8M parameters (17% more) because bottleneck blocks are more parameter-efficient.
- ResNet-152: 3.57% top-5 error won ILSVRC 2015, beating all ensemble methods from 2014. A single model outperformed the previous year's ensemble winner.
- An ensemble of 6 ResNet models achieved 3.08% top-5 error.
- Diminishing returns appear beyond 152 layers on ImageNet (1.2M images), but the ceiling is dataset-dependent, not architecture-dependent.
Key Points
- 1
ResNet-18/34 use basic blocks (two 3x3 convs per block); ResNet-50/101/152 use bottleneck blocks (1x1-3x3-1x1)
- 2
Stage config notation [3,4,6,3] means 3 blocks in conv2_x, 4 in conv3_x, 6 in conv4_x, 3 in conv5_x -- the deepest stages get the most blocks because higher-level features benefit more from depth
- 3
ResNet-50 has only 3.8M more params than ResNet-34 despite being 50% deeper, thanks to the parameter-efficient bottleneck design
- 4
A single ResNet-152 (3.57% top-5) outperformed the VGG ensemble from 2014 (6.8% top-5) -- depth with skip connections beats width without them
- 5
All variants share the same 7x7 initial conv + max pool stem, reducing 224x224 to 56x56 before the residual stages begin
- 6
Global average pooling replaces fully-connected layers (except the final classifier), reducing parameters significantly compared to VGG's 4096-dim FC layers
Mathematical Intuition
Plain nets show a degradation: a 56-layer net has higher training error than 20-layer. Adding capacity hurts, which means optimization — not overfitting — is the bottleneck. ResNets flip the curve: error strictly decreases from 20 → 152 layers. Depth becomes a pure win, and ImageNet top-5 error drops from 7.3% (VGG-19) to 3.57% (ResNet-152 ensemble).
Comparison
Before / Traditional
Before ResNet (2014):
- VGG-19 was deepest practical network (19 layers, 138M params, 7.3% top-5)
- GoogLeNet used 22 layers but complex Inception modules
- Deeper plain networks had HIGHER training error
- 34-layer plain net: 28.54% top-1 (vs 25.74% for 18-layer)
- No systematic path to scale depth
After / This Paper
ResNet (2015):
- 152 layers with 60.2M params and 3.57% top-5 error
- Clean sweep: won all 5 ILSVRC/COCO 2015 tracks
- Surpassed estimated human performance (~5.1% top-5)
- Deeper = consistently better with skip connections
- Simple design: just stack residual blocks, no complex topology
- Opened path to 1000+ layer networks (demonstrated on CIFAR-10)
A follow-up paper by He et al. (2016) systematically analyzed different residual block designs and showed that making the skip connection a pure identity mapping -- by moving BN and ReLU before the convolutions -- yields better optimization and enables training of 1001-layer networks.
The Problem
The original (post-activation) ResNet block has this structure:
x → Conv → BN → ReLU → Conv → BN → (+x) → ReLU → y
While this works for 152 layers, several issues emerge at extreme depths:
- The final ReLU after addition clips the output to non-negative values, meaning the skip connection is not a true identity: y=ReLU(F(x)+x)=F(x)+x. This non-linearity on the shortcut path breaks the clean gradient highway.
- BN after conv means the skip connection signal passes through BN and ReLU before reaching subsequent blocks, accumulating non-linear distortions.
- At 1000+ layers, these distortions compound: the information signal through the skip path degrades, and the gradient highway develops "toll booths" at every ReLU gate.
- He et al. tested a 1001-layer post-activation ResNet on CIFAR-10 and found it trained but showed signs of optimization difficulty compared to pre-activation.
- The paper systematically tested 5 different shortcut and activation arrangements to find the optimal design.
The Solution
Pre-activation rearranges the block so that BN and ReLU are applied to the input before the weight layers:
x → BN → ReLU → Conv → BN → ReLU → Conv → (+x) → y
Why this is better -- three key insights:
1. Pure identity shortcut: The skip connection is now y=x+F(x^) where x^=ReLU(BN(x)) is the pre-activated input. The addition is the LAST operation, with no ReLU gate after it. This means the skip path is a true identity mapping: information and gradients flow through without any non-linear distortion.
2. Clean gradient propagation: For a stack of L pre-activation blocks: xL=x0+∑i=0L−1Fi(x^i) ∂x0∂L=∂xL∂L(1+∂x0∂∑i=0L−1Fi(x^i))
The gradient from loss to ANY layer always contains the additive "1" term -- no multiplicative gates anywhere on the identity path.
3. BN as pre-conditioning: Moving BN before the conv means each conv layer receives normalized input. This is analogous to "pre-layer normalization" in Transformers (which was discovered later and provides similar benefits for deep Transformer training).
Empirical results on CIFAR-10:
- 164-layer pre-activation: 5.46% error (vs 5.93% post-activation)
- 1001-layer pre-activation: 4.92% error (trains cleanly!)
- 1001-layer post-activation: 7.61% error (optimization struggles)
The improvement grows with depth, confirming the theoretical advantage of pure identity shortcuts.
Key Points
- 1
BN and ReLU moved BEFORE convolutions, making the skip path a pure identity mapping with no non-linear gates
- 2
Post-activation shortcut: y=ReLU(F(x)+x) (ReLU distorts the skip signal). Pre-activation: y=F(x^)+x (clean addition)
- 3
A 1001-layer pre-activation ResNet achieves 4.92% error on CIFAR-10; the post-activation equivalent gets 7.61% -- a 2.7% gap that proves the identity shortcut matters at extreme depth
- 4
Pre-activation BN acts as a regularizer: each layer receives normalized input, improving generalization even at moderate depths
- 5
This design principle (pre-normalization) was later adopted by Transformers as 'Pre-LN', where it similarly improves training stability for deep models
- 6
He et al. tested 5 shortcut variants (identity, projection, conv shortcut, etc.) and found pure identity consistently best
Mathematical Formulation
Pre-Activation Forward Pass
y=x+F(ReLU(BN(x)))
BN and ReLU transform the input BEFORE the weight layers. The addition is the final operation -- no non-linearity on the shortcut path.
Gradient Through L Pre-Activation Blocks
∂xl∂L=∂xL∂L+∂xL∂L⋅∂xl∂∑i=lL−1Fi
The first term is the direct identity gradient (always present, never vanishes). The second term is the residual gradient (may be small but is additive, not multiplicative).
Mathematical Intuition
Original ResNet: y=ReLU(x+F(x)) — the ReLU on the skip path kills negative gradients. Pre-activation: y=x+F(BN(ReLU(x))) — the skip is now a pure identity ∂x∂y=I+∂x∂F, giving an even cleaner gradient highway. This lets ResNet train 1000+ layers without degradation.
ResNeXt (Xie et al., 2017) introduces 'cardinality' as a third scaling dimension alongside depth and width. By splitting the transformation into multiple parallel paths with group convolutions, ResNeXt achieves better accuracy than deeper or wider ResNets at the same computational budget.
The Problem
After ResNet established depth scaling, the question became: how to increase capacity without diminishing returns?
Three conventional scaling dimensions and their limitations:
- Depth (more layers): Returns diminish -- ResNet-200 barely improves over ResNet-152, and training time grows linearly.
- Width (more channels): FLOPs and parameters grow quadratically with channel count. Doubling width quadruples the cost of 3x3 convolutions.
- Kernel size: Larger kernels are expensive (k2 cost) and VGG showed 3x3 stacks outperform single large kernels.
The Inception insight, but simpler: GoogLeNet/Inception showed that multi-branch topology helps, but Inception modules require careful per-layer design with different kernel sizes (1x1, 3x3, 5x5). Can we get the benefits of multi-branch processing without the architectural complexity?
The Solution
ResNeXt introduces cardinality C -- the number of independent transformation paths within each block. All paths have identical topology (unlike Inception), making the design simple and modular.
How a ResNeXt bottleneck block works (ResNeXt-50 32x4d, conv4_x stage):
Input: 14×14×1024
Option A (equivalent grouped convolution implementation):
- 1x1 conv: 1024→128 channels (32 groups × 4 channels each)
- 3x3 grouped conv: 128→128 with C=32 groups (each group: 4→4 channels)
- 1x1 conv: 128→1024 channels
Option B (conceptual split-transform-merge):
- Split input into 32 paths via 32 separate 1x1 convs (1024→4 each)
- Each path: 1x1 (4) → 3x3 (4) → 1x1 (1024/32=32? No -- all paths share the output 1x1)
- Actually: each of 32 paths does 1024→4→4→4, then concatenate to 128, then 1x1 to 1024
These are mathematically equivalent but grouped convolution is the efficient implementation.
Parameter comparison with ResNet-50:
- ResNet-50 bottleneck (conv4_x): 1024×256+2562×9+256×1024=1.11M per block
- ResNeXt-50 32x4d (conv4_x): 1024×128+128×128/32×9×32+128×1024=1.05M per block (similar params, but distributed differently)
Why cardinality helps: Each group learns a different transformation subspace. The aggregation of 32 diverse 4-channel transformations captures richer representations than a single 128-channel transformation, even with the same total parameters. This is related to ensemble learning -- diversity among weak learners often outperforms a single strong learner.
Results on ImageNet:
- ResNeXt-50 32x4d: 77.8% top-1 (vs ResNet-50: 76.1%, ResNet-101: 77.4%)
- ResNeXt-101 32x4d: 78.8% top-1
- ResNeXt-101 64x4d: 79.6% top-1 (at higher compute)
Key Points
- 1
Cardinality C is the number of independent transformation groups -- a new dimension orthogonal to depth and width
- 2
Implemented via grouped convolutions: split channels into C groups, each processed independently, then concatenated
- 3
"32x4d" notation: 32 groups, each with bottleneck width 4 -- total bottleneck channels = 32×4=128
- 4
ResNeXt-50 (32x4d) achieves 77.8% top-1, matching ResNet-101 (77.4%) with ~56% of the parameters
- 5
Increasing cardinality from 1 to 32 at fixed FLOPs consistently improves accuracy -- more effective than increasing depth or width by the same compute budget
- 6
All paths share identical topology (unlike Inception), making ResNeXt a clean, modular design with a single hyperparameter C
Mathematical Formulation
ResNeXt Block
y=x+∑i=1CTi(x)
C parallel transformations T_i, each operating on a disjoint subset of channels via group convolution. All T_i share the same topology but learn different parameters.
Grouped Convolution FLOPs
FLOPsgrouped=GCin×Cout×k2×H×W
Grouped conv with G groups costs 1/G of a standard conv. With G=32, the 3x3 conv is 32x cheaper, allowing more total channels at the same budget.
Mathematical Intuition
Split one wide conv into C 'cardinality' groups: F(x)=∑i=1CFi(x) where each Fi is a smaller bottleneck. This is implemented efficiently as grouped convolution. At matched FLOPs, adding cardinality beats adding depth or width — a third axis of scaling.
Comparison
Before / Traditional
ResNet-50:
- Single 256-channel bottleneck path
- 25.6M parameters, 3.8B FLOPs
- 76.1% top-1 accuracy
- One transformation per block
After / This Paper
ResNeXt-50 (32x4d):
- 32 parallel 4-channel paths (128 total)
- 25.0M parameters, 3.8B FLOPs (same budget!)
- 77.8% top-1 accuracy (+1.7%)
- 32 diverse transformations per block
SE blocks (Hu et al., 2018) add lightweight channel attention to any CNN architecture, allowing the network to adaptively recalibrate channel-wise feature responses based on global context. SE-ResNet-50 adds only ~2.5M parameters (~10% overhead) but improves top-1 accuracy by over 1%. SE-Net won the final ImageNet competition in 2017 with 2.251% top-5 error.
The Problem
Standard convolutions treat all output channels identically -- each filter produces one channel, and all channels are passed to the next layer with equal importance:
- A 3x3 conv with 256 output channels produces 256 feature maps, but some are far more informative than others for the current input.
- A channel detecting "fur texture" is critical for classifying a cat but irrelevant for classifying a car. Yet both channels contribute equally to subsequent layers.
- Without explicit channel selection, the network must use deeper layers to implicitly learn to ignore irrelevant channels, wasting capacity and depth.
- Global context is needed to decide channel importance (e.g., knowing the overall scene determines which features matter), but standard convolutions operate locally.
- Attention mechanisms existed for spatial dimensions (e.g., in detection), but channel-wise attention was unexplored for classification.
The Solution
The Squeeze-and-Excitation (SE) block adds a lightweight channel attention mechanism in three steps:
Step 1: Squeeze (Global Average Pooling) Collapse each channel's H×W spatial map into a single scalar by global average pooling: zc=H×W1∑i=1H∑j=1Wxc(i,j)
This produces a channel descriptor z∈RC that captures the global distribution of each channel. For a 14×14×1024 feature map, squeeze produces a 1×1×1024 vector.
Step 2: Excitation (Bottleneck FC Network) A two-layer fully connected network learns non-linear channel interdependencies: s=σ(W2⋅δ(W1⋅z))
Where:
- W1∈RC/r×C reduces channels by ratio r (typically r=16): 1024→64
- δ is ReLU activation
- W2∈RC×C/r expands back: 64→1024
- σ is sigmoid, outputting values in [0,1]
Parameters for this FC bottleneck: 2×C×C/r=2×1024×64=131K per block.
Step 3: Scale (Channel-wise Multiplication) Multiply each channel by its learned attention weight: x~c=sc⋅xc
Channels with sc≈1 are amplified (important), channels with sc≈0 are suppressed (irrelevant).
Integration with ResNet: The SE block is inserted within each residual block, after the conv layers but before the skip connection addition:
x → [Conv layers → SE block] + x → ReLU → y
SE-ResNet-50 overhead:
- Extra parameters: ~2.5M (10% of 25.6M base)
- Extra FLOPs: negligible (FC on 1x1 vectors)
- Top-1 improvement: 76.1% → 77.6% (+1.5%)
ImageNet 2017 result: SE-ResNeXt-101 achieved 2.251% top-5 error, winning the last ImageNet classification competition.
Key Points
- 1
Squeeze: Global Average Pooling collapses H×W×C to 1×1×C, creating a channel-level global descriptor
- 2
Excitation: A bottleneck FC network (C→C/r→C with r=16) learns non-linear channel interdependencies, outputting sigmoid attention weights
- 3
Scale: Element-wise multiplication of each channel by its attention weight selectively amplifies or suppresses features
- 4
SE block is architecture-agnostic: can be added to ResNet, ResNeXt, Inception, MobileNet, etc. with consistent improvements
- 5
Minimal overhead: ~10% more parameters, negligible extra FLOPs (the FC operates on 1x1 vectors, not spatial maps)
- 6
SE-Net won ImageNet 2017 with 2.251% top-5 error, the final year of the competition -- channel attention was the winning ingredient
Mathematical Formulation
Squeeze Operation
zc=Fsq(xc)=H×W1∑i=1H∑j=1Wxc(i,j)
Global average pooling compresses each channel's HxW spatial map into a single scalar, capturing the channel's 'average activation level' as a proxy for its importance.
Excitation and Scaling
x~c=σ(W2⋅ReLU(W1⋅z))⋅xc
W₁ ∈ R^(C/r × C) reduces, W₂ ∈ R^(C × C/r) expands. The bottleneck (r=16) limits parameters while modeling cross-channel interactions. Sigmoid ensures weights ∈ [0,1].
Mathematical Intuition
After a residual block, SE computes channel attention: s=σ(W2⋅ReLU(W1⋅GAP(x))), then re-scales: y=s⊙x. The squeeze W1∈RC/r×C with r=16 adds only ∼2C2/r params — a free 1% top-5 gain. It's essentially learned per-channel importance, conditioned on the image.
Further Reading
Keep reading
Related Papers
Go deeper