A small filter, an entire image
Convolution, shared weights and the memory that still grows
Convolution reuses local filters across an image. Parameter count stays fixed while activation memory grows with image area.
A convolution layer builds two assumptions into an image model: nearby pixels belong together, and a useful local pattern may appear in many positions. Instead of learning a separate detector at every location, it moves the same learned filter across the image.
Prerequisites: Linear shapes and nonlinearity.
One filter, several positions
For an input row [1,2,4,3] and a filter [-1,1], stride 1 with no padding produces [1,2,-1]. Each output is the sum of products in one local window. We used the same two coefficients three times.
Deep-learning libraries commonly call this convolution even though the operation is cross-correlation: the kernel is not flipped.
In a two-dimensional layer the window has height and width. With RGB input, a filter spans all three input channels. It sums across both spatial positions and input channels, then adds a bias. Each output channel has its own learned filter.
Count parameters separately from outputs
Take one RGB image with shape [1,3,64,64] and:
With the default bias and groups=1:
| Quantity | Calculation | Result | |---|---|---:| | Parameters | 128 × 3 × 3 × 3 + 128 | 3,584 | | Output values | 1 × 128 × 64 × 64 | 524,288 | | FP32 output storage | 524,288 × 4 bytes | 2 MiB |
Those 3,584 parameters are reused across the image. The output still grows with image area and batch size. Double height and width to 128 and the parameters stay fixed while this output becomes 8 MiB.
That is only the output tensor: training, retained activations, gradients, optimizer state and temporary workspace need additional memory.
Moving the input is not the same as ignoring position
Convolution can be translation-equivariant: move a pattern and the response moves with it, subject to sampling and boundary conditions. Translation-invariant means the result stays the same. These are different claims.
Padding affects borders; stride can change how a shifted pattern lands on the sampling grid. Pooling or later aggregation may reduce sensitivity to location, but “a CNN ignores shifts” is too broad.
The architectural trade-off
Locality and shared weights can be valuable for images, but they are assumptions. A small kernel sees a small neighborhood; combining layers expands the receptive field. Choosing the architecture still depends on the task and data.
Check yourself
Change the kernel from 3×3 to 5×5 with 3 input and 128 output channels. With a bias there are 128×3×5×5+128 = 9,728 parameters. At stride 1, padding 2 preserves the spatial dimensions in this example. Compare the larger context and computation, not just the parameter count.