Convolutional Networks (CNN)#
Neural networks consisting of fully-connected layers are not well suited for processing images. They treat the input as a one-dimensional vector (after flattening), which completely discards the spatial structure of the data. This approach also scales poorly with input size, as the number of parameters grows rapidly with the number of input features. More importantly, a fully-connected layer must learn similar visual patterns independently at every position.
Convolutional neural networks (ConvNets or CNNs) are designed for structured arrays such as images, audio spectrograms, and other grid-like signals. A convolution applies the same small, trainable filter across the input. This gives ConvNets two useful properties:
Local connectivity: early layers combine nearby values, making them well suited to detecting edges, corners, and textures.
Weight sharing: the same filter is reused at every location, so a learned pattern can be recognized wherever it appears.
Convolutional layers are often followed by pooling or strided operations that reduce the spatial resolution of the feature maps. This makes later representations less sensitive to small shifts in the input, although padding, boundaries, and downsampling prevent perfect invariance. As layers are stacked, each activation sees a progressively larger receptive field, allowing the network to combine local features into larger structures.
CNNs often use fewer parameters than a comparable fully-connected network, but that does not automatically prevent overfitting. Dataset size, model capacity, regularization, and the training procedure still matter. A typical classifier combines convolutional layers, downsampling, and a classification head; modern heads often use global pooling instead of a simple flattening operation.
In this chapter, we will build a small ConvNet to classify images of handwritten digits. We will also introduce data augmentation as a regularization technique to improve generalization. From a high-level perspective, the training and evaluation pipeline will be the same as for fully-connected networks. The main differences are in the model architecture and the data preprocessing.
