LeNet-5 Architecture
LeNet-5 is one of the earliest successful Convolutional Neural Networks. It was developed by Yann LeCun and collaborators for recognizing handwritten and machine-printed characters in 1998.
The network was designed for small grayscale images, particularly handwritten digits. Although LeNet-5 is simple compared with modern CNNs, it established a pattern that remains fundamental:
Convolution extracts features, pooling reduces spatial size, and fully connected layers perform classification.
Complete Architecture
The original LeNet-5 takes a grayscale image with the shape:
The complete flow is:
Understanding the Output-Size Formula
For a convolutional layer, the spatial output size is:
where:
- is the input size,
- is the filter size,
- is the padding, and
- is the stride.
The original LeNet-5 convolutions use no padding, so .
Input Layer
The network receives a grayscale image.
Input shape: 32 × 32 × 1
The final dimension is one because a grayscale image contains one intensity channel.
MNIST images are normally . When reproducing the original LeNet-5 architecture, they can be padded to .
No features have been extracted yet. The values are simply pixel intensities.
C1: First Convolutional Layer
C1 is the first feature-extraction layer.
It uses:
- 6 filters,
- a filter size of ,
- stride 1, and
- no padding.
Output Size
The height and width are:
Because six filters are used, six feature maps are produced:
One filter produces one feature map. Six filters produce six feature maps.
Number of Parameters
Each filter has:
weights and one bias.
For six filters:
Therefore, C1 contains 156 trainable parameters.
S2: First Pooling Layer
The original LeNet-5 called S2 a subsampling layer. It performed a trainable average-based reduction.
Modern pooling has no trainable parameters. However, the original LeNet-5 used a slightly different operation called trainable subsampling. After averaging the values inside each (2 \times 2) region, LeNet-5 applied: [ y = a \times \operatorname(x) + b ]
For a modern and beginner-friendly explanation, we can describe it as an average-pooling layer.
S2 uses:
- a pooling window, and
- stride 2.
Output Size
Each non-overlapping region is reduced to one value:
The height and width are reduced by half, but the number of feature maps remains six.
Why Is Pooling Used?
Pooling:
- reduces the spatial dimensions,
- decreases later computation,
- summarizes nearby activations, and
- makes the representation less sensitive to small positional changes.
Historical Detail
The original S2 layer was not exactly the same as modern average pooling. For every feature map, it:
- combined values in a region,
- multiplied the result by a learned coefficient,
- added a learned bias, and
- applied an activation function.
Conceptually:
Modern implementations commonly use a normal AveragePooling2D layer instead.
C3: Second Convolutional Layer
C3 learns more complex patterns by combining the simpler features produced by C1.
It uses:
- 16 filters,
- a filter size of ,
- stride 1, and
- no padding.
Output Size
The spatial dimensions are:
Because the layer produces 16 feature maps, its output shape is:
S4: Second Pooling Layer
S4 is another average-pooling or subsampling layer.
It uses:
- a pooling window, and
- stride 2.
Output Size
The spatial dimensions are reduced from to :
The depth remains 16 because pooling operates independently on every feature map.
At this point, the representation is spatially small but contains more meaningful features than the earlier layers.
C5: Final Convolutional Layer
C5 connects the spatial feature-extraction part of LeNet-5 to its classification part.
It uses:
- 120 filters,
- a filter size of ,
- stride 1, and
- no padding.
Each filter extends through all 16 input channels. Its complete shape is therefore:
Output Size
The input feature maps are already . A filter covers their entire spatial area:
Therefore:
The output can be viewed as 120 learned values.
Why Does C5 Behave Like a Dense Layer?
Each C5 output observes the complete S4 representation. Therefore, for this fixed input size, C5 behaves similarly to a fully connected layer even though it is implemented using convolution.
Number of Parameters
Each filter contains:
weights and one bias.
For 120 filters:
Therefore, C5 contains 48,120 trainable parameters.
F6: Fully Connected Layer
The 120 values produced by C5 are connected to 84 neurons.
120 inputs → 84 neurons
F6 combines the extracted features into a compact representation that can be used for classification.
Number of Parameters
Each of the 84 neurons receives 120 inputs and has one bias:
Therefore, F6 contains 10,164 trainable parameters.
The original network used a scaled hyperbolic tangent activation. Modern recreations may use tanh or ReLU.
Output Layer
For handwritten-digit recognition, the final layer contains ten outputs:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
The original LeNet-5 used a distance-based output related to radial basis functions.
Modern implementations usually use a ten-neuron softmax layer:
Softmax converts the ten output scores into a probability distribution. The class with the highest probability becomes the predicted digit.
How Features Evolve Through LeNet-5
As an image passes through the network, its spatial size decreases while its feature depth generally increases.
Raw pixels
↓
Edges and short lines
↓
Curves and stroke combinations
↓
Character parts
↓
Compact high-level representation
↓
Digit class
The layer shapes evolve as follows:
32 × 32 × 1
↓
28 × 28 × 6
↓
14 × 14 × 6
↓
10 × 10 × 16
↓
5 × 5 × 16
↓
1 × 1 × 120
↓
84
↓
10
This illustrates a central CNN principle:
Spatial dimensions become smaller while the learned representation becomes more meaningful.
Why LeNet-5 Was Important
LeNet-5 demonstrated several ideas that remain important in modern computer vision:
- Local connectivity: A neuron observes only a small region of the previous layer.
- Parameter sharing: The same convolutional filter is reused across the image.
- Learned feature extraction: Filters are learned from data instead of being manually designed.
- Hierarchical representation: Simple features are combined into increasingly meaningful patterns.
- Spatial reduction: Pooling reduces the size and computational cost of feature maps.
- End-to-end learning: Feature extraction and classification are trained together.
Limitations of LeNet-5
- It was designed for small grayscale images.
- It has limited capacity for complex natural images.
- It uses tanh-style activations rather than ReLU.
- The original partial connectivity is inconvenient to reproduce using standard modern layers.
- It cannot capture the diversity and scale of objects found in large datasets such as ImageNet.
- Its fixed architecture is not designed for detection, segmentation or other dense vision tasks.
Key Takeaways
- LeNet-5 accepts a grayscale image.
- C1 uses 6 filters and produces 6 feature maps.
- S2 reduces the feature maps using average-based pooling.
- C3 uses 16 filters to learn more complex visual patterns.
- S4 reduces the spatial size to .
- C5 uses 120 filters that cover the complete spatial representation.
- F6 combines the extracted features using 84 neurons.
- The final layer predicts one of ten digit classes.
- LeNet-5 established the convolution–pooling–classification structure used by later CNNs.
LeNet-5 is small, but it provides an excellent starting point for understanding how a CNN gradually transforms raw pixels into a meaningful prediction.