Lesson 10: Convolutional Networks for Images
A convolutional neural network, or CNN, stacks convolutional layers, pooling layers and ordinary fully connected layers into one architecture. The convolutional layers learn the visual features, the pooling layers shrink the feature maps so the network can look at larger patterns, and the final fully connected layers turn the features into a decision — which class this image belongs to. It is the same layered idea as before, but with layers designed for pictures.
The architecture builds a hierarchy. The first convolutional layer learns simple filters: edges at different angles, patches of colour, simple textures. The second layer combines those into shapes: corners, circles, curves. Deeper layers combine shapes into parts: an eye, a wheel, a window. By the final layers, a single neuron can respond to something as specific as a dog's face — not because anyone programmed a dog-face detector, but because the hierarchy built up to it, layer by layer, from training examples.
Pooling: Shrinking with Purpose
Between convolutional layers sit pooling layers. Max pooling looks at a small window — usually 2 by 2 — and keeps only the largest value. This halves the size of the feature map, which makes the next layers cheaper and lets them see larger regions of the image at once. It also adds a little robustness: if an edge shifts by one pixel, the maximum in its window is often unchanged, so the network's answer does not wobble with tiny movements.
Pooling throws information away, and that is a deliberate trade. Exact positions matter less as you go deeper; what matters is which features are present, roughly where. By the end of the convolutional stack, the feature maps are small but rich, and the network flattens them into a list of numbers for the final classification layers. That flattening is where the picture stops being a picture and becomes a feature vector — the network's summary of what it saw.
Training a CNN in Practice
Training a CNN follows the same loop as any network: forward pass, loss, backward pass, update. A few practical points matter more for images. First, scale the pixel values, usually to the range 0 to 1, so the numbers the network sees are well behaved. Second, augment the data: flip images left to right, shift them a few pixels, or rotate them slightly, so the network sees each picture in many forms and cannot memorise exact pixel positions. Third, start with a proven architecture and small images, get that working, and only then scale up. A CNN that classifies small images well is a better starting point than a large one that never trains.
CNNs remain the workhorse for image tasks, from medical scans to satellite photos. The same hierarchy — edges, shapes, parts, objects — appears in every trained image network, which is a good sign that the architecture matches the structure of vision itself.
What CNNs Cannot Do
CNNs are powerful, but their strengths come with blind spots worth knowing. A CNN is good at recognising what is in a picture, but poor at reasoning about it: it can tell you there is a chair in the room, but not whether the chair is upside down, or whether it could hold a person's weight. It is also easily fooled in ways people are not: a small pattern of noise, invisible to a person, can make a CNN confidently misclassify an image, and a picture of a school bus on its side may be classified as something else entirely. These failures remind us that the network is matching patterns, not understanding the scene.
The practical consequence is that CNNs belong in systems where their limits are managed: a human checks the important cases, the input is controlled, and the model's confidence is treated with suspicion. A medical scan classifier that flags cases for a doctor to review is a good use; one that replaces the doctor is not, at least not on the strength of accuracy alone. Knowing what a tool cannot do is as much a part of learning it as knowing what it can.
Key Terms
- CNN
- Convolutional neural network: a network built from convolutional and pooling layers, designed for images.
- Pooling
- Shrinking a feature map, usually by keeping the maximum value in each small window.
- Max pooling
- Pooling that keeps the largest value in each window, typically 2 by 2.
- Feature hierarchy
- The build-up of features from simple edges to complex objects across the layers.
- Flattening
- Turning the final feature maps into a single list of numbers for the classification layers.
- Data augmentation
- Creating extra training examples by flipping, shifting or rotating the images you have.
- Feature vector
- The list of numbers summarising what the network detected in an image.
Discussion Questions
- Pooling throws away exact positions. When might exact position matter so much that pooling would hurt?
- Why does data augmentation reduce overfitting? What is it teaching the network not to rely on?
- If a deeper layer's neuron responds to a dog's face, what must the layers below it have learned?
Practice Questions
- What are the three kinds of layers in a typical CNN, in order?
- What does max pooling with a 2 by 2 window do to a feature map?
- Why should pixel values be scaled to 0 to 1 before training?
- Give two examples of data augmentation for images.
- What does the feature hierarchy mean in a CNN?
Show answers
- Convolutional layers, pooling layers, then fully connected layers. The convolutional layers find features, pooling shrinks the maps, and the fully connected layers decide the class.
- It halves its size in each direction, keeping only the largest value in each 2 by 2 window. A 28 by 28 map becomes 14 by 14.
- So the numbers the network sees are small and well behaved, which keeps training stable. Raw values up to 255 would make the gradients and updates much larger and harder to control.
- Flipping an image left to right, and shifting or rotating it slightly. Each creates a new training example that shows the same object in a different form.
- Early layers detect simple features like edges, middle layers combine them into shapes and parts, and deep layers detect whole objects. The meaning builds up layer by layer.