Did you know? The same curved edge can appear at the top of a photograph, near the centre or in a corner. An image model would be inefficient if it had to learn a completely different detector for every possible location. One powerful solution is a convolutional neural network (CNN).
CNNs use small learned filters that move across an image to respond to local visual patterns. Several layers can combine those responses into representations useful for classifying pictures and supporting other computer-vision tasks.
Quick answer: pixels → local filters → feature maps → nonlinear transformations → additional layers → task output. During training, the filter weights can be adjusted using a loss and an optimiser. Recognising an object is still a prediction, not proof of what a real scene contains.
A CNN in 30 seconds
- Pixel: a numerical image sample representing brightness or colour.
- Convolutional filter or kernel: a small collection of weights applied to local image regions.
- Feature map: an array of responses produced by a filter across locations.
- Activation: a nonlinear transformation often applied after convolution.
- Pooling: an operation that summarises neighbouring responses in some network designs.
- Receptive field: the region of the input image that can influence a particular feature.
The phrase “convolutional neural network” describes a family of architectures, not one universal image recogniser. Different CNNs use different layer arrangements and may be designed for classification, detection, segmentation or other tasks.
Step 1: Represent a photograph as numbers
A photograph is a grid of pixels. A typical colour image can be described using red, green and blue channel values at each pixel location. An image that looks continuous to our eyes is therefore available to software as a collection of numerical samples.
Before processing, the application may resize or normalise the image. This matters: shrinking a detailed photo could make small lettering or a distant object difficult to recognise. A model’s input preparation should match its intended job.
In the official PyTorch classifier tutorial, for example, the CIFAR-10 images are 32 × 32 pixels with three colour channels. That small training set is useful for explaining a CNN, but a real project may need much richer visual conditions.
Step 2: Move one small filter across the picture
Imagine looking for a vertical edge. A small filter might compare bright and dark pixels on opposite sides of a tiny window. When it slides across a suitable boundary, its numerical response can become stronger.
Unlike a hand-built image detector, the weights in a trainable CNN are adjusted from training examples. Different filters may become useful for distinct textures, contrasts or patterns depending on the model and data.
The same filter weights are reused as the filter moves across positions. This is called weight sharing. It allows a CNN to search for a learned pattern in more than one location without learning an independent set of weights at every pixel.
Step 3: Try a tiny filter calculation
Here is a deliberately simplified numerical example. Imagine a two-by-two patch of a greyscale image with values [1, 2; 3, 4]. Choose a two-by-two filter with weights [1, 0; 0, −1].
Multiplying matching positions and adding gives 1 × 1 + 2 × 0 + 3 × 0 + 4 × (−1) = −3. That one number is a local response for one filter placement. Real convolutional layers often include more channels, biases and many locations.
If the filter shifts to a neighbouring patch, it performs a similar calculation using that patch’s pixel values. Repeating these local operations produces an array of responses called a feature map.
The exercise is about how the arithmetic works; the chosen numbers are not a measured CNN trained on photographs.
Step 4: Build feature maps and combine them
One learned filter may respond to a particular type of edge. Another may respond to a texture or a differently oriented pattern. Their outputs form different feature maps that later layers can combine.
After a convolution, many networks apply an activation such as ReLU, which returns zero for negative inputs and retains positive ones. This introduces nonlinearity that helps the network represent more complex relationships.
The network does not need a human to write a sentence saying “this unit detects bicycle wheels.” Its numerical features can be learned through optimisation and may not correspond neatly to one human-readable idea.
Step 5: Why do some CNNs pool neighbouring responses?
Pooling summarises information from a neighbourhood. Max pooling keeps the largest response in a local window, while average pooling computes a mean. These operations can reduce spatial dimensions and change the system’s sensitivity to small changes in location.
Consider four fictional feature values: 1, 5, 2 and 3. A max-pooling operation over that tiny region would return 5. An average pooling operation would return 2.75. Neither operation knows what object is present; it summarises numbers.
Not every modern CNN uses traditional pooling in the same way. Some employ strided convolutions or other downsampling approaches. Reducing resolution also loses spatial detail, so small-object or pixel-level tasks need careful design.
Step 6: What do stride and padding control?
Stride describes how far a filter moves from one placement to the next. A stride of one visits more overlapping locations than a stride of two, generally producing a denser feature map for the same input and filter.
Padding adds values around an image’s borders so a filter can be applied near the edges under the chosen configuration. Without suitable padding, repeated convolutions can reduce the spatial size rapidly and underrepresent border information.
These settings affect computational cost and how much spatial detail survives. A fast design is not automatically the best design for a small defect or fine printed text.
Step 7: Combine local patterns over larger areas
At an early stage, one output location is influenced by a small portion of the image. As multiple layers are stacked, later representations can incorporate information from progressively larger input regions—their receptive fields grow.
This helps explain how patterns can be combined. Local contrasts may contribute to contours; groups of contours may contribute to larger visual structures. It is a useful intuition, not a promise that every layer has a tidy human label.
The core idea: CNNs reuse local learned filters across an image, then combine increasingly contextual numerical features.
Step 8: Train the filters with examples
A supervised CNN classifier can be given example images and appropriate labels. It predicts class scores; the training process measures an error; backpropagation calculates gradients; and an optimiser updates the learnable weights.
This is how a CNN becomes different from a fixed, hand-designed edge filter. The network’s useful patterns come from the training objective and examples, not from a programmer manually naming every curve or texture.
Training quality matters. If every apple photograph has a white background and every orange has a blue one, the CNN might learn background shortcuts. Independent examples with varied lighting and surroundings are needed to see whether it learned the intended visual distinction.
CNN classification versus detection and segmentation
- Image classification: predict a label for a complete image, such as “contains a bicycle.”
- Object detection: identify selected objects and estimate their positions.
- Semantic segmentation: classify regions or pixels into meaningful categories.
- Image enhancement: use learned operations to restore or improve certain image properties.
A basic CNN classifier does not automatically return the position of every object. More elaborate architectures add components suited to bounding boxes, dense pixel predictions or other outputs.
For a simpler entry point, read How AI Recognises Objects in Photos. This chapter explains one important family of networks behind such tasks.
Are transformers replacing convolutional networks?
Transformers are also used in modern vision systems and can process image patches with attention mechanisms. CNNs remain an important design family, with useful inductive biases for local patterns and weight sharing.
The best model depends on the dataset, training budget, required output, latency and deployment hardware. Neither “CNN” nor “transformer” is a guarantee of accuracy. A fair comparison evaluates models on the same task under stated conditions.
The companion article How Transformers Use Attention to Read Context introduces another family of learned information-processing methods.
What can make a CNN’s prediction unreliable?
- Unrepresentative training images: the model learns backgrounds or lighting rather than the intended object.
- Blur and occlusion: key visual information is hidden or distorted.
- Scale and orientation: an object appears very different from the training examples.
- Small-object loss: resizing or downsampling removes necessary detail.
- Incorrect labels: training targets reward the wrong pattern.
- Test leakage: near-duplicate images exaggerate reported performance.
A CNN may be useful for computer vision without providing complete scene understanding, identity verification or proof of a person’s intentions. Those are separate claims requiring suitable evidence.
Try it: a filter experiment with graph paper
Draw a small black-and-white grid. Shade the left half dark and the right half light to create a vertical boundary. Move a little two-column window across it and ask where the difference between the left and right pixel values is strongest.
Now draw a horizontal boundary and compare. A filter designed to respond to vertical contrast may react differently from one designed for horizontal contrast. You are exploring why multiple filters can be useful.
This is a paper analogy, not a neural network training run. Real CNNs learn their filter weights through numerical optimisation across many examples.
Frequently asked questions
Is a CNN the same as a neural network?
A CNN is one kind of neural network. It uses convolutional operations that share weights across positions, often particularly well suited to spatial data.
Does every CNN need pooling?
No. Some architectures use pooling; others use strided convolutions or different downsampling methods.
Why use filters instead of connecting every pixel to every neuron?
Local filters and weight sharing can exploit spatial structure efficiently, using fewer independent parameters than a naive fully connected design for many image tasks.
Can CNNs work with sound?
Yes. Related convolutional architectures can process suitable audio or spectrogram representations, depending on the task.
Can a CNN prove what happened in a photograph?
No. It produces predictions from visible data and training. Source provenance and factual context still matter.
Your one-minute takeaway
- CNNs move learned filters across local image regions and build feature maps.
- Weight sharing, nonlinearities and layers let patterns be combined efficiently.
- Good results depend on representative images, careful training and independent evaluation.
Trusted learning and related chapters
- PyTorch: Training a Convolutional Image Classifier — a practical official example.
- TensorFlow: Convolutional Neural Networks Tutorial — CNN layers and image classification.
- Stanford CS231n: Convolutional Neural Networks — filters, dimensions and receptive fields.
- How Neural Networks Turn Numbers Into Predictions — weights and activations.
- How Gradient Descent Teaches AI From Errors — learning the filters.
- How AI Recognises Objects and Actions in Video — the temporal dimension.
- How AI Works: Complete Overview — the series learning hub.