15 · Why CNNs: spatial structure + parameter sharing
MLPs ignore spatial structure and explode in parameters on images; CNNs exploit locality and weight sharing to slash parameter counts by 4 orders of magnitude.
A fully-connected layer ignores spatial structure; a convolution slides the SAME small filter across the image — far fewer parameters AND respects locality.
Without this:
MLP on a 224×224×3 image needs 150k params per neuron in the first layer; CNN needs ~3×3×3=27.
The moment you apply a standard fully-connected (MLP) layer to an image, you run into a wall. A modest 224×224×3 image is 150,528 numbers. If the first hidden layer has 256 neurons, that layer alone needs 150,528 × 256 = 38.5 million parameters — before a single other layer, before any depth. For the network to learn, you'd need billions of labelled images just to avoid memorising the training set.
But the real problem isn't just scale — it's the wrong inductive bias. A fully-connected layer treats every pixel as equally related to every other pixel. That's fine for a spreadsheet row where column order is arbitrary. For images it's absurd: a pixel's most informative neighbours are the pixels immediately around it. The edge between a dog's ear and the sky is a local pattern; there's no reason for that neuron to depend on a pixel 200 columns away.
Convolutional Neural Networks (CNNs) solve both problems with one idea: instead of one weight per (input pixel, neuron) pair, use a small filter — a 3×3 or 5×5 grid of weights — and slide it across the entire image, applying the same weights everywhere. This is parameter sharing: one filter, one set of weights, applied at every location.
Three properties fall out of this design:
- Local receptive fields — each output depends only on a small neighbourhood.
- Parameter sharing — one filter learns one feature (e.g., a vertical edge) and detects it everywhere.
- Translation equivariance — if the input shifts, the output shifts by the same amount.
These properties match the statistics of natural images almost perfectly, which is why CNNs dominated computer vision from AlexNet (2012) until Vision Transformers emerged a decade later.
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
The three core properties of CNNs: local receptive fields, parameter sharing, translation equivariance
Brain analogy: Hubel & Wiesel's visual cortex experiments and their connection to CNNs
Python (in browser)
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Why does a CNN need 4 orders of magnitude fewer params than an MLP on images?
- MLP on a 224×224×3 image → ~38M params in first layer; CNN with 32 filters of 3×3×3 → 864 params — 4 orders of magnitude smaller.
- Three CNN properties: (1) local receptive fields, (2) parameter sharing — same filter slides everywhere, (3) translation equivariance — output shifts when input shifts.
- CNN hierarchy mirrors the visual cortex hierarchy discovered by Hubel & Wiesel in 1959: edges → curves → object parts → whole objects.
- CNNs are equivariant (not invariant) to translation; max-pooling adds partial invariance; full invariance requires data augmentation or group convolutions.
Every image classifier, object detector, and segmentation model since 2012 is CNN-based or has a CNN backbone. Vision Transformers are starting to replace them but most production CV is still CNN.
If you remove it: You'd try to apply MLPs to images, hit the parameter explosion immediately, and have no mental model for why modern vision models are designed the way they are.