A photo has millions of numbers. Convolutions let a network find patterns anywhere in it with only a handful of weights.
4 minute read
In short
A convolution slides a small learned filter across the image, reusing the same weights everywhere.
Weight sharing makes CNNs far smaller than fully connected layers and detects patterns anywhere.
Early filters find edges; deeper layers combine them into parts and objects.
In plain words
A convolution slides a small grid of weights, called a filter or kernel, across the image. At each position it multiplies the filter with the patch underneath and adds the results into one number. The same filter is reused at every position, so it detects the same pattern, like an edge, wherever it appears.
Worked example: finding a vertical edge
A tiny 4 × 6 greyscale image: dark (0) on the left, bright (9) on the right. Every row is 0, 0, 0, 9, 9, 9. The filter has −1 in its left column, 0 in the middle and +1 on the right, so it responds to dark-to-bright changes.
1
Slide the 3 × 3 filter across
A 4 × 6 image gives a 2 × 4 output when the filter stays fully inside.
2
Over the flat dark area
Every value is 0.
(−1 × 0 + 1 × 0) × 3 rows = 0
3
Over the edge
Left column dark, right column bright.
(−1 × 0 + 1 × 9) × 3 rows = 27
4
The output
Large values exactly where the edge is, zero elsewhere.
[0, 27, 27, 0]
[0, 27, 27, 0]
In a real network nobody designs the filters. They're learned by backpropagation like any other weights. Early layers end up detecting edges and colours, middle layers textures and parts, and later layers whole objects.
Why not a normal layer?
layer on a 32 × 32 colour image
weights
Fully connected, 100 outputs
307,300
Convolution, 16 filters of 3 × 3 × 3
448
Sharing one small filter across the whole image cuts the weights by about 700 times here, and builds in a useful assumption: a pattern means the same thing wherever it appears. Pooling layers then shrink the maps, so later layers see larger areas.
Your turn
Why does a convolutional layer need far fewer weights than a fully connected one on the same image?
What to remember
CNNs dominated computer vision for a decade and are still common on phones and edge devices. Vision transformers, from the Transformers module, now match or beat them with enough data, by cutting images into patches and using attention. Many modern systems mix both ideas.
Common mistakes
Forgetting that the output shrinks unless you pad the image.
Thinking filters are designed by hand; in a CNN they're learned.
Counting parameters per pixel; a filter's weights don't depend on image size.
Check yourself
Answer in your own words, out loud or on paper, before you open the model answer.
How does a convolutional layer work?
A convolutional layer has a set of small filters, for example 3 by 3 across all colour channels. Each filter slides across the image; at every position it multiplies its weights with the patch underneath and sums them into one value, producing a feature map that shows where the filter's pattern appears. Because the same weights are reused at every position, the layer has very few parameters and recognises a pattern anywhere in the image. The filters are learned with backpropagation. Stacking layers, often with pooling to shrink the maps, lets early layers find edges and later layers combine them into textures, parts and whole objects.
More to think about
Why do CNNs use far fewer parameters than fully connected networks on images?