Build intuition for convolutional networks
Stack learned filters and pooling to turn pixels into features, and work out each layer’s size.
- Describe how a CNN learns filters and builds features layer by layer
- Compute a convolution layer’s output size from padding and stride
- Apply max and average pooling
A convolutional neural network (CNN) stacks the convolution you already know - but its kernel weights are learned from labeled images instead of picked by hand. Each layer applies many kernels, producing a stack of feature maps (one per kernel).
Early layers tend to learn simple detectors - edges, color blobs, textures. Later layers combine them into parts (eyes, wheels) and then whole objects. These are useful intuitions rather than fixed rules: what each filter learns depends on the data and training.
How big is the output?
Three settings decide a convolution layer’s output size (from the CS231n notes):
- kernel size F (e.g. 3),
- padding P: zeros added around the border so the kernel can sit on edge pixels,
- stride S: how many pixels the kernel jumps each step.
For an input of width W: output = (W − F + 2P) / S + 1. A 32-wide input with a 3×3 kernel, padding 1 and stride 1 stays 32 wide; with stride 2 it shrinks to 16.
1def output_size(width, kernel, padding, stride):
2 return (width - kernel + 2 * padding) // stride + 1
3
4print(output_size(32, 3, 1, 1), output_size(32, 3, 1, 2), output_size(7, 3, 0, 1))32 16 5
Pooling
Pooling shrinks feature maps by summarizing small windows. Max pooling keeps the strongest response in each window (“was the pattern anywhere here?”); average pooling keeps the mean. Shrinking saves computation and makes the network less sensitive to a pattern moving by a pixel or two.
Try it
Up to 15 XPPooling explorer
Click cells in the pooled map to see which 2×2 window each came from. Compare max and average pooling: which one keeps the single strong 9? What happens to the size of the map?
max(1, 3, 4, 2) = 4
Key takeaways
A CNN stacks learned convolution filters; features grow from edges to parts to objects.
Output size =
(W − F + 2P) / S + 1; padding preserves size, stride shrinks it.Pooling summarizes windows (max or average) to shrink feature maps.
Lesson quiz
7 questions · pass with 5 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: apply computer vision with Python
Use small pixel arrays to explore vision concepts, run your code against sample images, and connect each result to the larger computer vision idea.
Pool a feature map
Read a JSON 2×2 list of numbers and print its maximum value. This toy max-pooling operation summarizes the strongest activation in the region.
- One strong activation
- All negative values
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Max-pool a whole feature map
Read a JSON feature map whose height and width are even. Apply 2×2 max pooling with stride 2 and print the result as a list of rows.
- 4×4 map
- 2×4 map
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…