6  Convolutional Neural Networks

Every image classifier we have built so far has ignored the spatial geometry of images, flattening a two-dimensional pixel grid into a one-dimensional vector. The MLP in Chapter 4 treats a \(28 \times 28\) Fashion-MNIST photo as an unordered list of 784 numbers: if we applied the same fixed random permutation to the pixels of every image and retrained, the MLP would reach the exact same accuracy—even though the scrambled images would look like pure static to human eyes. Humans recognize a sneaker by its outline and textures, which are patterns formed by neighboring pixels, and an outline carries the same meaning wherever in the frame it appears.

Neuroscience offered an early clue. In classic experiments on cats and monkeys, Hubel and Wiesel discovered that neurons in the early visual cortex respond to oriented edges and bars within localized patches of the visual field—each neuron’s receptive field (Hubel and Wiesel 1959, 1962, 1968). Later, Field (1987) modeled these responses on natural images using a small bank of local filters swept across every image location (Figure 6.1).

Figure 6.1: Six receptive-field filters and their responses to a natural image, adapted from Field (1987) . The left panel shows the filters, the middle panel the input image, and the right panel the filtered responses sampled at intervals proportional to each filter’s size. Different filters respond to different local edge patterns.

Inspired by these findings, Fukushima’s Neocognitron (Fukushima 1980) organized local detectors into hierarchical layers repeated across space, and LeCun and collaborators showed how to train such architectures end to end via backpropagation to recognize handwritten ZIP codes (LeCun et al. 1989, 1995). Deeper layers of trained vision networks even exhibit representational parallels with higher stages of the primate visual pathway (Kuzovkin et al. 2018), though biology served as architectural inspiration rather than a blueprint for silicon computation.

At the heart of these architectures lies the convolutional layer, which slides a small shared kernel of weights across every neighborhood of an image. Each output unit depends only on nearby pixels, and shifting the input simply shifts the output, building locality and translation equivariance directly into the network while slashing parameter counts by orders of magnitude. These convolutional neural networks (CNNs) drove the watershed breakthrough on ImageNet (Deng et al. 2009; Krizhevsky et al. 2012) and remain a cornerstone of computer vision alongside vision transformers (Chapter 11).

This chapter derives and builds CNNs from first principles in three steps. We begin by showing that enforcing locality and translation equivariance on a dense layer leaves convolution as the unique linear choice (Section 6.1), then implement two-dimensional cross-correlation, learn an edge-detecting kernel by gradient descent, recast convolution as matrix multiplication (im2col), and trace how stacked layers widen receptive fields (Section 6.2). Next, we control spatial resolution, field of view, and feature capacity through padding, stride, and dilation (Section 6.3), multi-channel filter banks and \(1 \times 1\) bottlenecks (Section 6.4), and local and global pooling (Section 6.5). Finally, we assemble these pieces into LeNet (Section 6.6), compare it against our MLP on Fashion-MNIST, inspect its learned first-layer filters, and retrain LeNet on pixel-shuffled images, which by symmetry leave the MLP’s accuracy unchanged, to isolate the contribution of spatial inductive bias. Modern deep convolutional architectures follow in Chapter 7.

Resources and Further Reading

The resources below accompany the sections of this chapter; each names the section it goes with. All are freely accessible online except where noted.

Books

Courses and video lectures

Tutorials, notes, and interactive

Foundational papers