A convolutional neural network (CNN) is a type of deep learning model built for grid-shaped data, especially images. It slides small learned filters across the input to detect local patterns such as edges and textures, then combines them in deeper layers to recognise shapes, parts and whole objects. CNNs drove the breakthroughs in computer vision that started the modern deep learning era.
Key takeaways
- CNNs use convolution: the same small filter is reused across the whole image.
- This weight sharing makes them far more efficient than fully connected networks on images.
- Typical layers are convolution, activation, pooling and a final classification head.
- Famous CNNs include LeNet, AlexNet, VGG and ResNet.
- Vision transformers now compete with CNNs, but CNNs remain widely used, especially on devices.
A CNN explained in simple terms
Imagine checking a large photo for cracks using a small magnifying glass. You slide the glass across the photo, square by square, looking for the same thing everywhere. A CNN does this with many “magnifying glasses”, called filters. One filter looks for vertical edges, another for curves, another for a particular texture. Later layers look at the results of earlier ones, so they find bigger patterns: an eye, a wheel, a letter. At the end, the network decides what the whole image shows.
Why not use a regular neural network for images?
A small colour image of 224 × 224 pixels has 150,528 input values. Connect each to 1,000 neurons in a regular fully connected layer and you already need over 150 million weights, for one layer. It also ignores the fact that nearby pixels are related. CNNs fix both problems. A 3 × 3 filter on a colour image has just 27 weights plus a bias, and it is reused across every position. The network also becomes good at finding a pattern wherever it appears in the image.
The building blocks of a CNN
| Layer | What it does |
|---|---|
| Convolutional layer | Slides filters (kernels) across the input to produce feature maps showing where each pattern appears |
| Activation (usually ReLU) | Keeps positive responses and removes negative ones, adding non-linearity |
| Pooling layer | Shrinks feature maps, for example keeping the maximum value in each 2 × 2 block |
| Normalisation | Stabilises training, for example batch normalisation |
| Fully connected / head | Combines features to produce the final prediction |
| Softmax output | Turns scores into class probabilities |
Key settings include filter size (often 3 × 3), stride (how many pixels the filter moves each step) and padding (adding a border so edges are not lost). Output width = (input − filter + 2 × padding) ÷ stride + 1.
A worked example: detecting a vertical edge
Take a vertical-edge filter:
| −1 | 0 | +1 |
| −1 | 0 | +1 |
| −1 | 0 | +1 |
Place it over a 3 × 3 image patch where the left two columns are dark (0) and the right column is bright (10). Multiply matching cells and add: (−1×0 + 0×0 + 1×10) × 3 rows = 30. A strong response: there is an edge here.
Now place it over a patch that is bright everywhere (all 10s): (−10 + 0 + 10) × 3 = 0. No edge. Sliding the filter across the whole image gives a feature map that lights up wherever vertical edges appear. In a trained CNN, nobody designs these filters. The network learns hundreds of them from data, many far more complex than this one.
How a CNN builds understanding
- Early layers detect edges, colours and simple textures.
- Middle layers combine these into corners, curves and patterns.
- Deeper layers detect object parts such as eyes, wheels or letters.
- Final layers combine parts into whole-object decisions.
Each layer “sees” a larger area of the original image than the one before, known as a growing receptive field.
Famous CNN architectures
| Model | Year | Why it matters |
|---|---|---|
| LeNet | 1989–1998 | Yann LeCun’s networks read handwritten digits, including for cheque processing |
| AlexNet | 2012 | Sharply cut ImageNet error rates and launched the deep learning boom |
| VGG | 2014 | Showed that deep stacks of small 3 × 3 filters work well |
| GoogLeNet (Inception) | 2014 | Used parallel filter sizes efficiently |
| ResNet | 2015 | Skip connections allowed training networks over 100 layers deep |
| MobileNet / EfficientNet | 2017–2019 | Efficient designs for phones and edge devices |
CNNs vs vision transformers
Vision transformers (introduced in 2020) split images into patches and use attention instead of convolution. With very large datasets they can match or beat CNNs. CNNs still have advantages: they tend to need less data, run efficiently on phones and cameras, and are well understood. Many modern systems combine both ideas.
Beyond images
Convolution works on any data with a grid or sequence structure: 1D convolutions for audio and sensor signals, and 3D convolutions for video and medical scans such as CT and MRI.
Limitations
- Need large labelled image datasets, unless fine-tuning a pre-trained model.
- Can be fooled by small, deliberate pixel changes (adversarial examples).
- May rely on shortcuts, such as backgrounds or watermarks, instead of the object itself.
- Weaker at modelling long-range relationships across an image than attention-based models.
- Can overfit without data augmentation and regularization.
