CSC3104 Β· Module 2 of 9

Convolutional Neural Networks

Understand convolution, pooling & feature maps

~56 min to study properly

Why not a plain fully connected network? Flattening a 224Γ—224Γ—3 image gives 150,528 inputs. Connect that to just 1,000 neurons and you already have 150 million weights β€” slow, and it overfits.

Checkpoint Β· the examiner asks

Does max pooling have any learnable parameters? And what is the difference between translation equivariance and translation invariance?

In one minute

CNNs replace giant fully connected layers with small shared kernels: local connectivity plus parameter sharing gives translation equivariance and far fewer weights. Pooling downsamples with zero learnable parameters and adds a little invariance. Know the output-size formula floor((W βˆ’ K + 2P)/S) + 1 and the parameter count KΒ·KΒ·C_inΒ·C_out + C_out.

Traps examiners look for
  • Saying pooling has learnable weights β€” it has none.
  • Mixing up equivariance (output moves with input) and invariance (output doesn't change).
  • Forgetting the bias term (+C_out) or the input channels when counting conv parameters.
Read

Study notes

01Why not a fully connected network?

Flatten a 224 Γ— 224 Γ— 3 image and you have 150,528 inputs. A single dense layer to 1,000 neurons needs 150 million weights β€” slow, memory-hungry and a recipe for overfitting. Worse, it treats a pixel in the top-left corner as unrelated to its neighbour, and has to learn "cat ear" separately at every position.

Convolutional networks build in two assumptions (inductive biases) about images:

  • Local connectivity β€” each neuron looks at a small patch (its receptive field), because nearby pixels are related.
  • Parameter sharing β€” the same small kernel slides across the whole image, because a useful feature (an edge, an eye) is useful everywhere.

02Convolution arithmetic

Output size: O = ⌊(W βˆ’ K + 2P) / SβŒ‹ + 1 for input width W, kernel K, padding P, stride S.

  • "Same" convolution: K = 3, P = 1, S = 1 keeps the size (32 β†’ 32).
  • No padding shrinks by K βˆ’ 1 (32 β†’ 30 with K = 3).
  • Stride 2 roughly halves it (224 β†’ 112 with K = 3, P = 1).

Parameters: each of C_out filters has K Γ— K Γ— C_in weights plus one bias: (KΒ·KΒ·C_in + 1) Β· C_out. A 3 Γ— 3 conv from 64 to 128 channels has (9Β·64 + 1)Β·128 = 73,856 parameters β€” independent of the image size, thanks to sharing.

Compute (multiply-adds): O Γ— O Γ— K Γ— K Γ— C_in Γ— C_out β€” this does scale with image size, which is why resolution drives inference cost.

03Equivariance, invariance and pooling

  • Equivariance β€” shift the input and the output shifts the same way. Convolution is translation-equivariant: if the cat moves 10 px right, its feature-map activation moves right too.
  • Invariance β€” shift the input and the output doesn't change. A classifier's final "cat" score should be (approximately) invariant.

Max pooling (e.g. 2 Γ— 2, stride 2) keeps the largest value in each window. It halves height and width, has zero learnable parameters, and adds a little invariance to small shifts. Stacking conv + pooling, plus global average pooling at the end, moves the network from equivariant feature maps to an invariant prediction.

04The feature hierarchy and receptive fields

Each layer sees a larger region of the original image β€” its receptive field grows with depth (two stacked 3 Γ— 3 convs see 5 Γ— 5; three see 7 Γ— 7, with fewer parameters than one 7 Γ— 7). So features build up:

  • early layers: edges, colours, simple textures;
  • middle layers: patterns, corners, motifs;
  • deep layers: object parts (eyes, wheels) and whole objects.

That's why early layers transfer well between tasks (module 4) and why visualising feature maps is a useful debugging tool. Modern CNNs (ResNets) add skip connections so very deep stacks still train, and batch normalisation to stabilise activations.

Watch it done

Worked examples

Worked example 1

Shapes through a small network

Input 64 Γ— 64 Γ— 3 β†’ conv 3Γ—3, 32 filters, P=1, S=1 β†’ max-pool 2Γ—2 β†’ conv 3Γ—3, 64 filters, P=0, S=1. Give each output shape and the parameters of both convs.

    Worked example 2

    Dense vs conv parameter count

    Compare a dense layer from a flattened 32 Γ— 32 Γ— 3 input to 64 units with a 3Γ—3 conv layer from 3 to 64 channels.

      Vocabulary

      Key terms

      CNNs fought back: ConvNeXt

      In 2022, Meta's ConvNeXt modernised a plain ResNet with transformer-era tricks β€” 7Γ—7 depthwise convolutions, LayerNorm, GELU, fewer activations β€” and matched Swin Transformers on ImageNet without any self-attention. ConvNeXt V2 (2023) added masked-autoencoder pretraining.

      Practise

      Quick check

      0 of 8 correct so far. Wrong answers come with an explanation β€” and the buddy can unpack them.

      Q1A conv layer: 3Γ—3 kernel, 64 input channels, 128 output channels, with bias. How many parameters?

      Q2Input 64Γ—64, kernel 5, padding 0, stride 1. Output size?

      Q3W = 128, K = 5, P = 2, S = 2. Output width?

      Q4Parameters in a 3Γ—3 conv from 16 to 32 channels (with bias)?

      Q5Max pooling has how many learnable parameters?

      Q6Convolution is translation-…

      Q7Two stacked 3Γ—3 convs have the same receptive field as one…

      Q8Which part of a CNN cost grows with image resolution?

      Exam-style

      Written practice

      Short answer5 marks

      Explain the two inductive biases of CNNs and why they suit images.

      Short answer5 marks

      Does max pooling have learnable parameters? Distinguish equivariance from invariance.

      Long answer12 marks

      Design a small CNN for 32 Γ— 32 Γ— 3 images with 10 classes. Give each layer's output shape and parameter count, the total parameter count, and explain how the design moves from equivariant features to an invariant prediction.

      Watch

      Videos

      Fresh picks are chosen by AI every day.
      Hands-on

      Convolution arithmetic

      4 guided tasks: predict, experiment, explain β€” then challenge yourself. Plus 2 coding exercises you run right in the browser.

      Start the lab