Deep Learning Slides 📂 Introduction · 14 of 18 47 min read

CNN Fully Solved Numericals: Conv → ReLU → Pool

Two complete CNN forward-pass problems worked entirely by hand. Watch a 5×5 and a 4×4 image flow through convolution, ReLU, and max pooling — every dot product, every feature map, every output dimension computed step by step, then verified in Python. The exact numericals you'll be asked to solve.

CNN — Fully Solved Numericals

Two complete image-to-output problems, every dot product worked by hand. Watch a picture flow through convolution, ReLU, and pooling — the exact arithmetic a CNN runs, and the exam question you'll be asked to solve.
Conv → ReLU → Pool Feature Maps by Hand Output Dimensions Python-Verified

Press Next → or use ← → arrow keys

Section 01

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:

Inputimage Convfeature map ReLUmax(0,x) Pooldownsample
⚠️
Never reverse the order

Convolution extracts features, ReLU keeps only the positive activations, then pooling summarises. Pooling before ReLU or ReLU before convolution gives the wrong answer.

Section 01

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:

O = (N − F + 2P) / S + 1
N = input size · F = filter/window · P = padding · S = stride
NumericalConv (5×5 / 4×4, 3×3, s1)PoolFinal
N1⌊(5−3)/1⌋+1 = 3×32×2, s1 → ⌊(3−2)/1⌋+1 = 2×22×2
N2⌊(4−3)/1⌋+1 = 2×22×2, s2 → ⌊(2−2)/2⌋+1 = 1×11×1
📐
Knowing the shape first prevents mistakes

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.

Section 02 · Numerical 1

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.

Input 5×5 1 2 3 0 1 4 5 6 1 2 7 8 9 0 3 2 1 0 4 5 6 3 2 1 0
 1  0 −1
 1  0 −1
 1  0 −1
Left column positive, right column negative — it fires on left-to-right brightness changes.
🎯
Nine dot products to compute

The 3×3 kernel fits into the 5×5 image in 3×3 = 9 positions. Each gives one feature-map value.

Section 02 · Numerical 1

N1 · Step 1 — Convolution

Slide the kernel, multiply element-wise, sum. Two sample windows, then the full feature map:

A
Top-left [0,0]: (1−3) + (4−6) + (7−9) = −2 −2 −2 = −6
B
Position [0,1]: (2−0) + (5−1) + (8−0) = 2 + 4 + 8 = 14
Feature map 3×3 -6 14 12 -2 9 5 4 7 3
🔴
Red cells are negative

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.

Section 02 · Numerical 1

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:

After ReLU 3×3 0 14 12 0 9 5 4 7 3 Max pool → 2×2 14 14 9 9
1
ReLU: −6 → 0, −2 → 0; all others unchanged → [[0,14,12],[0,9,5],[4,7,3]]
2
Max pool (stride 1): windows give 14, 14, 9, 9 → final output [[14,14],[9,9]]
Section 03 · Numerical 2

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).

Input 4×4 2 4 1 3 5 8 2 6 1 3 7 4 0 2 5 9
 0 −1  0
−1  5 −1
 0 −1  0
A strong centre (+5) minus its neighbours — it amplifies the difference between a pixel and its surroundings.
🎯
Only four dot products

A 3×3 kernel on a 4×4 image fits in just 2×2 = 4 positions — a compact feature map.

Section 03 · Numerical 2

N2 · Step 1 — Convolution

The centre weight is 5, so each output leans heavily on its middle pixel:

A
[0,0]: −4 + (−5 + 40 − 2) + (−3) = −4 + 33 − 3 = 26
B
[0,1]: −1 + (−8 + 10 − 6) + (−7) = −1 − 4 − 7 = −12
Feature map 2×2 26 -12 -3 21
📊
Feature map = [[26, −12], [−3, 21]]

Two strong positive responses where the centre pixel stands out, and two negatives where it sits below its neighbours.

Section 03 · Numerical 2

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:

After ReLU 2×2 26 0 0 21 Max pool s2 → 1×1 26
1
ReLU: −12 → 0, −3 → 0 → [[26,0],[0,21]]
2
Max pool (2×2, stride 2): max(26, 0, 0, 21) → final output [[26]]
Section 04

Side-by-Side Summary

StageNumerical 1Numerical 2
Input5×5 image4×4 image
KernelVertical edge (3×3)Sharpen (3×3)
Conv output3×3 feature map2×2 feature map
Pool2×2, stride 1 (overlapping)2×2, stride 2 (non-overlapping)
Final2×2 → [[14,14],[9,9]]1×1 → [[26]]
🔑
Stride controls the shrink

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.

Section 05

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]]
Every hand-computed value confirmed

The code returns exactly [[14,14],[9,9]] for N1 and [[26]] for N2 — matching the tables cell for cell.

Section 06

5 Golden Rules for CNN Numericals

  The three-step sequence
1Compute output dimensions first with O = ⌊(N − F + 2P)/S⌋ + 1 — it's your checksum.
2Convolution = dot product: multiply element-wise, then sum all the products.
3ReLU is simple: negatives become 0, positives stay unchanged.
4Order is Conv → ReLU → Pool — never reverse it.
5Stride sets the compression: stride = pool size gives non-overlapping windows.
🚀
You can now solve any CNN forward pass by hand

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.