Convolutional neural networks
Weight sharing for images: convolutions, feature maps, pooling and deep vision architectures.
Animated explanation
The idea
A 224 × 224 colour image has 150,528 numbers. A fully connected layer of 1,000 units on it would need 150 million weights, and it would have to learn separately that a cat in the top-left is the same as a cat in the bottom-right.
A convolutional layer instead learns a few small filters (say 3 × 3) and slides each one across the whole image, computing a dot product at every position. The result is a feature map that lights up wherever the filter's pattern appears. Two ideas make this powerful: local connectivity (each output looks only at a small patch) and weight sharing (the same filter is used everywhere, so a learned edge detector works at every position). Stacking conv layers builds a hierarchy: edges → textures → parts → objects.
Channels, stride, padding, pooling
A conv layer takes input channels and learns filters, each of shape . Stride skips positions (downsampling); padding adds a border of zeros so the output keeps its size. Max pooling keeps the largest value in each 2×2 block, halving the resolution and adding a little tolerance to small shifts. The receptive field of a unit (the input region that affects it) grows with every layer.
Architectures in one paragraph
LeNet (1998) read digits; AlexNet (2012) won ImageNet with GPUs and ReLU; VGG showed that stacks of 3×3 convolutions work; ResNet (2015) added skip connections so 100+ layer networks train; modern vision mixes convolutions with attention. In practice you rarely train from scratch: transfer learning fine-tunes a network pretrained on millions of images.
The algorithm, step by step
- 1Input: an image tensor of shape (C, H, W), normalised.
- 2Conv layer: for each output channel, slide its kernel over every position; add a bias.
- 3Apply ReLU; optionally max-pool to reduce resolution.
- 4Repeat conv/ReLU/pool blocks, increasing channels as resolution falls.
- 5Global-average-pool, then a dense layer with softmax; train end-to-end with backpropagation.
The maths
2-D convolution (cross-correlation)
Output size
Parameters per layer
Residual block
Strengths and weaknesses
Strengths
- Far fewer parameters than dense layers (weight sharing)
- Built-in sense of locality and translation
- Pretrained models transfer to new tasks with little data
Weaknesses
- Needs a lot of data and compute to train from scratch
- Not inherently rotation- or scale-invariant
- Hard to interpret (saliency maps help)
Reach for it when…
Check your understanding
Lambdian Lab
Convolution and pooling in NumPy
Single-channel operations, as in a CNN layer (cross-correlation, no kernel flip).
- conv2d(img, kernel, stride=1, pad=0): zero padding, then valid cross-correlation.
- relu(x) and maxpool2d(x, size=2) (non-overlapping; drop leftover rows/columns).
- out_size(n, k, p, s) from the formula.
- conv_params(k, c_in, c_out) including biases.