Feature maps
Calculate a convolutional output and explain filters, stride, padding, pooling and residual connections.
THE IDEA
Feature maps and how far each value can see
The output of a convolution layer is a feature map: how strongly the learned pattern was found at each position. Stack layers and the second layer looks at the first layer's maps, so each of its values depends on a bigger patch of the original image. That patch is its receptive field.
| layer | kernel | stride | receptive field |
|---|---|---|---|
| 1 | 3 |
Three 3×3 stride-1 layers see a 7×7 patch, yet need only 3·9 = 27 weights per channel pair instead of 49 for one 7×7 kernel.
Predict first. A feature map has a very large value somewhere. Does that prove a human-recognisable concept (say, an eye) was detected?
Chapter context
A convolutional layer reuses a local filter across positions. Weight sharing encodes a structural assumption about repeated local patterns while greatly reducing parameters compared with a fully connected map over all pixels.
TRY IT YOURSELF
Part 1. Do it hands-on
Compute a receptive field, then build a stack with a big field using strides. The Python part computes receptive fields and feature map sizes for any stack.
| layer | kernel | stride | receptive field |
|---|---|---|---|
| 1 | 3 |
- To do: Three 3×3 stride-1 convolutions in a row: how wide a patch of the input does one output value depend on? Type the width
- To do: Build a stack of at most 3 layers whose receptive field is at least 15, using strides
Part 2. Do it in code
- receptive_field(layers): layers is a list of (kernel, stride) pairs, first layer first. Return how many input positions one output of the last layer depends on, using rf = 1, jump = 1; for each layer: rf += (k - 1) * jump; jump *= stride. An empty list gives 1.
- feature_map_sizes(n, layers): layers is a list of (kernel, stride, padding). Return the list of spatial sizes after each layer, starting with n for the input, using the output-size formula. Raise ValueError if a layer does not fit.
Stuck, or something not working? You can come back to it any time.
CHECK YOUR UNDERSTANDING
Does a large activation prove a human-interpretable concept was detected?
Chapter reference: math, worked example & code
This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.
Math and notation
For one spatial dimension, output size is
Here n is input size, k kernel size, p padding, d dilation and s stride. Cross-correlation is . A residual block has form when shapes agree.
Worked example
For input [1,2,3,4] and kernel [1,−1], stride-one valid cross-correlation returns [−1,−1,−1]. Separately, n=7,k=3,p=1,s=2,d=1 gives floor((7+2−2−1)/2)+1=4 output positions.
Reference code
The following example uses the Python standard library and does not call a remote service.
x,w = [1,2,3,4],[1,-1]
y = [sum(x[t+i]*w[i] for i in range(len(w))) for t in range(len(x)-len(w)+1)]
assert y == [-1,-1,-1]
n,k,p,s,d = 7,3,1,2,1
assert (n+2*p-d*(k-1)-1)//s+1 == 4
Python examples are provided for study and local execution; this page does not execute Python.
Common mistakes
Padding does not reveal missing real pixels. Kernel flipping conventions change calculations. A residual shortcut needs a defined shape-compatible path.