The idea
A convolution layer slides a small learned kernel across the input, taking a dot product at each position — the same handful of weights, reused everywhere. (Frameworks actually compute cross-correlation, no kernel flip; nobody cares, the weights are learned.) For a kernel of size over input patch centered at :
With multi-channel input, each filter spans the full channel depth ( weights) and produces one output channel; filters stack into the output volume.
Two design commitments do all the work:
- Locality: each output looks at a small neighborhood, matching the statistics of images — meaningful structure is local before it is global.
- Weight sharing: one detector is applied at every position, giving translation equivariance for ideal unit-stride convolution away from boundaries. Padding, stride, pooling, and finite edges can break exact equivariance. Parameter count remains independent of image size.
The knobs: stride (step size; stride 2 halves resolution), padding (zeros around the border; preserves size at stride 1), and filter count . Output size per dimension:
Depth builds a hierarchy: edges → textures → parts → objects. Each layer's receptive field (input region influencing one activation) grows with depth, so late layers reason about large structures using features computed once, locally, by early layers. A standard modern trunk: repeated conv → BN → ReLU blocks, downsample by stride-2 convs a few times, global average pool, one linear classifier.
Worked example
A 1-D convolution you can do in your head. Input , kernel , stride 1, no padding. Output size: .
| Window | Dot product | Output |
|---|---|---|
This kernel is a difference detector — on a constant-slope ramp it reads a constant everywhere. Learned 2-D kernels in first layers are exactly this species: oriented edge and gradient detectors.
Parameter arithmetic that wins interviews. CIFAR-scale input , one conv layer: 16 filters of , stride 1, padding 2.
The output shape and parameter count are
A dense layer mapping the same 3,072 inputs to 16,384 outputs would need
a factor of roughly 41,000 more. Same input and output sizes, five orders of magnitude fewer parameters, with position-sharing built in.
Cheat sheet
Formulas
- Output size: ; same padding at stride 1: .
- Parameters: — independent of input resolution.
- FLOPs scale with output area: multiply-adds.
- Stacked 3x3 receptive fields: layers see square — 2 layers = 5x5 (18 params) vs one 5x5 (25); 3 layers = 7x7 (27) vs one 7x7 (49), plus extra ReLUs.
Components
- Max pool: downsample + local invariance, 0 params; largely replaced by stride-2 convs.
- Global average pool: kills the spatial dims before the classifier → any input size works, no giant flatten layer.
- 1x1 conv: channel mixing / bottlenecks; no spatial context.
- Residual blocks: identity shortcuts make 50-150 layer CNNs trainable (ResNet).
- BN + ReLU after each conv is the default trunk pattern.
Facts and gotchas
- Equivariant to translation, not to rotation or scale — augmentation covers those.
- Channels-out = number of filters; each filter always spans all input channels.
- Stride-2 layer halves H and W → area drops 4x; channel count typically doubles to compensate.
- Edges/textures (early layers) are generic → freeze them when transferring; object-level layers are dataset-specific → retrain those.