Intermediate level · Module 2: Convolutional Neural Networks · Lesson 1 of 3
Inside a Convolutional Neural Network
Learners connect the hand-made filters of the Beginner level to learned convolution layers and trace how shapes change through a small CNN.
In this lesson you will
- Describe convolution, pooling and fully connected layers
- Compute output shapes through a network
Key concepts
learned kernelschannels (feature maps)stride and paddingmax poolingreceptive field
The lesson
A convolution layer learns many kernels at once. Conv2d(3, 16, kernel_size=3, padding=1) takes a 3-channel image and produces 16 feature maps, each from its own learned 3×3×3 kernel. Early layers learn edges and colours; deeper layers combine them into textures and parts.
Output size = (input + 2 × padding − kernel) / stride + 1. Max pooling with a 2×2 window halves height and width, which reduces computation and makes features less sensitive to small shifts. Each layer sees a larger region of the original image, its receptive field.
After several convolution and pooling blocks, the feature maps are flattened (or globally averaged) and passed to fully connected layers that output one score per class.
Step by step
- Study the CNN architecture diagram and name each block.
- Compute the output shape after each layer for a 64 × 64 × 3 input.
- Check your calculation by passing a random tensor through the PyTorch model.
- Count the model's parameters with sum(p.numel() for p in model.parameters()).
A small CNN for classifying produce photos
How a 64×64 colour image becomes four class scores through convolution, pooling and a classifier head.
Convolution + ReLU
Sixteen learned 3×3 filters with padding 1 keep the 64×64 size and produce 16 feature maps; later, 32 filters combine them into richer patterns.
Max pooling
Each 2×2 pooling halves height and width (64 → 32 → 16), cutting computation and making features less sensitive to small shifts.
Global average pooling
Averages each of the 32 final feature maps into one number, giving a 32-value vector whatever the input size.
Classifier head
A fully connected layer turns the 32 values into four class scores; softmax converts them into probabilities.
Why it matters
Parameters: the first convolution has 16 × (3×3×3) + 16 = 448; the second has 32 × (3×3×16) + 32 = 4,640; the classifier has 32 × 4 + 4 = 132, so 5,220 in total. This is small enough to train on a laptop CPU.
Practice activity
Calculate and verify layer-by-layer shapes and parameter counts for a small CNN.
Expected result: Correct shapes and parameter counts confirmed in code.
Check your understanding
-
What is the output height of a 64-pixel input through a 3×3 convolution with padding 1 and stride 1?
Show answer
64.
-
What does 2×2 max pooling do to a 32 × 32 feature map?
Show answer
It reduces it to 16 × 16.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.