MAI5063 Advances in Deep Learning · Week 3 learning resource

Introduction to CNNs: the big picture

Intuition edition. Every idea comes with an everyday example and something to try, and the maths stays to adding and multiplying. Read it before the lecture or the lab, or come back when a layer name stops making sense.

Parts 9, one idea each Time about 30 min Maths minimal

The one-line version

A CNN is a stack of reusable pattern detectors. Each one looks through a small window, and together they build from edges to objects.

How to use this page

  • Each part has a small demo. Change something, then say what you expected.
  • The pictures are tiny on purpose, so you can follow every number.
  • The curves in Part 8 are illustrative shapes, not measured results.
  • Lab 3 runs the same ideas on real images in Colab.
Part 1 · The problem

Why not just flatten the picture?

Imagine cutting a photograph into thin strips and laying them end to end in one long line. Every pixel still has its number, but who was next to whom is gone. The eye of a cat is no longer near the nose.

A tiny picture and its flattened strip

Select a pixel. Its neighbours light up in both views.

Picture (8×8)
Flattened into one line of 64

Same face, different spot

Slide the face around the picture. A cat in the corner and a cat in the middle look like two unrelated puzzles to a flattened network.

The fix, in one line. Look at small neighbourhoods, and reuse what you learn everywhere. A fully connected network ignores that images have structure: nearby pixels belong together, and the same pattern can appear anywhere.
Part 2 · Window, stamp and match

Look through a small window, with one stamp

Reading a street sign, you do not look at the whole city at once. You scan with a small field of view and notice local patterns: a corner, a stripe, a curve. A CNN neuron does the same with a small patch, say 3×3 pixels. That is local connectivity.

A detective has a template for "vertical stripe". She does not make a new template for every part of the photo. She slides the same one across the whole picture. At each position, multiply the patch by the template and add up. The total says how well the patch matches.

Slide the template

Picture
Template
Picture
Template
Feature map (select a cell)

What the numbers say

  • A flat patch (all 2s): positives and negatives cancel, so the score is 0.
  • A patch straddling a bright-to-dark edge gives a big number, 6.
  • The grid of scores is a feature map: a heat map of "edge here".
  • No hand-made templates. The numbers inside the template are learned by training, not designed by a person.

One stamp, used everywhere

  • Weight sharing: one small set of numbers is reused at every position, so the network needs very few parameters.
  • Translation invariance: a stripe in the top-left or the bottom-right is found by the same detector.

Find the plus sign, wherever it is

Select any square to move the plus sign. The same 9-number stamp slides over the whole picture. Add a second copy and it finds both.

Picture (10×10)
Match score (8×8)

How many dials?

Giving every pixel its own dial is wasteful. A phone photo has about 150,000 numbers.

The bar compares the 3×3 stamp (27 dials for a colour picture) with the 224-pixel flattened neuron.

Part 3 · A team of specialists

Many detectors, many feature maps

One template finds one kind of pattern. A convolution layer uses a team of specialists in parallel: vertical edges, horizontal edges, a particular curve, a colour blob, a texture. Thirty-two filters give thirty-two feature maps stacked like a deck of transparent sheets, and each shows where its pattern appears.

Four specialists, one picture

Picture

Warm cells mean a strong match for that specialist. Grey cells mean the opposite pattern. A real layer runs 32 or more of these side by side.

Part 4 · Pace, frame and zoom

Walking pace, a frame, and zooming out

Stride is how big a step the window takes. Padding is a frame of blanks around the photo. Pooling is making a thumbnail. These three settings decide how big the output is and how much detail it keeps.

Stride and padding on one row

Stride
Padding

What each setting does

  • Stride 1 moves the window one pixel at a time and keeps a detailed output. Stride 2 jumps two, giving an output about half the size and faster.
  • No padding: the output shrinks, because the window cannot hang over the edge.
  • Padding "same": a border of zeros keeps the picture the same size.

A 6×6 picture with a 3×3 window gives 4×4 with no padding and stride 1, 6×6 with padding 1, and 2×2 with stride 2.

