CNN Architectures: LeNet to ConvNeXt
AlexNet, VGG, Inception, ResNet and a decade of design lessons.
Between 2012 and 2017 the best ImageNet classifier's error fell from 15.3% to 2.25%, and almost every step left behind a design rule that is still in use: ReLUs and GPUs, depth built from small filters, cheap bottlenecks, and residual connections that let networks grow to hundreds of layers. This lesson walks the decade block by block and counts what each block costs.
What you’ll learn
- Describe LeNet-5 and AlexNet layer by layer, and identify which of AlexNet's ingredients made the 2012 result possible.
- Derive why stacks of convolutions beat larger kernels, and how reductions make Inception modules affordable.
- Explain residual learning and the bottleneck block, and count the parameters and multiply–adds of a block and of ResNet-50.
- Contrast DenseNet's concatenation with ResNet's addition, and summarize the design lessons of the ImageNet era through ConvNeXt.
LeNet-5 and AlexNet
LeNet-5 (LeCun et al., 1998) fixed the template that every later CNN follows: alternate convolutions and subsampling so that maps shrink while channels grow, then finish with fully connected layers. Its subsampling layers summed blocks, scaled the sum by a trainable coefficient, added a trainable bias and squashed the result, and its third layer connected each map to only some of the previous ones, to save connections and break symmetry.
| Layer | Output | Trainable parameters |
|---|---|---|
| Input | grayscale | — |
| C1: six convolutions | 156 | |
| S2: subsampling | 12 | |
| C3: sixteen convolutions on subsets of S2 | 1,516 | |
| S4: subsampling | 32 | |
| C5: 120 convolutions of (a full connection here) | 48,120 | |
| F6: fully connected | 10,164 |
AlexNet (Krizhevsky, Sutskever & Hinton, 2012) scaled the template to color images and 1,000 classes: five convolutional layers, starting with 96 filters of at stride 4, then three fully connected layers, about 60 million parameters in all. Counting them shows where the weight was: the three fully connected layers hold about 58.6 million, roughly 96%. The convolutions, with a few percent of the weights, did most of the computation. Its ingredients:
- ReLU activations: a four-layer CNN with ReLUs reached 25% training error on CIFAR-10 six times faster than the same network with tanh;
- two GTX 580 GPUs with 3 GB each, the network split between them, about 90 epochs in five to six days;
- dropout with probability 0.5 in the first two fully connected layers, without which the network overfit substantially;
- augmentation: random crops of images with horizontal flips, and PCA-based color jitter;
- overlapping max pooling with stride 2, and local response normalization, a cross-channel normalization later abandoned.
It won ILSVRC 2012 with 15.3% top-5 error, using an ensemble that included two networks pretrained on a larger ImageNet release, against 26.2% for the runner-up; an ensemble trained on the challenge data alone scored 16.4%.
VGG: depth from small filters
VGG (Simonyan & Zisserman, 2015) asked a single question: what if every convolution is with stride 1 and padding 1, and every downsampling is a max pool, and you only vary depth? Its 16- and 19-layer networks took second place in the ILSVRC 2014 classification task (7.3% top-5 error with an ensemble of seven) and first in localization. The argument for small filters is short:
Stacked layers with stride 1 grow the receptive field by 2 per layer, so two of them see and three see :
With channels in and out, compare the weights (biases ignored):
The stack uses 28% fewer weights than a layer and 45% fewer than a one (equivalently, the layer needs 81% more), the multiply–adds shrink in the same ratio, and each extra layer inserts another ReLU, making the function more nonlinear. Simonyan & Zisserman also read the stack as a regularization of the filters, forcing them to decompose into ones (with ReLUs in between); Szegedy et al. (2016) pushed the idea further, replacing by followed by .
A convolution with 256 input and 256 output channels is replaced by two stacked convolutions with 256 channels throughout. What percentage of the original weights do the two layers need?
Show the answer
72 %
against , a ratio of , whatever the channel count. The receptive field is the same , and the stack adds a nonlinearity in the middle.
The price of VGG was elsewhere. VGG-16 has 138 million parameters, of which the first fully connected layer, from the final maps to 4,096 units, alone holds about 103 million, and it costs about 15.5 billion multiply–adds per image. Later designs attacked both numbers.
Inception: going wide, cheaply
GoogLeNet (Szegedy et al., 2015), the ILSVRC 2014 winner at 6.67% top-5 error, was designed to a budget of 1.5 billion multiply–adds at inference. Its building block, the inception module, runs four branches in parallel on the same input and concatenates their outputs along channels: a convolution, a , a , and a max pool. Different branches cover different scales, and the network learns how to weight them.
Run naively, the module is expensive, and pooling makes it worse because it passes all its input channels through. The fix is a convolution that reduces the channels before each and branch and after the pooling, the "network in network" idea of Lin, Chen & Yan (2014).
The module sees a input. Its branch outputs 32 channels. Applied directly, it costs
With a reduction to 16 channels first, the branch costs two cheap layers:
Over the whole module (64, 128 and 32 output channels for the convolutional branches, reductions to 96 and 16, and 32 after pooling) the reductions bring the cost down to the 128 million multiply–adds listed in the paper and the output to 256 channels, against 303 million and 416 channels for the naive module.
GoogLeNet stacks nine such modules into a network 22 layers deep with about 12 times fewer parameters than AlexNet, ends with global average pooling instead of large fully connected layers, and adds two auxiliary classifiers on intermediate layers, weighted 0.3 in the loss during training and discarded at inference. Later versions added batch normalization (Ioffe & Szegedy, 2015), factorized filters and label smoothing (Szegedy et al., 2016).
ResNet: learning residuals
By 2015, batch normalization had made deep networks trainable from scratch, and a strange fact appeared. On CIFAR-10, a plain 56-layer network had higher training error than a plain 20-layer one (He et al., 2016). That is not overfitting, since training error is the thing that got worse, and it is not a capacity limit, since the deeper network could copy the shallower one and set its extra layers to the identity. The optimizer simply failed to find such solutions.
A residual block makes the identity the default: it computes , so the layers learn only a correction to their input, and is easy to reach. The Jacobian contains an identity term, so gradients reach early layers along the shortcut without passing through every weight matrix. When the shapes change, at a stride or a change of width, a convolution projects the shortcut. Residual Connections treats the theory in depth.
For deeper models, ResNet replaces two layers by a bottleneck: a convolution reduces 256 channels to 64, a works at 64, and a restores 256. Its weights, , are about the same as a basic block of two layers at width 64 (), and 17 times fewer than two layers at width 256. At the bottleneck costs about 218 million multiply–adds.
import torch
import torch.nn as nn
class Bottleneck(nn.Module):
"""ResNet bottleneck: 1x1 reduce, 3x3, 1x1 expand (x4), added to a shortcut."""
def __init__(self, c_in, width, stride=1):
super().__init__()
c_out = 4 * width
self.f = nn.Sequential(
nn.Conv2d(c_in, width, 1, bias=False), nn.BatchNorm2d(width), nn.ReLU(inplace=True),
nn.Conv2d(width, width, 3, stride=stride, padding=1, bias=False), nn.BatchNorm2d(width), nn.ReLU(inplace=True),
nn.Conv2d(width, c_out, 1, bias=False), nn.BatchNorm2d(c_out))
if stride == 1 and c_in == c_out:
self.shortcut = nn.Identity()
else: # projection when the shape changes
self.shortcut = nn.Sequential(nn.Conv2d(c_in, c_out, 1, stride=stride, bias=False), nn.BatchNorm2d(c_out))
def forward(self, x):
return torch.relu(self.f(x) + self.shortcut(x))
block = Bottleneck(256, 64)
print(sum(p.numel() for p in block.parameters())) # 70400 = 69,632 conv weights + 768 BatchNormThis places the stride in the convolution, as torchvision does; the original paper put it in the first . Stacking (3, 4, 6, 3) such blocks at widths 64, 128, 256 and 512 after a stride-2 stem and a max pool gives ResNet-50.
Counting ResNet-50. Summing every layer gives 25,557,032 parameters, the familiar 25.6 million, of which the final 1,000-way layer holds about 2 million. The multiply–adds per image come to 3.86 billion with the original stride placement, the "3.8 billion FLOPs" of He et al. (2016), who counted a multiply–add as one operation, and 4.09 billion with the stride in the . Remarkably, even ResNet-152, at 11.3 billion, is cheaper than VGG-16. An ensemble of ResNets won ILSVRC 2015 with 3.57% top-5 error.
Two refinements followed quickly. Moving batch normalization and ReLU before each convolution, so the shortcut path stays a pure identity, trained a 1,001-layer ResNet on CIFAR-10 to 4.62% error (He et al., 2016, "Identity mappings"). ResNeXt replaced the convolution by a grouped one, adding cardinality, the number of parallel paths, as a design dimension that improved accuracy at fixed cost (Xie et al., 2017).
He et al. (2016) trained plain, non-residual networks of 20 and 56 layers on CIFAR-10, and the deeper one finished with the higher training error. What does this indicate?
- The deeper network overfits the training data
- The deeper network is less expressive than the shallower one
- The optimizer fails to find good solutions in the deeper network, although such solutions exist
- The data are too few for 56 layers
Show the answer
C. The optimizer fails to find good solutions in the deeper network, although such solutions exist
The deeper network can represent everything the shallower one can (extra layers set to the identity), yet its training error is worse: an optimization problem, which residual connections address by making the identity the default.
DenseNet, and a decade of lessons
DenseNet (Huang et al., 2017) took the shortcut to its limit. Within a dense block, every layer receives the concatenation of all earlier feature maps, , giving direct connections in a block of layers. Each layer adds only new channels, the growth rate, so a block entered with channels leaves with . A bottleneck before each and transition layers that compress channels and pool between blocks (DenseNet-BC) keep the cost down. Concatenation reuses features instead of re-learning them, which made DenseNets accurate for their parameter count, at the price of many large activations held in memory.
Addition (ResNet) and concatenation (DenseNet) are the two ways to keep earlier signals available. The first preserves width and makes the identity cheap; the second preserves every feature unchanged at the cost of growing width.
| Year | ILSVRC classification winner | Top-5 error |
|---|---|---|
| 2010 | NEC–UIUC (hand-designed features) | 28.2% |
| 2011 | XRCE (Fisher vectors) | 25.8% |
| 2012 | SuperVision (AlexNet) | 16.4% with challenge data only; 15.3% with extra data |
| 2013 | Clarifai | 11.7% |
| 2014 | GoogLeNet (VGG second, 7.3%) | 6.67% |
| 2015 | ResNet (MSRA) | 3.57% |
| 2016 | the winning entry | 2.99% |
| 2017 | SENet (squeeze-and-excitation) | 2.25% |
After ImageNet: efficiency, search and ConvNeXt
By 2017 the questions were changing. On phones, multiply–adds and memory traffic matter more than the last point of accuracy, which led to depthwise separable convolutions, MobileNets and EfficientNet's compound scaling. Architectures were increasingly found by search rather than by hand. And in 2021 Vision Transformers matched and then beat CNNs when pretrained on enough data.
ConvNeXt (Liu et al., 2022) answered by modernizing a ResNet-50 step by step toward the design of the Swin Transformer, without any attention. A modern training recipe alone (300 epochs, AdamW, heavy augmentation, stochastic depth, label smoothing) lifted ResNet-50 from 76.1% to 78.8% ImageNet top-1. Architectural changes (a "patchify" stem, depthwise convolutions, inverted bottlenecks, GELU, fewer activations and normalizations, layer normalization, separate downsampling layers) brought it to 82.0%, and the final ConvNeXt-T reached 82.1%, against 81.3% for Swin-T at the same 4.5 billion FLOPs. Much of what looked like an architecture gap had been a training gap.
Key takeaways
- LeNet-5 set the template of convolution, subsampling and fully connected layers with 60,000 parameters; AlexNet scaled it with ReLUs, dropout, augmentation and GPUs, and 96% of its 60 million parameters sat in the fully connected layers.
- Stacks of convolutions match larger kernels' receptive fields with fewer weights ( vs. ) and more nonlinearities; reductions make wide multi-branch inception modules affordable.
- Residual blocks compute , curing the degradation of very deep plain networks; bottlenecks keep them cheap, giving ResNet-50 25.6 million parameters and about 4 billion multiply–adds.
- DenseNet concatenates instead of adding; global average pooling, batch normalization and identity paths became standard; top-5 error on ImageNet fell from 28.2% (2010) to 2.25% (2017).
- ConvNeXt showed that a ResNet modernized with a transformer-era recipe and design choices matches a Swin Transformer at equal FLOPs.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A bottleneck block reduces 512 channels to 128 with a convolution, applies a convolution at 128 channels, and restores 512 channels with a . How many convolution weights does it have (no biases)?
Show the answer
C.
, about 17 times fewer than two layers at 512 channels.
Why did VGG replace large kernels by stacks of convolutions?
- kernels are the only size GPUs can compute efficiently
- A stack covers the same receptive field with fewer weights and more nonlinearities
- A stack has a larger receptive field than any single kernel
- Small kernels make the network translation-invariant
Show the answer
B. A stack covers the same receptive field with fewer weights and more nonlinearities
Three layers see with weights instead of , and put three ReLUs where there was one.
In an inception module, what is the main job of the convolutions placed before the and branches?
- To reduce the number of channels so the expensive spatial convolutions become affordable
- To enlarge the receptive field of the branch
- To normalize the activations
- To downsample the feature map spatially
Show the answer
A. To reduce the number of channels so the expensive spatial convolutions become affordable
In module 3a, reducing 192 channels to 16 before the cuts that branch from about 120 to about 12 million multiply–adds; a layer mixes channels per pixel without touching the spatial extent.
A dense block with growth rate receives 64 channels and has 6 layers. How many channels does it output?
Show the answer
D.
Every layer adds channels to the running concatenation: . A transition layer then compresses and pools before the next block.
Go deeper
- Efficient ConvNets · Depthwise separable convolutions, inverted bottlenecks and compound scaling.
- Neural Architecture Search · Reinforcement learning, evolution and differentiable search, and what design spaces revealed.
- ConvNets vs Vision Transformers · Inductive bias, data scale and the modernized ConvNet.
Further reading
- K. Simonyan & A. Zisserman, "Very deep convolutional networks for large-scale image recognition," ICLR (2015).
- C. Szegedy, W. Liu, Y. Jia, P. Sermanet, S. Reed, D. Anguelov, D. Erhan, V. Vanhoucke & A. Rabinovich, "Going deeper with convolutions," CVPR (2015).
- K. He, X. Zhang, S. Ren & J. Sun, "Deep residual learning for image recognition," CVPR (2016).
- G. Huang, Z. Liu, L. van der Maaten & K. Q. Weinberger, "Densely connected convolutional networks," CVPR (2017).