What a convolutional network is
An MLP treats a 28 × 28 digit as 784 unrelated numbers: its first layer gives every pixel its own weight into every unit, so a stroke learned at the top left has to be learned again at the bottom right. A convolutional network (CNN) builds in two facts about images instead. Nearby pixels belong together, so each unit looks at a small window; and a pattern means the same thing wherever it appears, so the same small set of weights, a kernel, is applied at every position.
The network on this page is LeNet-style: two convolution layers, each followed by a ReLU and a 2 × 2 max pool, then one dense layer that maps the last 16 maps to ten digit scores. It was trained here on MNIST with the MLP tab's exact images, batches, learning rate and seed, and reaches 97.9 % test accuracy with 6,582 parameters, against the MLP's 95.4 % with 52,650.
Convolution
Output channel at position is a weighted sum over a window of every input channel, plus a bias:
Deep-learning libraries compute this cross-correlation and call it convolution; flipping the kernel would make it a convolution in the signal-processing sense, and learning does not care which. Here . The first layer pads the image with 2 zeros on each side so its 6 maps stay 28 × 28; the second has no padding, so its 16 maps shrink from 14 × 14 to 10 × 10. In general a map of size with padding and stride gives outputs per side.
The One output pixel panel spells one of these sums out: the 5 × 5 window, times the kernel, plus the bias, equals the recorded value.
Weight sharing
Because one kernel is reused at every position, the first layer has only parameters. Written as an ordinary dense layer from 784 pixels to its 4,704 outputs, the same map would be a matrix of 3,687,936 entries, of which 107,736 are non-zero and only 150 distinct numbers repeat: the kernel weights, placed again at every shift. The MLP's first layer, 784 → 64, has 50,240 parameters.
Sharing makes a convolution translation-equivariant: shift the input and the feature map shifts with it (away from the borders). The network does not have to learn each stroke at each place, which is most of why it beats the MLP with an eighth of the parameters.
ReLU and max pooling
After each convolution a ReLU, , keeps the positive responses. A 2 × 2 max pool with stride 2 then keeps the largest of every four neighbours and halves each side: 28 → 14 and 10 → 5. The page marks which of the four cells won each window.
Pooling has no weights. In the backward pass the gradient goes only to the winning cell of each window and the other three get zero. Small shifts that keep the same winner leave the pooled map unchanged, so pooling adds a little tolerance to position on top of the equivariance of the convolution.
Receptive field
The receptive field of a unit is the patch of input pixels that can change it. Each layer with kernel and stride grows it by times the distance between neighbouring units of the layer below:
Starting from one pixel (, ) this network's units see 5 pixels square after the first convolution, 6 after the first pool, 14 after the second convolution and 16 after the second pool, so the dense layer reads 25 overlapping 16 × 16 views of the digit. The page draws each layer's real input gradient inside its window. Not every pixel of the window matters equally: Luo et al. found the gradient concentrated near the centre, an effective receptive field smaller than the theoretical one.
Learning a kernel
Training uses the same loss and optimiser as the MLP: cross-entropy on the ten scores and plain SGD with learning rate on batches of 64. Because a kernel weight is used at every position, its gradient adds up the contributions of all of them:
So the update of one kernel is itself a correlation, of the input with the gradient map. The One SGD update panel shows a real step on one first-layer kernel, split into each batch image's share. The kernels panel shows the learned kernels at each checkpoint, starting from random noise.
Where CNNs came from
Fukushima's Neocognitron (1980) already stacked layers of local feature detectors and pooling-like units, trained without gradients. LeCun and colleagues trained a convolutional network with backpropagation to read handwritten zip codes (1989) and refined it into LeNet-5 for cheque reading (1998), the design this tab follows. In 2012 AlexNet, a much deeper CNN trained on GPUs with ReLUs and dropout, won ImageNet by a wide margin and started the deep-learning era in vision. Going much deeper needed residual connections: see the ResNet tab.
Papers
- Gradient-based learning applied to document recognition LeNet-5: convolution, subsampling and a dense classifier trained end to end on handwritten digits, the network this tab follows.
- Backpropagation Applied to Handwritten Zip Code Recognition The first convolutional network trained end to end with backpropagation, on handwritten zip-code digits.
- Neocognitron: A self-organizing neural network model for a mechanism of pattern recognition unaffected by shift in position Layers of local feature detectors and position-tolerant pooling, the architecture CNNs grew from.
- Understanding the Effective Receptive Field in Deep Convolutional Neural Networks Shows that the input gradient inside a receptive field is roughly Gaussian and covers much less than the theoretical field.
- A guide to convolution arithmetic for deep learning Output sizes for every combination of kernel, padding and stride, with pictures; also transposed convolutions (see the GAN tab).
- Visualizing and Understanding Convolutional Networks What the kernels and feature maps of a trained CNN respond to, layer by layer.