←Back to 03 / Published Articles
03 / Resources/Deep Learning · Convolutional Neural Networks
Interactive Diagnostic Essay · Topic 08

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.

01 / The Sliding Filter

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.

7×7 INPUT × 3×3 KERNEL → 5×5 FEATURE MAPlooping · 25 positions per cycle
input image
kernel (edge detector)
+1
0
-1
+1
0
-1
+1
0
-1
Σ (pixel × weight)
feature map (output)
0
0
3
3
0
0
0
3
3
0
0
0
3
3
0
0
0
3
3
0
0
0
3
3
0

the edge column of the feature map lights up — the filter found the border

02 / Why Not Just Flatten?

Weight Sharing & Translation Invariance

A dense layer connecting a 28×28 image to just 1,000 neurons needs 784,000784{,}000 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.

The Convolutional Counter-Offer

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.

Parameter Count Formulaparams=(k×k×Cin+1)×Cout\text{params} = (k \times k \times C_{\text{in}} + 1) \times C_{\text{out}}

For 8 filters of 3×3 on grayscale: (9+1)×8=80(9+1) \times 8 = 80 weights instead of 784,000. Depth (channels) grows as spatial size shrinks.

The output size follows from three knobs — kernel size kk, stride (step size), and padding (zero-border):

Output Spatial SizeO=⌊N−k+2PS⌋+1O = \left\lfloor \frac{N - k + 2P}{S} \right\rfloor + 1
STRIDE

How far the window jumps each step. Stride 2 halves the output — cheap downsampling.

PADDING

A zero border lets the filter visit the edges and keeps output size equal to input (“same” padding).

CHANNELS

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).

03 / Shrinking Without Losing the Point

Max Pooling

After each convolution, a pooling layer downsamples the feature map. Max pooling splits the map into 2×22 \times 2 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.

4×4 → 2×2 · 75% of values dropped · zero learned parameters

Modern architectures sometimes replace pooling with strided convolutions, but the idea — shrink spatial, keep signal — is everywhere.

MAX POOL 2×2 · STRIDE 2looping
3
1
2
0
1
4
0
2
2
0
6
1
0
3
1
5
→
4
2
6
5

each output = max of its 2×2 quadrant

04 / The Full Pipeline

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.

INPUT
28×28×1
pixel grid
CONV
26×26×8
8 filters
ReLU
26×26×8
clamp ≥ 0
POOL
13×13×8
max 2×2
CONV
11×11×16
16 filters
POOL
5×5×16
max 2×2
FLAT
400
unroll
DENSE
128
reason
SOFTMAX
10
probabilities
spatial shrinks 28 → 26 → 13 → 11 → 5 · depth grows 1 → 8 → 16 · dense layers decide
ReLU — THE NONLINEAR SPARKReLU(x)=max⁡(0,x)\text{ReLU}(x) = \max(0, x)

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.

SOFTMAX — THE FINAL VERDICTsoftmax(zi)=ezi∑jezj\text{softmax}(z_i) = \frac{e^{z_i}}{\sum_j e^{z_j}}

Converts 10 raw scores into a probability distribution that sums to 1 — Topic 02's sigmoid, generalized to many classes.

05 / Landmark Lineage

From LeNet to ResNet

LeNet-5 · 1998

The original digit reader — the exact CONV→POOL→FLAT→DENSE skeleton you animated above.

AlexNet · 2012

Same skeleton, GPUs + ReLU + dropout. Won ImageNet by a mile and started the deep learning era.

VGG · 2014

Showed depth matters: only 3×3 kernels, stacked very deep. Simple and uniform — but heavy.

ResNet · 2015

Skip connections let gradients bypass layers, making 100+ layers trainable. The backbone of modern vision.

THE ROAD AHEAD

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.

06 / What Each Neuron Sees

Receptive Fields & the Price of Sharing

A single neuron in a 3×33 \times 3 convolution only ever looks at 3×33 \times 3 pixels — its receptive field. Stack a second convolution on top and each of its neurons reads a 3×33 \times 3 block of the first feature map, which was itself built from overlapping 3×33 \times 3 patches. The window it effectively sees in the original image is therefore 5×55 \times 5. Add a third and it becomes 7×77 \times 7.

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.

Receptive Field Recurrencerout=rin+(k−1)∏isir_{\text{out}} = r_{\text{in}} + (k - 1)\prod_i s_i

Each layer adds k−1k-1 to the window, scaled by the strides already applied before it.

StackField
1 × conv 3×33×3
2 × conv 3×35×5
3 × conv 3×37×7
2 × conv + pool 2×210×10
WHY THIS IS ONLY POSSIBLE WITH SHARING

A dense layer feeding a 28×28 image to 1,000 neurons needs 784,000784{,}000 independent weights, and stacking three of those makes the cost explode. Convolution replaces them with one 3×33 \times 3 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.