Lesson 9: Convolutions and Feature Maps
A plain network treats a picture as a long list of pixels, with no idea which pixels sit next to each other. That wastes the most useful fact about images: nearby pixels belong together. A convolution is an operation that respects that fact. It slides a small grid of weights, called a filter or kernel, across the image, and at each position it computes a weighted sum of the pixels underneath. The result is a new grid, called a feature map, that records where a particular pattern appears.
A simple filter can detect a vertical edge. Imagine a filter that gives positive weights to the left column and negative weights to the right column: where the image is flat, the positive and negative parts cancel and the output is near zero; where the image jumps from dark to light, the filter fires strongly. Different filters detect horizontal edges, corners, or textures. Early in training, a network learns exactly such filters on its own — nobody has to design them by hand.
Sharing Weights Across the Image
The key efficiency of a convolution is weight sharing: the same small filter is used at every position in the image. A vertical-edge detector is useful everywhere, not just in one corner, so there is no need to learn a separate detector for each place. That keeps the number of weights small even for large images, and it gives the network a useful property called translation invariance — an edge is an edge wherever it appears, and the network will find it.
A convolutional layer usually learns many filters at once — 32 or 64 in a typical first layer — and each produces its own feature map. Stacked together, those maps form a small volume: the image, re-described as a set of answers to the questions "is there a vertical edge here?", "is there a corner here?", and so on. The next layer then convolves those maps again, combining simple features into more complex ones: edges into shapes, shapes into parts, parts into objects.
A Worked Example of the Arithmetic
Take a worked example: a 5 by 5 image and a 3 by 3 filter. The filter sits over the top-left 3 by 3 patch, multiplies each pixel by its matching weight, adds the nine products, and writes the result in the top-left cell of the feature map. It then slides one step right and repeats, until it has covered the image. With a stride of 1 and no padding, the output is 3 by 3 — the image shrinks by two in each direction, because the filter cannot hang over the edge. That shrinking is normal, and later lessons show how padding controls it.
Convolutions are the reason deep learning became so good at images. They use the structure of the picture instead of ignoring it, they share weights so they need far less data to train, and they build a hierarchy of features that mirrors how we understand vision: from edges, to shapes, to objects.
Filters the Network Learns
It is worth asking what filters a trained network actually learns, because the answer is both reassuring and strange. In the first layer, the filters look like the edge and colour detectors a person might design: vertical edges, horizontal edges, diagonal edges, blobs of colour. Researchers have visualised them, and they are remarkably consistent across different datasets and tasks — the visual world has edges, and any network that sees it will find them. Deeper in the network, the filters become harder to describe: combinations of edges and textures that do not have names in ordinary language, but which the network finds useful.
That strangeness is a feature, not a bug. The network is not obliged to use human concepts; it only needs features that help it predict. Sometimes those features are surprising — a network might distinguish two kinds of animal by the background rather than the animal, if the backgrounds differ between the classes. That is a warning as much as a curiosity: the features a network learns reflect the data it was given, including its shortcuts, and checking what the network actually relies on is part of evaluating it honestly.
A 3 by 3 filter sliding over an image
The filter fires strongly where its pattern appears, and weakly elsewhere — so the feature map shows where the pattern is.
Key Terms
- Convolution
- Sliding a small grid of weights across an image and computing a weighted sum at each position.
- Filter (kernel)
- The small grid of weights used in a convolution; each filter detects one kind of pattern.
- Feature map
- The grid produced by a convolution, showing where a filter's pattern appears.
- Weight sharing
- Using the same filter at every position, so one detector works across the whole image.
- Stride
- How many pixels the filter moves at each step; a larger stride shrinks the output faster.
- Translation invariance
- The property that a pattern is detected wherever it appears in the image.
Discussion Questions
- Why is it wasteful to learn a separate edge detector for every position in an image?
- A filter detects vertical edges. What would happen if you flipped its weights left-to-right?
- Convolutions build features in a hierarchy. What might the third or fourth layer of a network detect, if the first detects edges?
Practice Questions
- What does a convolution do at each position of an image?
- What is a feature map?
- A 5 by 5 image is convolved with a 3 by 3 filter, stride 1, no padding. How big is the output?
- What is weight sharing, and why does it help?
- Why do convolutional layers usually learn many filters at once?
Show answers
- It computes a weighted sum of the pixels under the filter, using the filter's weights. The result goes into the corresponding cell of the feature map.
- The grid produced by applying one filter across the whole image. Each cell says how strongly that filter's pattern appeared at that position.
- 3 by 3. The filter can sit in 3 positions across and 3 down, so the image shrinks by 2 in each direction.
- Using the same filter at every position. It keeps the number of weights small and means a pattern is detected wherever it appears.
- Because different filters detect different patterns — vertical edges, horizontal edges, corners, textures — and the network needs all of them. Each filter produces its own feature map.