CNN — Fully Solved Numericals
Press Next → or use ← → arrow keys
The Full Pipeline — In Order
Every CNN block runs the same three steps, always in this sequence. Get the order right and the numbers follow:
Convolution extracts features, ReLU keeps only the positive activations, then pooling summarises. Pooling before ReLU or ReLU before convolution gives the wrong answer.
Step Zero — Compute the Output Sizes
Before touching a single number, work out how big each stage will be. Both conv and pool use the same formula:
| Numerical | Conv (5×5 / 4×4, 3×3, s1) | Pool | Final |
|---|---|---|---|
| N1 | ⌊(5−3)/1⌋+1 = 3×3 | 2×2, s1 → ⌊(3−2)/1⌋+1 = 2×2 | 2×2 |
| N2 | ⌊(4−3)/1⌋+1 = 2×2 | 2×2, s2 → ⌊(2−2)/2⌋+1 = 1×1 | 1×1 |
If your feature map doesn't come out 3×3 for N1 or 2×2 for N2, you've mis-slid the kernel. The formula is your checksum.
Numerical 1 — The Setup
A 5×5 image and a 3×3 vertical-edge detector. No padding, stride-1 convolution, then a 2×2 max pool with stride 1.
1 0 −1
1 0 −1
The 3×3 kernel fits into the 5×5 image in 3×3 = 9 positions. Each gives one feature-map value.
N1 · Step 1 — Convolution
Slide the kernel, multiply element-wise, sum. Two sample windows, then the full feature map:
The feature map is [[−6,14,12],[−2,9,5],[4,7,3]]. The two negative responses (−6, −2) are about to be erased by ReLU.
N1 · Steps 2 & 3 — ReLU then Max Pool
ReLU zeroes the negatives; then a 2×2 max pool (stride 1) slides over the 3×3 map, keeping the biggest value in each window:
Numerical 2 — A Sharpening Kernel
A 4×4 image and a 3×3 sharpening filter. No padding, stride-1 conv, then a 2×2 max pool with stride 2 (non-overlapping).
−1 5 −1
0 −1 0
A 3×3 kernel on a 4×4 image fits in just 2×2 = 4 positions — a compact feature map.
N2 · Step 1 — Convolution
The centre weight is 5, so each output leans heavily on its middle pixel:
Two strong positive responses where the centre pixel stands out, and two negatives where it sits below its neighbours.
N2 · Steps 2 & 3 — ReLU then Max Pool
ReLU clears the negatives; a single 2×2 stride-2 window then covers the whole map, collapsing it to one number:
Side-by-Side Summary
| Stage | Numerical 1 | Numerical 2 |
|---|---|---|
| Input | 5×5 image | 4×4 image |
| Kernel | Vertical edge (3×3) | Sharpen (3×3) |
| Conv output | 3×3 feature map | 2×2 feature map |
| Pool | 2×2, stride 1 (overlapping) | 2×2, stride 2 (non-overlapping) |
| Final | 2×2 → [[14,14],[9,9]] | 1×1 → [[26]] |
The same 2×2 pool gives a 2×2 output at stride 1 but a 1×1 at stride 2. Stride = window size means non-overlapping windows and maximum compression.
Python — Verify Both Pipelines
Three tiny functions reproduce every number above:
import numpy as np
def conv2d(x, k): # stride 1, no padding
Oh, Ow = x.shape[0]-2, x.shape[1]-2
out = np.zeros((Oh, Ow))
for i in range(Oh):
for j in range(Ow):
out[i,j] = np.sum(x[i:i+3, j:j+3] * k)
return out
def relu(x): return np.maximum(0, x)
def max_pool(x, pool=2, stride=2):
Oh = (x.shape[0]-pool)//stride + 1
Ow = (x.shape[1]-pool)//stride + 1
return np.array([[x[i*stride:i*stride+pool,
j*stride:j*stride+pool].max()
for j in range(Ow)] for i in range(Oh)])
# N1: conv → relu → pool(stride 1) = [[14,14],[9,9]]
# N2: conv → relu → pool(stride 2) = [[26]]
The code returns exactly [[14,14],[9,9]] for N1 and [[26]] for N2 — matching the tables cell for cell.
5 Golden Rules for CNN Numericals
Slide, multiply, sum; clip the negatives; pool the maxima. Scale those three moves across layers and channels and you have every convolutional network there is.