Inside a CNN

A convolutional network is a pipeline, and this page runs the whole thing live on a 16×16 image you control: convolve → ReLU → pool → classify. Every number you see is really computed. Draw a shape, watch four feature maps light up, watch pooling shrink them — then train two classifiers on the spot and discover why the convolutional one wins.

conv → ReLU → poolfeature maps weight sharingreceptive fields

The pipeline, stage by stage

Stage 1 you already know from image kernels: four 3×3 kernels slide over the input, each producing a feature map — a picture of "how much does my pattern exist here?". Ours detect vertical edges, horizontal edges, and the two diagonals. Stage 2, ReLU, throws away the negative half ("anti-evidence") — remember, convolution is linear, so without this bend a deep CNN would collapse into one useless linear op. Stage 3, max pooling, keeps only the strongest response in each 2×2 window: the maps halve in size (14×14 → 7×7), the "what" survives, the "exactly where" blurs — and it costs zero learnable parameters. Then we pool again (7×7 → 3×3), because real CNNs stack these stages — and each stage widens the blur: one pool forgives a 1-pixel shift, two pools forgive several. Hover any feature-map pixel to see which input patch it watches — its receptive field — and notice it growing from 3×3 to half the image as you go deeper.

Draw → convolve → ReLU → pool → classify

shift:
input 16×16 (click to edit)
conv maps 14×14 (hover → receptive field)
max-pooled 7×7 — half the size, no parameters
pooled again 3×3 — the forgiveness radius grows (hover: receptive fields are huge now)
🧠 CNN head — softmax on the 36 twice-pooled features
🥩 raw-pixel head — softmax on the 256 raw pixels
untrained

Both heads see the SAME training set: 240 noisy, jittered shapes. Only their features differ.

The experiment that explains CNNs

Press 🎓 train both heads. Two identical softmax classifiers learn from identical data — every training shape jittered by at most one pixel — and the only difference is what they look at: one reads the 256 raw pixels, the other reads the 36 conv+pool+pool features. On familiar data, both ace it. Then read the second line: on shapes shifted 2 pixels — farther than anything either head ever saw — the raw head collapses to near coin-flipping while the CNN head stays perfect. Recreate it by hand: pick the ◯, press shift → and shift ↓ twice each, and watch the raw head confidently call it a ╱ while the CNN head doesn't budge. To the raw head, a shifted shape shares few lit pixels with the template it memorized. The CNN head doesn't care: the same kernels slide everywhere (weight sharing), so the diagonal evidence is still found — just at a new position — and two rounds of pooling forgave the displacement. That is the entire architectural bet of a CNN: vision features are local and position-independent, so scan for them with shared weights instead of memorizing where every pixel goes.

The economics follow: our conv layer costs 4 kernels × 9 weights = 36 parameters; a dense layer "watching" the same 16×16 input with 4×14×14 outputs would need 200k+. Real CNNs stack these stages — conv/ReLU/pool, then conv on the feature maps of the previous layer — so layer 2 builds corners out of edges, layer 3 builds parts out of corners. That hierarchy is why transfer learning works: a net trained on a million photos has already learned universal early layers; you keep them and retrain only the head — exactly what your car-damage capstone does with YOLOv8.

⚠️ Traps: convolution is linear — ReLU after it is what makes depth meaningful · pooling has no learnable parameters and halves spatial dims — it reduces computation and adds shift tolerance, but "loses precise position" is by design · the CNN's kernels here are fixed for clarity; in a real CNN backprop learns them (first layers rediscover edge detectors) · a CNN isn't "better at everything" — it encodes an image assumption (local, translatable patterns); on tabular data that assumption is false and trees win (Phase 3).
Takeaways: pipeline = conv (find patterns) → ReLU (keep positive evidence) → pool (summarize, shrink, forgive shifts) → head (decide) · feature map = "where my pattern is" · receptive field = the input patch a deep pixel watches · weight sharing = few params + translation tolerance — the reason CNNs conquered vision · transfer learning reuses the early layers. Next: sequences — LSTM / GRU.

Curated companion: poloclub — CNN Explainer — the same pipeline on a real 10-class photo CNN.