Deep Learning · Architecture Design
From LeNet to ResNet: Why CNN Architectures Changed
CNN architecture names are useful only when you understand the problem each design tried to solve. This lesson follows the move from small digit recognizers to GPU-scale networks, repeated small filters, multi-scale branches and residual shortcuts. You will calculate why stacked 3 × 3 filters work, trace a residual block with numbers, and learn when a pretrained architecture is a sensible starting point.
An Architecture Is a Plan for Moving and Combining Features
The previous lesson explained convolution, feature maps and pooling. An architecture specifies how many of those operations are used, how they connect, when spatial size shrinks, how channel count grows and how the final prediction is produced. Changing the plan changes accuracy, memory, speed and how easily gradients reach early layers.
The classic architectures below are milestones because each demonstrated a reusable idea. Later models did not simply “add more layers”; they found better ways to use depth, computation and information flow.
CNN progress was a sequence of solved bottlenecks
Read this as a map of design ideas, not a leaderboard for today.
LeNet-5 Established the Basic CNN Pattern
LeNet-5 was designed for small grayscale character images. Its recognizable flow—convolution, subsampling, another convolution, then fully connected classification—showed that a network could learn local stroke patterns and combine them into digit evidence. It is small enough to study, but its original activations and training context belong to an earlier era.
Read an architecture as a sequence of explained shape changes
The historical LeNet-5 flow is useful because every dimension can be followed. Shapes below use channels × height × width for one image.
AlexNet Showed What Scale, ReLU and GPUs Could Do
AlexNet tackled ImageNet: roughly 1.2 million training images across 1,000 classes in the original competition setup. Its five convolutional and three fully connected learned layers were far larger than LeNet. GPU training made the computation feasible; ReLU activations trained faster than saturating tanh units in that setting; overlapping max pooling, data augmentation and dropout were important parts of the system.
Compute
The original network split work across two GPUs because the model did not fit conveniently on one GPU of that era.
Optimization
ReLU produced positive linear responses instead of saturating both sides like sigmoid/tanh.
Generalization
Random crops/reflections and dropout reduced overfitting in a high-capacity model.
VGG Made Depth Easy to Read
VGG replaced a mixture of large filter sizes with a regular pattern: repeat 3 × 3 convolutions, then downsample. Stacking small filters gradually grows the receptive field while placing nonlinear activations between calculations. VGG-16 is conceptually clean and remains useful for education and feature-based perceptual losses, but its dense classifier makes the standard model very large.
Why VGG repeated 3 × 3 convolutions
Two stride-1, unpadded 3 × 3 layers give the second layer a 5 × 5 receptive field, with a nonlinearity between them.
3 × 3
first local view
3 × 3
second local view
5 × 5
effective receptive field
One 5×5 filter: 25 spatial weights per input-output channel pair.
Two 3×3 filters: 18 spatial weights in this simplified single-channel comparison, plus an extra learned nonlinearity.
GoogLeNet Looked at Multiple Scales Without Paying the Full Cost
A small filter is good for fine detail; a larger filter sees a wider region. An Inception module sends the same input through several branches and concatenates their output channels. A 1 × 1 convolution is more than a spatial filter: at each position it learns a weighted combination across input channels and can reduce the number of channels before a costly 3 × 3 or 5 × 5 operation.
An Inception module asks several size questions in parallel
Why place a 1 × 1 convolution before an expensive 5 × 5 branch?
Suppose one location has 192 incoming channels and the branch should produce 32 output channels. These channel counts are architecture choices. Ignore biases so the comparison stays focused.
Direct 5 × 5 convolution
5 × 5 spatial weights
× 192 input channels
× 32 output filters
= 153,600 weights
Reduce to 16 channels, then use 5 × 5
1×1 reduction: 1×1×192×16 = 3,072
5×5 branch: 5×5×16×32 = 12,800
total = 15,872 weights
GoogLeNet also used global average pooling near the end, avoiding the enormous dense head seen in VGG. The trade-off is a more complicated branching design. Modern descendants changed the exact factorization and normalization choices, but the multi-scale and bottleneck ideas remained influential.
Why Simply Making a Plain Network Deeper Can Fail
Depth lets a network compose more stages of representation, but a deeper plain network can be harder to optimize. The ResNet authors highlighted a degradation problem: adding layers could produce higher training error, even when overfitting was not the explanation. In principle, extra layers could copy their input and do no harm; in practice, learning that identity through many nonlinear layers was difficult.
A residual block makes the easy path explicit. The main branch learns F(x), a change to the input, while the shortcut carries x directly. Their sum lets a block preserve information when a large change is unnecessary and gives gradient information a direct route backward.
A residual block learns a useful change while preserving a direct route
One residual addition with numbers
For a transparent teaching example, we manually choose the incoming feature vector x = [2, −1] and suppose the convolutional branch has calculated F(x) = [0.5, 0.8]. In a trained network, x comes from the previous layer and F(x) is produced by learned convolution and normalization parameters.
1. Main branch result
F(x) = [0.5, 0.8]
2. Add matching positions
[0.5+2, 0.8+(−1)]
= [2.5, −0.2]
3. Apply ReLU
[max(0,2.5), max(0,−0.2)]
= [2.5, 0]
Why addition? It preserves the original signal while letting the branch propose a correction at each matching position. The gradient of the addition also contains a direct identity route back to x. Addition requires equal shapes; when shapes differ, the shortcut must first project x to the required size.
Compare the Design Idea, Not Just the Depth Number
| Architecture | Published | Recognizable design | Problem it helped solve | Important limitation |
|---|---|---|---|---|
| LeNet-5 | 1998 | Small conv/pool network for handwritten digits | Showed learned local features could replace much manual feature design | Historical teaching; input and activations differ from modern practice |
| AlexNet | 2012 | 5 convolutional + 3 dense trainable layers; ReLU, dropout, GPU training | Made large-scale deep CNN image classification practical | Large early filters and dense head are compute/parameter heavy |
| VGG-16 | 2014 | Uniform stacks of 3×3 convolutions | Simple repeated design increased depth and receptive field | About 138M parameters in the standard ImageNet model |
| GoogLeNet / Inception v1 | 2014 | Parallel 1×1, 3×3, 5×5 and pooling branches | Captured multiple scales while reducing expensive channel dimensions | Branch design is more complex than a plain sequential stack |
| ResNet | 2015 | Residual blocks with identity shortcuts | Made substantially deeper networks easier to optimize | Shortcuts help optimization but do not remove compute or guarantee better generalization |
Parameter totals depend on the exact variant and classifier. For reference, Keras lists approximately 138.4M parameters for its standard VGG16 and 25.6M for ResNet50; depth and parameter count are not the same measurement.
Implement the Residual Idea Before Using a Full ResNet
This teaching block keeps the same number of channels and the same height and width, so the identity tensor can be added directly. Batch normalization and ReLU are shown in a common basic-block arrangement.
import torch
from torch import nn
class BasicResidualBlock(nn.Module):
def __init__(self, channels):
super().__init__()
self.main = nn.Sequential(
nn.Conv2d(channels, channels, 3, padding=1, bias=False),
nn.BatchNorm2d(channels),
nn.ReLU(),
nn.Conv2d(channels, channels, 3, padding=1, bias=False),
nn.BatchNorm2d(channels),
)
self.relu = nn.ReLU()
def forward(self, x):
residual = self.main(x) # learn F(x)
return self.relu(residual + x) # add identity path
block = BasicResidualBlock(channels=32)
x = torch.randn(8, 32, 28, 28)
y = block(x)
print(y.shape) # torch.Size([8, 32, 28, 28])If a block changes shape—for example 32 to 64 channels with stride 2—the shortcut also needs a projection that produces the same shape. Tensor addition cannot combine mismatched dimensions.
Where the code dimensions come from: 8 is a chosen teaching batch size; 32 is the chosen channel count for the block; 28 × 28 is a sample spatial size. None of these values is learned.
What the layers do internally: each 3 × 3 convolution learns filters, padding 1 preserves 28 × 28, BatchNorm normalizes each channel and learns scale/shift parameters, and residual + x performs elementwise addition.
In Practice, Start From a Pretrained Model
For most applied image projects, recreating AlexNet or training ResNet from random weights is not the first choice. A model pretrained on a large image collection has already learned useful visual features. Replace its classifier for your classes, begin with conservative fine-tuning, and validate latency, memory and accuracy on your own data.
| Project constraint | Reasonable starting direction | Why |
|---|---|---|
| Learning architecture mechanics | LeNet-like network or hand-built residual block | Small enough to trace every shape |
| General image baseline | Pretrained ResNet-18/50 | Widely supported residual backbone |
| Very small device budget | MobileNet/EfficientNet-family lightweight variant | Designed for parameter/FLOP efficiency |
| Need simple feature extractor for legacy workflow | Pretrained VGG features | Easy sequential blocks, but heavy model |
| Large modern vision pretraining | Compare modern CNN with Vision Transformer | Global attention and convolutional bias trade off differently |
Mistakes That Architecture Diagrams Can Hide
Counting names instead of tensors
Trace N×C×H×W and the shortcut shape through every stage. A familiar block name does not prevent a dimension error.
Assuming deeper always means better
Optimization, data size, regularization, compute and task difficulty matter. Compare validated systems, not layer counts.
Using historical preprocessing blindly
Use the preprocessing specified for the exact pretrained weights. Input size and normalization differ across model families.
Comparing parameter count alone
Latency depends on operation type, resolution, hardware, memory movement and implementation—not just parameters.
Forgetting the classifier head
A 1,000-class ImageNet head does not match a four-class project. Replace and train the final layer deliberately.
Loading weights into the wrong variant
Match architecture, version and weight enum; strict loading errors often reveal a real mismatch rather than an inconvenience.
The Design Story to Remember
- LeNet established the convolution–downsample–classify pattern.
- AlexNet demonstrated deep CNNs at ImageNet scale with GPUs, ReLU and strong regularization.
- VGG made depth systematic by stacking small 3 × 3 filters.
- GoogLeNet processed several spatial scales in parallel and used 1 × 1 bottlenecks.
- ResNet added identity shortcuts so blocks could learn changes instead of reconstructing everything.
- A modern project should select and benchmark a pretrained architecture against its actual accuracy, latency, memory and data constraints.