Answers · How models work
What does a convolution actually calculate at a single point in the image?
In shortIt multiplies each filter weight by the pixel beneath it, adds those products, and writes the single total at the matching position in the output.
At one position, a convolution multiplies each weight in the filter by the input value under it, adds those products, and writes that one number into the output at the same position. It is a dot product between the filter and one local patch, so the number measures how much that patch agrees with the filter's pattern. The result is one value, not a patch and not a new picture of the whole input.
Take the filter and the row . The first window starts at and reads : the product is . The window starting at reads : . The window starting at reads : . Each window used the same three weights; only the three values underneath changed.
| start | patch | products | response |
|---|---|---|---|
| 0 | 10, 10, 90 | -10, 0, 90 | 80 |
| 1 | 10, 90, 90 | -10, 0, 90 | 80 |
| 2 | 90, 90, 20 | -90, 0, 20 | -70 |
The blur guess
The natural guess is that the output is a blurred copy of the input, as if every filter averaged nearby pixels. A blur is a dot product too, but with weights that are all positive and sum to one: with weights on a flat patch the output is . Now use on the same flat patch: . The weights sum to , so flat regions vanish no matter how bright they are. The output cannot be a copy of brightness. It is the amount of agreement between the patch and the filter, which is why a change from dark to bright gives while a change in the other direction gives .
A two-dimensional window changes the number of sums, not the idea. A by filter has weights, lies over input values at a time, and produces one number from those products. The row index and the column index of the output say where the patch was, because the value stored there came from the input centred near that same row and column.
The output is a map
On the row above, the output is , one value for each valid window start. The first two values mark the places where the row rises from towards ; the third marks the place where it falls from to . That ordering is the point: the output has the same geography as the input. A layer that turned the whole row into a few numbers would have thrown the geography away, but a convolution writes each response at the place that caused it, so the result is a map of where the pattern occurred.
A dot product is large when two lists are large and point the same way, and near zero when they disagree. The filter is a list of weights, so it is a direction in the space of small patches. The response at a position asks how much of the patch beneath the window lies along that direction. That is why the same three weights can find an edge without knowing the word edge: the weights are the pattern, and the dot product measures resemblance to it.
The operation is also linear: double the row to and the first window gives , which is twice . Shift the input and the responses shift with it, unchanged in value. This is the precise sense in which all positions are treated alike, and it is what a connected layer lacks, since there every position has its own weights.
Where the reading changes
The formula assumes the patch exists. At an edge the indices run past the input, so something has to be chosen: pad the input, or drop the positions that do not fit. Stride changes the step between window starts, and dilation spaces out which input values the weights read, but neither changes the dot product itself. In a deeper layer the patch is no longer made of pixels but of earlier feature values, so the filter is matching a pattern in a feature map rather than a pattern in the picture. And if the weights are allowed to differ from position to position, the operation stops being a convolution and becomes a connected layer. The blur reading is only the special case where every weight is positive and the weights sum to one.
Worth keeping
- At one position a convolution is a dot product between the filter and the patch under it.
- The same weights slide to every position, so the output is a map of where the pattern matched, not a summary of the whole input.
- A blur is the special case where all weights are positive and sum to one; an edge filter has weights summing to zero and gives zero on flat patches.
Where this goes next
This question is one step of How a Filter Reads a Picture, a course that works through its subject from the beginning. The page that teaches this part of it is One Small Window, Moved Everywhere, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- What do you give up when you pool or downsample a feature map?You give up exact position: each block of the map becomes one number, so later layers see a coarser grid, gain reach, and lose the ability to say where a response came from.
- What does it mean to use stride 2 in a convolution?Using stride 2 keeps the filter the same but moves its window two positions at a time, so it produces about half as many outputs in each direction and about a quarter of the work in two dimensions.
- Why do CNNs use the same weights everywhere instead of learning a separate filter for each spot?They share one small filter across every position because a pattern such as an edge means the same thing wherever it appears; the huge cut in parameters is a consequence, not the main reason.
- Why does a convolution make the image smaller if you don't pad it?A convolution shrinks the image because the window must fit completely inside it, so the first and last few positions have no full window. Padding adds extra values at the border so those positions can be used.
- Why does the model get stuck repeating the same sentence over and over?The model is not stuck in a memory loop: once it has written a phrase, that phrase is in its context and makes writing it again more likely, so a decoder that always picks the top word cannot leave.
- Why does diffusion add Gaussian noise instead of any random corruption?Diffusion adds Gaussian noise because Gaussian errors combine exactly: each step keeps the spread fixed and gives a closed-form noisy picture at any later step, which makes the reverse step learnable.