In 2012 a convolutional network called AlexNet won the ImageNet classification contest with a top-5 error of 15.3% on the test set, while the second-best entry had 26.2%. Top-5 error is the share of test images whose true class is not among the model’s five highest-scoring classes. Three years later an ensemble of residual networks with up to 152 layers reached 3.57% in the same contest. In those three years the number of layers went from 8 to 152.
Between the two results lie a handful of design ideas that image models still use. This lesson walks through nine networks in the order they appeared, with the problem each faced, the idea it added, a drawing of its block, its paper and its parameter count. The building blocks are taught in P5.5 ( convolutions, bottlenecks, depthwise-separable convolutions) and P4.20 (residual connections). Here you meet the networks that made them famous.
Scope: classification networks only. Detection and segmentation designs are P5.12 and P5.13, Vision Transformers are P5.15, and training a CNN yourself is P5.7.
How to read the tour
Each design gets four things: the problem that stopped earlier networks, the idea that helped, a repeating block (drawn with tensor shapes in the widget), and the size in parameters.
Parameter counts come from torchvision, the vision library of PyTorch (version 0.24.1). We build each model with weights=None, which gives the untrained network, and add up p.numel() over its parameters. We call the result “the torchvision version”. Two networks are not in torchvision: LeNet-5, which we build ourselves, and the first MobileNet, which we build from the table in its paper.
ImageNet results come from the original papers, with the exact measure. The contest entries below are ensembles: the predictions of several networks are averaged, which lowers the error but costs several times the compute.
See the nine designs
Pick a design on the timeline. The Block view draws its characteristic block, with shapes as (channels, height, width) for one image. The Compare view puts the nine parameter counts on one log scale, where each gridline is 10 times the one before.
Notice that the bars do not rise with the years: VGG-16 (2014) is the largest.
LeNet-5 (1998): the pattern
Problem. Recognize handwritten digits from pixels without hand-designed features.
Idea. Alternate convolution layers with subsampling layers, then finish with dense layers (LeCun, Bottou, Bengio and Haffner, Proceedings of the IEEE, November 1998). The input is a grey image, and the paper counts 7 layers without it. Because each kernel is shared over the whole image (P5.2), the network has only 60,000 trainable parameters, although the paper counts 340,908 connections.
The original has details that modern networks dropped: trainable subsampling coefficients, a third convolution that connects each map to only some of the maps before it, and an output layer that compares 84 numbers with stored patterns. The widget draws a modern variant with plain average pooling, a full third convolution and a dense output layer. It has parameters. The original’s 60,000 are the sum over its layers C1, S2, C3, S4, C5 and F6, without the stored patterns of the output layer.
AlexNet (2012): scale and the tricks that made it work
Problem. Why not earlier? The authors point to two things that had only just become available: labelled datasets with millions of images, and GPUs fast enough to train big CNNs. The task was to train a large CNN on 1.2 million high-resolution images in 1,000 classes without overfitting and without waiting months.
Idea. A deeper CNN, with five convolutional and three dense layers, plus training changes (Krizhevsky, Sutskever and Hinton, NIPS 2012, now NeurIPS):
- ReLU instead of tanh. In their test, a four-layer CNN on CIFAR-10 reached 25% training error six times faster.
- GPUs. The network was split over two GTX 580 GPUs and trained for five to six days.
- Dropout (P4.17) in the first two dense layers. Without it the network showed substantial overfitting.
- Data augmentation (P4.18). Random crops of images and horizontal flips enlarged the training set by a factor of 2048, and a random change of colour intensities added more.
- Overlapping max-pooling and local response normalization, a layer later replaced by batch normalization (P4.19).
The paper reports 60 million parameters. The torchvision version, which follows the variant in the “One weird trick” paper (Krizhevsky, 2014), has 61,100,840, with 64, 192, 384, 256 and 256 channels. In the 2012 contest the authors’ entry, an average of several CNNs, had a top-5 test error of 15.3%, against 26.2% for the second-best entry.
Where the parameters are. The torchvision AlexNet has 58,631,144 parameters in its three dense layers and only 2,469,696 in its five convolutions. So 96% of the weights sit in the dense head, 37,752,832 of them in the first dense layer alone ( inputs to 4,096 units). Remember this when we reach global average pooling.
VGG (2014): small kernels, stacked
Problem. AlexNet used large kernels ( and ). Is there a simpler recipe that goes deeper?
Idea. Use only convolutions, in stages of two or three, each stage followed by a max pool (Simonyan and Zisserman, arXiv 2014, ICLR 2015). Two layers in a row, with stride 1 and no pooling between, see a patch of the input, and three see (receptive fields are P5.6). What do you gain by three small layers instead of one big one? The paper gives two reasons: three nonlinearities instead of one, and fewer weights. With channels in and out, the weight counts are
which is 81% more for the single large layer. At these are 110,592 and 200,704 (weights only, no biases).
VGG-16 has 13 convolutions in five stages of 2, 2, 3, 3 and 3 layers, with 64, 128, 256, 512 and 512 channels, and three dense layers: 16 weight layers. The torchvision version has 138,357,544 parameters, of which 123,642,856 (89%) are in the dense head, 102,764,544 in the first dense layer alone ( inputs to 4,096 units). In the 2014 contest VGG came second in classification, with a top-5 test error of 7.3% for an ensemble of 7 networks (6.8% for two networks, found after the deadline), and first in localisation.
GoogLeNet and Inception (2014): branches, and 1×1 reductions
Problem. Which kernel size is best, , or ? And how can a network get deeper and wider without the cost exploding?
Idea. Do not choose. An Inception module runs a , a , a and a pooling branch side by side on the same input and concatenates their outputs along the channels (Szegedy et al., arXiv 2014, CVPR 2015). To keep the cost down, convolutions come first in the and branches and shrink the channels, the same trick P5.5 shows for ResNet.
Take the paper’s module 3a, which reads 192 channels. Its branch has 128 outputs and its branch has 32. If both read the 192 channels directly, they need weights. With reductions to 96 and 16 channels first, they need , which is 2.59 times fewer (weights only).
GoogLeNet is the name of the contest entry, a 22-layer network built from such modules. Its other choices:
- Average pooling before the last layer instead of big dense layers. The paper reports about 0.6% better top-1 accuracy.
- Two auxiliary classifiers on middle layers, used only in training, to strengthen the gradient signal that reaches early layers (P4.16).
- The paper says it uses 12 times fewer parameters than Krizhevsky et al. and a budget of 1.5 billion multiply-adds. Counts differ between implementations: the torchvision version has 6,624,904 parameters without the auxiliary classifiers, 9 times fewer than torchvision’s AlexNet, and it uses a convolution in the third branch where the paper uses .
It won the 2014 contest with a top-5 error of 6.67%, for an ensemble of 7 networks that each looked at 144 crops of the image.
ResNet (2015): add the input
Problem. Plain networks stopped improving with depth, and even their training error got worse (the degradation problem of P4.20).
Idea. Let each block learn a correction to its input: (He, Zhang, Ren and Sun, arXiv 2015, CVPR 2016). P4.20 explains why the added makes deep networks trainable. ResNet-18 and ResNet-34 use a basic block of two convolutions. ResNet-50, 101 and 152 use a bottleneck block: a convolution that shrinks the channels, a convolution, and a convolution that expands them again.
For a block with 256 channels the bottleneck goes 256 to 64, at 64, then 64 to 256, with weights. Two layers at 256 channels would have 1,179,648, and one layer 589,824 (weights only: these are P5.5’s numbers without the biases P5.5 counted). So the bottleneck has about 17 times fewer weights than a pair of layers with the same 256-channel input and output.
When a stage halves the image size and doubles the channels, the shortcut cannot be a plain copy. The block then uses a projection shortcut, a convolution with stride 2 on the shortcut path (in the torchvision ResNet-50 the second stage has one that maps 256 to 512 channels with stride 2). ResNet-50 has blocks in its four stages, batch normalization (P4.19) after every convolution, and ends with global average pooling and one dense layer.
The paper’s deepest ImageNet network has 152 layers. A single ResNet-152 had a top-5 error of 4.49% on the validation set, and an ensemble reached 3.57% on the test set, first place in 2015. The torchvision counts are 11,689,512 (ResNet-18), 25,557,032 (ResNet-50) and 60,192,808 (ResNet-152).
DenseNet (2016): keep everything
Problem. Each layer of a plain network sees only the maps of the layer before it. Can later layers reuse earlier features directly, and can the gradient reach early layers by a short path?
Idea. Give each layer the maps of all earlier layers in its block, joined by concatenation. The authors argue that this strengthens feature propagation and encourages feature reuse (Huang, Liu, van der Maaten and Weinberger, arXiv 2016, CVPR 2017):
A block of layers then has direct connections, where a plain stack has . A residual block adds (shapes must match); a dense layer concatenates, so the earlier maps stay as they are and the channel count grows.
Each layer adds only new maps, the growth rate, with on ImageNet. A layer with input channels applies a convolution to make maps, then a convolution to make , and appends them to its input, giving channels. A transition layer between blocks (a convolution and average pooling) halves the channel count. DenseNet-121 has four blocks of 6, 12, 24 and 16 layers, with channel counts , , and (the Python cell below prints them). Its 7,978,856 parameters in the torchvision version are about a third of ResNet-50’s.
MobileNet (2017): cheap enough for a phone
Problem. The networks above need billions of multiply-adds, too many for a phone.
Idea. Replace each ordinary convolution by a depthwise-separable pair (Howard et al., arXiv 2017): a depthwise convolution that filters each channel on its own, then a pointwise convolution that mixes the channels (P5.5 shows the counts). The paper’s cost ratio is
where is the number of output channels and the kernel size, so a pair costs 8 to 9 times less than a full convolution. At 256 channels in and out, a full layer has 589,824 weights and the pair has , 8.7 times fewer.
The network has a first full convolution, then 13 such pairs, with stride-2 depthwise layers to halve the size, then average pooling and one dense layer. Almost all the work is now in the layers: 95% of the multiply-adds and 75% of the parameters (the paper’s Table 2). A width multiplier and a resolution multiplier shrink the network uniformly to fit a budget. Version 1 has 4.2 million parameters and 569 million multiply-adds in the paper, and building its Table 1 in PyTorch gives 4,231,976 parameters.
EfficientNet (2019): scale all three together
Problem. To get a better network, people made one dimension bigger: more layers (depth), more channels (width), or larger images (resolution). The gain shrinks quickly when only one of them grows.
Idea. Compound scaling (Tan and Le, ICML 2019): grow all three together, with one coefficient that says how much more compute you can spend:
with and . The squares appear because the cost of a convolution layer grows with the number of layers, with the square of the width (input and output channels both grow) and with the square of the resolution (height and width both grow). So the cost grows by about . A small grid search on the base network found , , , and is a little under 2 (the cell below tries ).
The base network, EfficientNet-B0, was found by an architecture search. Its block is the mobile inverted bottleneck of MobileNetV2 (Sandler et al., CVPR 2018: thin ends, a wide middle with a depthwise convolution) plus squeeze-and-excitation, a small gate that rescales each channel using the average of that channel over the image. B1 to B7 are B0 scaled up. In the paper’s table, B0 has 5.3 million parameters, 0.39 billion FLOPs and 77.1% top-1 accuracy on the ImageNet validation set, and B7 has 66 million parameters, 37 billion FLOPs and 84.3%. The torchvision counts are 5,288,548 and 66,347,960.
ConvNeXt (2022): a ResNet that learned from Transformers
Problem. After Vision Transformers appeared in 2020 (P5.15), Transformers overtook ConvNets on ImageNet classification. Was the gain from attention, or from other changes made at the same time?
Idea. Take a ResNet-50 and move it one change at a time toward the Transformer design, keeping only convolutions (Liu et al., arXiv 2022, CVPR 2022). The paper’s roadmap, with ImageNet-1K top-1 accuracy on the validation set:
- A newer training recipe (300 epochs instead of 90, the AdamW optimizer, stronger augmentation) on the unchanged ResNet-50: 76.1% to 78.8%.
- Blocks per stage from to (79.4%), and a patchify stem, one convolution with stride 4 (79.5%).
- Depthwise convolutions with wider channels, an inverted bottleneck (a hidden layer four times wider than the block’s input and output, like a Transformer’s feed-forward layer), and a kernel size: 80.6%.
- GELU instead of ReLU, fewer activation and normalization layers, LayerNorm instead of batch normalization (P4.19) and separate downsampling layers: about 82%.
The roadmap ends at 82.0% (82.1% for ConvNeXt-T in the comparison table, from the final training runs), against 81.3% for Swin-T of similar size. Depthwise convolutions alone first lowered the accuracy, to 78.3% in the paper’s figure. The torchvision ConvNeXt-Tiny has 28,589,128 parameters and about 4.5 billion multiply-adds. The first step is the surprise: the authors conclude that a significant part of the gap between older CNNs and Transformers may be due to how they were trained.
The head: global average pooling
The end of a classifier turns feature maps into class scores. AlexNet and VGG flatten the last maps and use big dense layers. Later networks use global average pooling: average each channel’s map over all its positions, so maps become numbers, then one dense layer (pooling is P5.6, the dense layer is P4.5). A ResNet-50 ends with 2,048 maps of size . Flattening them gives numbers, and a dense layer from there to 4,096 units would have 411,045,888 weights. Average pooling gives 2,048 numbers, and the dense layer to 1,000 classes has 2,049,000.
That is why the head is 8% of ResNet-50’s parameters, against 96% for AlexNet and 89% for VGG-16. Each channel’s average can be read as how strongly that feature is present anywhere in the image, and the layer shapes no longer depend on the image size. GoogLeNet’s paper credits the idea to the Network-in-Network paper and reports the 0.6% gain mentioned above.
What changed, and what stayed
Across the tour networks got deeper, made trainable by ReLU, batch normalization (P4.19) and shortcuts (P4.20), while each layer got cheaper (stacked convolutions, reductions, bottlenecks, depthwise-separable layers) and the heads shrank to global average pooling. Scaling rules (EfficientNet) and training recipes (ConvNeXt’s first step) now matter as much as layer types, and ideas travel both ways: ConvNeXt borrows from Transformers (P5.15).
How to choose in practice
- Start from a pretrained model, not from random weights (P5.10), and pick the backbone by three numbers.
- Parameters set the memory for the weights, 4 bytes each in 32-bit floating point: about 102 MB for ResNet-50, 553 MB for VGG-16 and 14 MB for MobileNetV2.
- Compute and latency. Multiply-adds and the measured time on your device are not the same (see the box below).
- Match the input. Pretrained weights expect a certain image size and the per-channel normalization of their training (P5.1).
Go deeper FLOPs, parameters and latency
Three numbers describe a network, and they do not move together. Counting the multiply-adds of every convolution and linear layer for one image (with forward hooks in PyTorch):
- AlexNet: 61.1 million parameters, 0.71 billion multiply-adds.
- VGG-16: 138.4 million parameters, 15.47 billion multiply-adds.
- ResNet-50: 25.6 million parameters, 4.09 billion.
- ConvNeXt-T: 28.6 million parameters, 4.46 billion (the paper says 4.5).
- MobileNetV2: 3.5 million parameters, 0.30 billion.
The parameter counts set the memory for the weights, 4 bytes each in 32-bit floating point.
Parameters are not compute. A convolution reuses each weight at every position, so a layer on a large map can need many multiply-adds with few weights. AlexNet has 2.4 times the parameters of ResNet-50 but 5.7 times fewer multiply-adds. Compute is not time either, and multiply-adds set the work per image while latency is the measured time on your device. The ConvNeXt paper notes that, at similar FLOPs, models with depthwise convolutions are known to be slower and to use more memory than models with only dense convolutions. MobileNet’s authors point out that their design puts nearly all the work into convolutions, which map directly onto fast matrix multiplication. Latency also depends on the hardware, the library, the batch size and the memory traffic. Resolution matters too: the ConvNeXt paper’s comparison table lists EfficientNet-B7 at pixels with 37.0 billion FLOPs, and ConvNeXt-T at with 4.5 billion.
So treat parameters and multiply-adds as a first filter and measure latency on the target device before you commit. (“FLOPs” is used in two ways: some papers count one multiply-add as one FLOP, as the ResNet paper does, others count it as two.)
Go deeper Inception v3: splitting a kernel into a column and a row
P5.3 showed that some kernels, like the Gaussian blur and the Sobel filter, split into a column and a row. Inception v3 (Szegedy, Vanhoucke, Ioffe, Shlens and Wojna, arXiv 2015, CVPR 2016) uses the same idea for learned layers: a convolution is replaced by a convolution followed by a convolution. With channels in and out, that costs weights instead of , which the paper puts as 33% cheaper. Replacing a layer by two layers would save only 11% ( against ). The paper also uses followed by on medium-sized maps. At the layer has 36,864 weights and the pair 24,576.
The pair is not the same as a hand-made separable kernel. With one channel and no activation in between, the pair can only represent kernels that split exactly (rank 1, P5.3). With many channels between the two layers, the pair can represent more. The MobileNet paper adds that this kind of spatial factorization saves little on top of depthwise convolutions, because very little computation is spent in the depthwise layers.
Depth: three ways to see it
Intuition
A CNN is a factory line of identical workstations, and each design in the tour redesigned the workstation. VGG used two or three small tools in a row. Inception gave it several tools working on the same part at once. ResNet added a conveyor that carries the part past the station. DenseNet kept a copy of every earlier part on the table. MobileNet split each tool into a cheap per-channel tool and a mixer. EfficientNet asked how long, how wide and how fine the line should be.
The picture breaks in two places. The stations are trained together, not designed one at a time. And a faster station on paper is not always faster in the real factory, because the hardware likes some layouts better than others.
Math
Weights of a convolution (no bias): , divided by the number of groups for a grouped convolution. A depthwise convolution has weights.
Compound scaling. A convolution layer costs about multiply-adds. Scaling the depth by , the channels by and the height and width by multiplies the cost by . With , , this is , which the constraint turns into about .
Code
Counting the parameters of the torchvision models and the size of two heads.
from torchvision import models
def count(m):
return sum(p.numel() for p in m.parameters())
names = ["alexnet", "vgg16", "googlenet", "resnet50", "densenet121",
"mobilenet_v2", "efficientnet_b0", "convnext_tiny"]
for name in names:
extra = {"aux_logits": False} if name == "googlenet" else {}
model = getattr(models, name)(weights=None, **extra)
print(f"{name:16s}{count(model):>12,}")
vgg = models.vgg16(weights=None)
print("VGG-16 dense head:", f"{count(vgg.classifier):,}")
print("ResNet-50 head :", f"{count(models.resnet50(weights=None).fc):,}")Output from a local run with PyTorch 2.9.1 and torchvision 0.24.1:
alexnet 61,100,840
vgg16 138,357,544
googlenet 6,624,904
resnet50 25,557,032
densenet121 7,978,856
mobilenet_v2 3,504,872
efficientnet_b0 5,288,548
convnext_tiny 28,589,128
VGG-16 dense head: 123,642,856
ResNet-50 head : 2,049,000The aux_logits=False argument leaves out the two auxiliary classifiers of GoogLeNet, which are used only in training. The shape of a pretrained model for your own task is the subject of P5.10.
Try it in Python
The first cell counts the weights of the blocks in this lesson. The second runs the compound-scaling arithmetic, the DenseNet channel growth and the two heads. Both use only NumPy and plain arithmetic, with weights counted without biases.
Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).
Running the cell gives 69,632 weights for the bottleneck against 1,179,648 for two layers, and 144,896 for Inception 3a against 374,784.
Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).
Running the cell gives a cost of , , for , and 411,045,888 against 2,049,000 weights for the two heads.
Common mistakes
Quiz
Check your understanding
In a ResNet-50 bottleneck block that reads 256 channels, the first layer is a convolution from 256 to 64 channels. What is its job?
The layer then works on 64 channels instead of 256, which is why the block has 69,632 weights instead of the 1,179,648 of two layers at 256 channels. The shortcut is a separate path, and a convolution sees one pixel at a time, so it does not enlarge the receptive field. Batch normalization does the normalizing.
In a DenseNet with growth rate 32, a layer receives 128 channels. How many channels does the next layer in the same block receive?
A dense layer produces new maps, and the next layer sees this layer’s input plus those maps: . Passing only the newest maps would describe a plain stack. Adding is what a residual block does. Doubling would need 128 new maps, but there are 32.
A ResNet-50 ends with 2,048 feature maps of size . After global average pooling, how many weights (without bias) does the dense layer to 1,000 classes have?
Pooling turns each map into one number, so 2,048 numbers remain, and each of the 1,000 outputs has one weight per number: (2,049,000 with the biases). The value 100,352,000 is the flattened head that pooling avoids. Each map is averaged separately, so 2,048 numbers remain, not one.
Exercises
- Two layers with 128 channels in and out, against one layer with the same channels (weights only). Which has fewer weights?
Show answer
Two layers: . One layer: , about 39% more. Both see a patch of the input. - A bottleneck block reads 128 channels, shrinks to 32, applies a convolution at 32 channels and expands back to 128. Compare its weights with one layer from 128 to 128 channels (weights only).
Show answer
Bottleneck: . One layer: . The bottleneck has about 8.5 times fewer weights. - DenseNet-121’s third block starts with 256 channels, has 24 layers and growth rate 32. How many channels does layer 10 read, and how many does the block output?
Show answer
Layer 10 reads channels. The block outputs channels. - How much memory do the weights of ResNet-50 (25,557,032 parameters) and of VGG-16 (138,357,544) need in 32-bit floating point? What does this number leave out?
Show answer
About MB and MB (decimal megabytes). It leaves out the activations stored during a forward pass, which depend on the image size and batch size, and during training also the gradients and optimizer state.
Next: P5.10 turns these networks into starting points: transfer learning and fine-tuning reuse a pretrained backbone for your own images.