ML Systems Lab Open interactive version →
Intermediate 31 min read CNNconvolutionpoolingreceptive fieldcomputer vision

Convolutional Neural Networks

Convolution mechanics, pooling, receptive field, translation equivariance

Everything so far — activation choice, normalisation, the optimiser's step size — assumed a network of generic flat layers, and said nothing about whether *flat* is even the right shape for the input. For an image, it isn't. Take a 28×28 MNIST digit — 784 raw pixels. Feed them into a flat linear layer of 128 units and you need 784×128 = 100,352 parameters just for that one layer. Worse than the parameter count: the model treats pixel (3,4) and pixel (3,5) as completely independent inputs. Nothing in the architecture says these two pixels are neighbours, that they participate in the same local edge, or that an edge at position (3,4) is the same *kind* of feature as an edge at position (15,20). If the model wants to recognise "a horizontal edge," it has to separately learn that concept, from scratch, at every one of the 784 positions it might appear.

Picture a stencil — a small cut-out pattern you can lay over any part of a larger surface and trace through. Cut the stencil for a horizontal edge once, and you can hold it up to *any* patch of the image; the same nine numbers on the stencil test for "is there a horizontal edge here" whether "here" is the top-left corner or the dead centre. Now picture the flat linear layer's alternative: instead of one reusable stencil, it hand-draws a *separate* horizontal-edge detector at every single position, never reusing the shape it already learned three pixels over. That is the structural gap a flat layer can't close on its own — it has no notion that "here" and "three pixels to the right" might want the same test.

Convolution is that stencil, made mathematical. A 3×3 filter slides across the image, computing a dot product at every position: the same 9 weights applied at (3,4), at (15,20), and at every other location. That is weight sharing — the filter has 9 parameters regardless of image size. Learn a horizontal-edge detector once and it fires on horizontal edges *everywhere*, because the same weights do the computation everywhere — a single 3×3 filter does with 9 numbers what the flat layer above needed 100K numbers to attempt. Pooling takes a filter's output over a small spatial region and keeps only the maximum: if the edge appeared slightly left or slightly right within that region, the pooled value is the same either way — a small, deliberate loss of exact position in exchange for *position invariance*. Stack several convolutional layers and a hierarchy emerges: the first layer detects edges, the second combines edges into corners and curves, the third into shapes, the fourth into objects. Each deeper neuron's receptive field — the patch of the *original* image its value depends on — grows with every convolution it sits behind: a neuron at layer 5 of a 3×3-stride-1 network has a receptive field of 11×11 pixels, spanning a neighbourhood wide enough to cover multiple objects, not just one edge.

NOT this. "CNNs were designed for images." The principle — local patterns plus translation equivariance — applies anywhere locality matters. 1D CNNs classify audio and DNA sequences, where adjacent time steps or nucleotides are locally related. 3D CNNs process video, where nearby frames in time are locally correlated. Graph CNNs extend the idea to molecular structures and social networks. The architecture is not about pixels; it is about exploiting whatever spatial or sequential structure your data has. If your input has the property that neighboring elements are more related than distant elements, a convolutional inductive bias is appropriate. If your input is a bag of features with no meaningful ordering, it is not.

Key points

Takeaway

A CNN's efficiency comes entirely from weight sharing: the same filter applied everywhere encodes the assumption that features repeat across space, cutting parameters 100× versus a flat model and building translation equivariance into the architecture by construction.

Recap

Check your understanding

Q1. A convolutional layer has filter size 3×3, 64 input channels, 128 output channels. How many parameters? How does this compare to a fully connected layer with the same input/output dimensions? Select the TWO correct statements.

Q2. Why does max pooling help with spatial invariance, and what is the downside for tasks requiring precise localisation?

Q3. What is the receptive field of a neuron after three 3×3 convolutional layers (no pooling)? Why does depth matter for receptive field size?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →