Convolutional Neural Networks
A tiny magnifying glass sweeping across an image is the whole idea. Watch a real filter slide over real pixels, watch edges become feature maps, and follow the data through a full CNN — all on loop.
Convolution: A Flashlight Over the Pixels
On the left is a 7×7 image — bright on the left, dark on the right, so a vertical edge runs down the middle. The red 3×3 window is the filter (kernel). It starts in the corner, multiplies its 9 numbers with the 9 pixels underneath, sums them into one output pixel, then steps one cell right — raster-scanning the whole image. The output grid on the right is the feature map: bright where the filter found its pattern.
the edge column of the feature map lights up — the filter found the border
Weight Sharing & Translation Invariance
A dense layer connecting a 28×28 image to just 1,000 neurons needs weights — and a cat in the top-left corner teaches it nothing about a cat in the bottom-right, because every pixel gets its own private weights.
Use the same 9 weights at every position. One 3×3 filter = 9 numbers (plus 1 bias), slid across the entire image. A cat anywhere is still a cat, because the detector looks for the same local pattern everywhere.
For 8 filters of 3×3 on grayscale: weights instead of 784,000. Depth (channels) grows as spatial size shrinks.
The output size follows from three knobs — kernel size , stride (step size), and padding (zero-border):
How far the window jumps each step. Stride 2 halves the output — cheap downsampling.
A zero border lets the filter visit the edges and keeps output size equal to input (“same” padding).
Filters are 3D (k×k×channels). 64 stacked outputs = 64 feature maps = depth of the next layer.
Early filters learn edges and blobs; deeper layers combine them into corners, textures, eyes, wheels, faces. Nobody programs this — it emerges from backpropagation (Topic 07).
Max Pooling
After each convolution, a pooling layer downsamples the feature map. Max pooling splits the map into tiles and keeps only the strongest activation per tile.
Why throw information away? Because whether an edge was found matters more than exactly which pixel it peaked on. Pooling buys translation tolerance: shift the input a little, the max stays the same.
Modern architectures sometimes replace pooling with strided convolutions, but the idea — shrink spatial, keep signal — is everywhere.
each output = max of its 2×2 quadrant
A Classic CNN, End to End
Stack the pieces — convolve, activate, pool, repeat — then flatten and hand over to dense layers for the final verdict. Below is a LeNet-style digit classifier; the flowing dots show a batch of pixels riding the conveyor belt. Spatial size shrinks, channel depth grows, until the network thinks in pure concepts.
Without it, 100 convolutions collapse into one big convolution — the whole network would be a single linear map. ReLU keeps the negatives silent and lets depth mean something.
Converts 10 raw scores into a probability distribution that sums to 1 — Topic 02's sigmoid, generalized to many classes.
From LeNet to ResNet
The original digit reader — the exact CONV→POOL→FLAT→DENSE skeleton you animated above.
Same skeleton, GPUs + ReLU + dropout. Won ImageNet by a mile and started the deep learning era.
Showed depth matters: only 3×3 kernels, stacked very deep. Simple and uniform — but heavy.
Skip connections let gradients bypass layers, making 100+ layers trainable. The backbone of modern vision.
CNNs conquer space — images, where neighbors matter. But language, audio and time series have a before and after. For that, the next topic rolls the network out along a timeline.
Receptive Fields & the Price of Sharing
A single neuron in a convolution only ever looks at pixels — its receptive field. Stack a second convolution on top and each of its neurons reads a block of the first feature map, which was itself built from overlapping patches. The window it effectively sees in the original image is therefore . Add a third and it becomes .
Depth is a zoom-out machine: shallow layers detect tiny local patterns (edges, corners), deep layers respond to large structures (eyes, wheels, faces) while still computing each response from a small local kernel. Pooling accelerates the zoom-out — a stride-2 pool roughly doubles every subsequent hop, so a handful of layers can cover the whole image.
That growth is also what buys translation tolerance. Shift the input a few pixels and the same features simply land in neighbouring neurons; after pooling keeps only the strongest activation per tile, the deeper representation barely changes. A dense network would instead have to relearn the pattern at every position.
Each layer adds to the window, scaled by the strides already applied before it.
| Stack | Field |
|---|---|
| 1 × conv 3×3 | 3×3 |
| 2 × conv 3×3 | 5×5 |
| 3 × conv 3×3 | 7×7 |
| 2 × conv + pool 2×2 | 10×10 |
A dense layer feeding a 28×28 image to 1,000 neurons needs independent weights, and stacking three of those makes the cost explode. Convolution replaces them with one kernel — 9 weights plus a bias — reused at all 26×26 positions. Sharing is exactly what makes deep stacks affordable: 80 parameters for 8 filters instead of 784,000, while still letting the receptive field grow layer by layer. The network learns a detector once and applies it everywhere, which is also why a cat in any corner triggers the same feature.
