LeNet-5 (LeCun et al., 1998) read handwritten digits on bank cheques with two convolution and subsampling stages followed by three fully connected layers, about 60 thousand parameters in all. It established the pattern every later CNN follows: local receptive fields, shared weights, and spatial subsampling, trained end to end by backpropagation. This page walks through its layers, shapes and parameter counts, and the original design choices that modern reimplementations drop. In the exercises you build LeNet-5 and count its 61,706 parameters, then repeat LeCun's 1989 comparison on shifted digits: a convolutional network with 1,030 parameters generalised to 0.59 test accuracy against 0.49 for a locally connected network and 0.42 for a fully connected one, all fitting the training data perfectly.
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.
The first working CNN
LeNet-5 looks at a 32 × 32 picture of a digit. Small 5 × 5 detectors slide over it looking for strokes; their outputs are shrunk by averaging neighbouring pixels; a second set of detectors looks for combinations of strokes; and a few fully connected layers turn those into ten scores, one per digit. Banks used systems built on it to read millions of cheques a day in the late 1990s.
Architecture explorer: shapes, parameters and compute
stage
output C × H × W
parameters
multiply–adds
C1
6 × 28 × 28
156
117.6 k
S2
6 × 14 × 14
0
0
C3
16 × 10 × 10
2.4 k
240.0 k
S4
16 × 5 × 5
0
0
F5
120 × 1 × 1
48.1 k
48.0 k
F6
84 × 1 × 1
10.2 k
10.1 k
out
10 × 1 × 1
850
840
Total: 61,706 parameters (61.7 k), 416.5 k multiply–adds per image at 32 × 32.
Bars show each row's share of the total. Convolutions dominate compute because they run at every position; fully connected layers dominate parameters in older designs (AlexNet, VGG). Changing the input size changes the compute of every convolution but not its parameters. Parameter counts include biases and BatchNorm scale and shift and match torchvision's implementations.
Why engineers care
Every image network since, from AlexNet to the detectors on drones and rovers, keeps LeNet’s three ideas: local connections, shared weights and subsampling.
📝 Quick check (Level 0)
0/3 answered
1. LeNet-5 was built to read…
2. Its detectors are…
3. Subsampling…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.
By hand
Layers on a 1 × 32 × 32 input, in a modern reimplementation with full connectivity:
layer
operation
output
parameters
C1
6 convolutions 5 × 5
6 × 28 × 28
6·25 + 6 = 156
S2
2 × 2 average pooling
6 × 14 × 14
0
C3
16 convolutions 5 × 5 × 6
16 × 10 × 10
16·150 + 16 = 2,416
S4
2 × 2 average pooling
16 × 5 × 5
0
F5
fully connected 400 → 120
120
48,120
F6
fully connected 120 → 84
84
10,164
output
fully connected 84 → 10
10
850
Total: 61,706 parameters, 96% of them in the fully connected layers.
Multiply–adds: C1 needs 28·28·6·25 = 117,600 and C3 needs 10·10·16·150 = 240,000, more than F5’s 48,000, although C3 has 20 times fewer parameters.
📝 Quick check (Level 1)
0/3 answered
1. C1 output size from a 32 × 32 input with 5 × 5 kernels:
2. C3 parameters (full connectivity):
3. Most parameters are in…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.
LeNet-5 in code
Exercise 1.
The forward pass produced the expected shapes at every stage.
The parameter count was exactly 61,706.
One entry of the convolution matched a hand-computed sum.
Practice.
A modern LeNet-5 uses ReLU and max pooling, which train faster than the original tanh and trainable subsampling, and plain linear outputs with a softmax cross-entropy loss.
It reaches about 99% accuracy on MNIST in a few epochs on a CPU.
MNIST images are 28 × 28, so either pad them to 32 or add padding 2 to C1.
Implement convolution, average pooling and the LeNet-5 forward pass, and count its parameters.
📝 Quick check (Level 2)
0/3 answered
1. Modern reimplementations replace tanh by…
2. To feed 28 × 28 MNIST images, C1 uses padding…
3. Typical MNIST accuracy of LeNet-5:
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.
Theory
Three ideas.
Local receptive fields: each unit sees only a small patch, matching the local structure of images.
Shared weights: the same kernel is used at every position, so a feature detector learned in one place works everywhere, and the number of free parameters does not grow with image size.
Subsampling: pooling reduces resolution and gives some tolerance to small shifts and distortions.
Original details.
C3 connected each of its 16 maps to only a subset of S2’s 6 maps (a connection table). That gave 1,516 parameters instead of 2,416 and broke symmetry between maps.
S2 and S4 had a trainable coefficient and bias per map.
The output layer used Euclidean radial basis functions with fixed targets.
The full model had about 60 thousand trainable parameters and 340 thousand connections.
Why sharing generalises. A fully connected layer must learn a separate detector for every position, so it needs examples of every pattern at every position. Weight sharing builds in translation equivariance, which reduces the hypothesis space and the amount of data needed (exercise 2).
📝 Quick check (Level 3)
0/3 answered
1. Shared weights make the parameter count…
2. The original C3 used…
3. Weight sharing builds in…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.
Why share weights?
History.
K. Fukushima (1980) proposed the Neocognitron, with local features and subsampling but no backpropagation.
Y. LeCun et al. (1989) trained a shared-weight network on zip codes by backpropagation, and compared fully connected, locally connected and shared-weight networks.
Y. LeCun, L. Bottou, Y. Bengio, P. Haffner (1998) described LeNet-5 and graph transformer networks for cheque reading; LeNet-5 reached 0.95% test error on MNIST (0.8% with distortions).
Exercise 2. The data are 5 × 7 digit glyphs placed anywhere on a 10 × 10 canvas, with noise and 10% of stroke pixels erased; 300 training and 1,000 test images. Three networks are compared:
fully connected;
locally connected (3 × 3 receptive fields with separate weights at every position);
convolutional (the same 3 × 3 kernels everywhere).
Both of the latter use 6 maps, 2 × 2 average pooling and a linear output. Each is trained with Adam for 200 steps; results are the mean of 2 seeds:
network
parameters
train accuracy
test accuracy
fully connected (100–30–10)
3,340
1.000
0.424
locally connected 3 × 3
4,810
1.000
0.486
convolutional 3 × 3
1,030
1.000
0.585
All three memorised the training set; only their generalisation differed.
Local connections helped a little; sharing helped most, with the fewest parameters. A stroke detector learned at one position transfers to every other. Seeds 2 to 4 gave the same ordering (shared 0.60, 0.60, 0.60; fully connected 0.40, 0.46, 0.41).
Accuracy is still far from perfect: the fully connected output layer after pooling must learn each digit at each coarse position. Later networks add more convolution and pooling stages, or global pooling (E8-5), to remove that dependence.
🐍 Exercise 2 (research): why share weights?
Train fully connected, locally connected and convolutional networks on shifted digits and compare their parameters and test accuracy.
LeNet in AI, robotics and aerospace
Document reading: cheque and postal-code readers built on LeNet were among the first commercial neural-network systems.
Embedded vision: LeNet-sized networks still run on microcontrollers for digit, gesture and simple sign recognition.
Teaching and testing: LeNet on MNIST is the standard first experiment and a sanity check for new hardware and frameworks.
References
Y. LeCun et al. (1989). “Backpropagation applied to handwritten zip code recognition.” Neural Computation 1(4).
Y. LeCun, L. Bottou, Y. Bengio, P. Haffner (1998). “Gradient-based learning applied to document recognition.” Proc. IEEE 86(11).
K. Fukushima (1980). “Neocognitron: a self-organizing neural network model for a mechanism of pattern recognition unaffected by shift in position.” Biological Cybernetics 36.
Test-accuracy gain of the convolutional over the fully connected network?
0.585 − 0.424 = 0.161.
Level 3
Problem 14Level 3
Show that a convolution’s parameter count does not depend on the image size.
A convolution applies the same Cout kernels of size k × k × Cin, plus Cout biases, at every position. The number of positions depends on the image size, but the weights are shared across them, so the count k²·Cin·Cout + Cout contains no H or W. ∎
Problem 15Level 3
Explain why the locally connected network generalised worse than the convolutional one, although it has the same receptive fields.
Each position of the locally connected layer has its own weights, which are trained only by the examples whose strokes fall there. A digit at a position rarely seen in training meets untrained detectors. With sharing, all positions use the same detectors, trained by every example, so a stroke learned anywhere is recognised everywhere. The locally connected network also has 4.7 times more parameters to fit from the same 300 images. ∎
Problem 16Level 3
Compare where LeNet-5’s parameters and its compute are concentrated.
Parameters: 59,134 of 61,706 (96%) are in the fully connected layers. Compute: C1 and C3 need 117,600 + 240,000 = 357,600 multiply–adds against 48,000 + 10,080 + 840 = 58,920 for the fully connected layers (86% in the convolutions). Convolutions reuse few weights at many positions; fully connected layers use many weights once. ∎
Problem 17Level 3
Advise whether LeNet-5 is a good choice for reading digits on a microcontroller in a utility meter.
Yes, as a starting point: about 62 thousand parameters (under 250 kB in 32-bit floats, about 62 kB in 8-bit integers) and about 0.4 million multiply–adds per image fit small devices. Train on images from the actual meters, with augmentation for lighting and blur; quantise to 8 bits; check accuracy per digit and on worn or partly occluded digits. Replace F5 by global pooling if memory is tight. ∎
Level 4
Problem 18Level 4
Parameters of the original sparse C3, as reported by LeCun et al.?
1516.
Problem 19Level 4
LeNet-5’s MNIST test error without distortions, in percent?
0.95.
Problem 20Level 4
Test accuracy of the locally connected network in exercise 2?
0.486.
Coding practice
🐍 Code 1 (Level 1): output size
⌊(n + 2p − k)/s⌋ + 1.
🐍 Code 2 (Level 1): convolution parameters
k²·Cin·Cout plus biases.
🐍 Code 3 (Level 0): fully connected parameters
nin·nout plus biases.
🐍 Code 4 (Level 1): LeNet shapes
Spatial size after C1, S2, C3, S4.
🐍 Code 5 (Level 1): saving from sharing
Locally connected weights over convolution weights.
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
LeNet-5: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.