Guide

A convolution slides a small filter, called a kernel, across the input. At each position it takes a weighted sum of the values underneath, and writes that sum to an output map. The weights are learned, and the same weights are reused at every position. That reuse is what makes convolution efficient for images.

A one-dimensional trace

Start with a 1D signal x = [1, 2, 3, 4, 5] and a kernel w = [1, 0, −1]. At each step, the kernel multiplies three neighbors and adds them up:

y[0] = 1·1 + 0·2 + (−1)·3 = −2
y[1] = 1·2 + 0·3 + (−1)·4 = −2
y[2] = 1·3 + 0·4 + (−1)·5 = −2

The output is [−2, −2, −2]. A signal that rises by 1 at every step gives a constant output, because the kernel measures the change across three neighbors. The output is shorter than the input, because the kernel needs three values at each position.

Two dimensions and channels

Images use a k_H × k_W kernel, often 3 × 3. An RGB image has three input channels, so each kernel has a depth of 3. The products are summed across the depth and across the window, giving one value per output channel at each position.

A 3 × 3 kernel on an RGB image holds 3 · 3 · 3 = 27 weights per output channel. A fully connected layer on the same image would need one weight per pixel for each output.

Why the reuse matters

Concept

Parameter sharing means the same kernel is applied at every spatial position. The layer's size depends on the kernel and the number of channels, not on the image size.

Because the same filter looks at every position, a feature found in one place is found in every place. Shift the input by a few pixels, and the feature map shifts by the same amount. This is translation equivariance. A dense layer has no such built-in structure, so it must learn each position separately.

Common mistakes

  • Expecting the output to match the input size. Without padding, a convolution shrinks the grid. The next page covers padding and stride.
  • Counting weights per pixel. Weights are shared across positions. A 3 × 3 kernel does not have one weight per pixel.
  • Forgetting the bias. Each output channel usually has one bias term, added after the sum.

Check yourself

  1. For x = [5, 4, 3, 2, 1] and w = [1, 0, −1], what is the output? [2, 2, 2], because each step gives 5 − 3, 4 − 2, 3 − 1.
  2. How many weights does a 3 × 3 kernel over an RGB image hold, per output channel? 3 · 3 · 3 = 27.

Key takeaways

  • A convolution takes a weighted sum over a small window, then slides the window.
  • Weights are shared across positions, so the layer stays small.
  • Shifting the input shifts the feature map, which is translation equivariance.
  • Each output channel has its own kernel that spans all input channels.

Further learning

The next page covers how kernel size, stride and padding set the output size: output shapes and parameter counts.