Pooling: keep the loudest signal

Select a square to raise its number by 1, up to 9. Each 2×2 block keeps only its largest value.

Before (4×4)
After max-pool (2×2)

Why a thumbnail helps

  • The picture gets smaller, so there is less memory and it runs faster.
  • It no longer matters whether the stripe moved by one pixel. That is mild tolerance to shifts.
  • Pooling has no learned numbers. It is a fixed rule.
Part 5 · The rhythm of a CNN

Detect, filter, summarise, then see more

Almost every CNN repeats one three-beat rhythm. Think of airport security: scan the bag (conv), flag anything suspicious and ignore the rest (ReLU), file a one-line report per area (pool). The next officer reads the reports, not the bag.

1 · DetectConv: slide the templates and score every position
2 · FilterReLU: keep the positive evidence, drop the negatives
3 · SummarisePool: shrink the map, keep the strongest

One round on a row of scores

Scores from the conv step
After ReLU (negatives become 0)
After max-pool, pairs (keep the strongest)

Why ReLU? Without a non-linear step the stacked layers would collapse into one big linear operation.

Seeing more as you go deeper

Reading: letters build words, words build sentences. CNNs build understanding the same way. Stack 3×3 layers and see how much of the picture one neuron covers.

Part 6 · The final vote

From features to an answer

After many rounds of detect, filter and summarise, the last feature maps are handed to a small committee that votes. Softmax turns the votes into probabilities that sum to 100%.

Turn votes into probabilities

Flatten, or boil each map down first

  • Flatten and vote: line up all the numbers and let dense layers weigh them.
  • Global average pooling: first boil each feature map to one number ("how much cat-ear evidence overall?"), then vote. Fewer dials, less memorising.

Counted for 8×8 feature maps feeding a dense layer of 128 units.

Part 7 · Staying steady

Dropout, BatchNorm and augmentation

Three habits keep a network steady and stop it memorising. Each has an everyday picture.

Dropout: practising with random absences

A football team that always trains with the same eleven becomes dependent on its star striker. Send a few random players home each session, and everyone learns to contribute.

Batch Normalization: same-size baton every hand-over

In a relay race, each runner receives a baton of unpredictable size and weight. Now suppose each hand-over re-weighs and re-balances the baton. BatchNorm re-centres and re-scales each layer's numbers using the current mini-batch.

Layer output before (batch of 8)
After BatchNorm

Usual order: Conv → BatchNorm → ReLU → Pool. At prediction time there is no mini-batch, so it uses the averages it collected during training. Two learned knobs let the network undo the rescaling if that helps.

Data augmentation: show the same cat in many poses

A child who has only seen a cat sitting to the left may not recognise one facing right. Show the same cat flipped, tilted and zoomed, and the lesson sticks. Here a letter F stands in for the cat.

Flip
Label: F. A rotated F is still an F.

The goal: teach the network what should change and what should stay the same. Augmentation is applied only while training, never to validation or test pictures.

Part 8 · Reading the chart

Read the training curves like a doctor's chart

Before you change anything, read the curves. The training loss shows how well the network fits what it has seen. The validation loss shows how it does on pictures it has not. The four shapes below cover most of what you will meet. These are illustrative curves.

training lossvalidation loss
Part 9 · Summary

The big picture, in seven lines

  • Flattening an image throws away who is next to whom. CNNs keep it.
  • A filter is a small template slid over the image. The scores form a feature map.
  • The same filter is reused everywhere (weight sharing), so it finds a pattern wherever it appears.
  • Stride sets the step size, padding protects the border, pooling zooms out.
  • Stacking Conv → ReLU → Pool grows what each neuron sees: edges, then parts, then objects.
  • Dropout, BatchNorm and augmentation keep the network steady and stop it memorising.
  • Read the training curves before changing anything.
If you remember one thing. A CNN is a stack of reusable pattern detectors, each looking through a small window, together building from edges to objects.

?Where else in daily life do you reuse one small tool across many places, and how would a CNN do the same?

Saved in this browser only.