Repository navigation
Module 11
⬅️ Module 10 · 🗺️ Curriculum · 🏠 Home · Module 12 ➡️
Level: Intermediate · Prerequisites: Modules 01, 07, 09 · Time: about 9–10 hours
On this page: Overview and learning goals · Beginner: the big picture · Core concepts and derivations · Worked example · Implementation · Advanced topics · Pitfalls and best practices · Conceptual questions and answers · Sources and further reading
Images, audio and video have local structure and translation regularities: an edge is an edge wherever it appears. Convolutional neural networks (CNNs) build these two assumptions — locality and weight sharing — into the architecture, using far fewer parameters than fully connected layers and generalising better on grid-structured data.
After this module you should be able to:
- compute convolution output sizes, parameter counts and receptive fields;
- explain padding, stride, dilation, pooling and channels;
- derive convolution gradients and explain equivariance;
- describe the main CNN families and efficiency tricks (depthwise separable convolution).
Instead of connecting every pixel to every neuron, a CNN slides a small filter (e.g.

Figure 11.1 — A synthetic image filtered with Sobel kernels: figures/make_figs_2.py).
flowchart LR
I["Image 3x224x224"] --> C1["Conv + BN + ReLU"] --> P1["Pool"] --> C2["Conv + BN + ReLU"] --> P2["Pool"] --> GAP["Global average pool"] --> FC["Linear classifier"] --> S["Softmax"]
A
Input
(Deep-learning "convolution" is technically cross-correlation, without kernel flipping; it makes no difference for learned filters.) Parameters:
1D slides along time (audio, text, sensors), 2D along height and width (images), 3D along depth/time (volumetric medical scans, video). Same maths with more indices.
For input size
"Same" padding (
The receptive field
Max pooling keeps the strongest response in each window (local translation invariance); average pooling smooths; global average pooling collapses each channel to one number, replacing large dense heads. Strided convolutions can learn the downsampling instead.
After feature extraction: global average pool → linear → softmax (modern), or flatten → dense layers (AlexNet/VGG). Detection and segmentation heads keep spatial maps.
With upstream gradient
Shifting the input shifts the feature map:
| Model | Key idea |
|---|---|
| LeNet-5 (1998) | conv–pool–dense; digit recognition |
| AlexNet (2012) | ReLU, dropout, GPUs, large-scale ImageNet |
| VGG (2014) | stacks of |
| Inception/GoogLeNet | multi-scale parallel branches, |
| ResNet (2015) | residual connections, 50–152 layers |
| DenseNet (2017) | concatenate all earlier feature maps |
| EfficientNet (2019) | compound scaling of depth/width/resolution |
| MobileNet / ShuffleNet | depthwise separable convs, channel shuffle |
| ConvNeXt (2022) | ResNet modernised with Transformer-era design choices |
Depthwise separable convolution factorises a conv into a per-channel spatial filter (
1D CNNs process sensor/audio sequences; 3D CNNs video and CT volumes. Benchmarks: MNIST (digits), CIFAR-10/100 (tiny images), ImageNet (1000-class classification), COCO and PASCAL VOC (detection/segmentation).
A
Parameters:
import numpy as np
def conv2d(x, K, stride=1, pad=0): # x: (C,H,W), K: (O,C,k,k)
x = np.pad(x, ((0, 0), (pad, pad), (pad, pad)))
O, C, k, _ = K.shape; H = (x.shape[1] - k) // stride + 1; W = (x.shape[2] - k) // stride + 1
y = np.zeros((O, H, W))
for i in range(H):
for j in range(W):
patch = x[:, i*stride:i*stride+k, j*stride:j*stride+k]
y[:, i, j] = np.tensordot(K, patch, axes=([1, 2, 3], [0, 1, 2]))
return y
x = np.arange(1, 10, dtype=float).reshape(1, 3, 3)
K = np.array([[[[1, 0, -1]] * 3]], dtype=float) # shape (1,1,3,3)
print(conv2d(x, K)) # [[[-6.]]]import torch.nn as nn
block = nn.Sequential(nn.Conv2d(3, 64, 3, padding=1, bias=False), nn.BatchNorm2d(64), nn.ReLU(),
nn.MaxPool2d(2), nn.AdaptiveAvgPool2d(1), nn.Flatten(), nn.Linear(64, 10))- Dilated/atrous convs and feature pyramids for dense prediction; U-Net skip connections (reused in diffusion, Module 20).
- Anti-aliased downsampling restores shift stability; group/steerable convs add rotation equivariance.
- Convolution as matrix multiplication (im2col, Winograd, FFT) is how hardware executes it.
- Vision Transformers replace local filters with global attention; hybrid and ConvNeXt-style models show convolution remains competitive.
- Receptive-field–aware design, NAS (EfficientNet), pruning/quantisation for deployment (Module 24).
- Visualisation: filters, activation maximisation, Grad-CAM (Module 24).
- Mixing channel-first/channel-last layouts.
- Forgetting that the receptive field must cover the object scale.
- Over-aggressive early downsampling that destroys small details.
- BatchNorm with tiny batches in detection (use GroupNorm).
- Evaluating with train-time augmentation or without matching normalisation statistics.
Q1. Why do CNNs need fewer parameters than dense networks on images?
Show answer
Local connectivity limits each unit to a small patch and weight sharing reuses one filter at every location, so parameters do not grow with image size.
Q2. Derive the output size formula for
Show answer
Q3. Why stack small kernels instead of using one large kernel?
Show answer
Same receptive field with fewer parameters (
Q4. Why is the kernel gradient summed over spatial positions?
Show answer
The same kernel weights are used at every location, so each location contributes to their gradient.
Q5. Equivariance versus invariance?
Show answer
Equivariant: the output shifts with the input (convolution). Invariant: the output is unchanged (approximately obtained by pooling over positions for classification).
Q6. What problem do residual connections solve in CNNs?
Show answer
Degradation/vanishing gradients in very deep plain stacks; shortcuts let layers learn residuals and give gradients an identity path (Module 09).
Q7. How much does a depthwise separable convolution save?
Show answer
About
Q8. Why use global average pooling?
Show answer
It removes huge dense layers, reduces overfitting, handles variable input size and gives class-activation interpretability.
- LeCun, Y., Bottou, L., Bengio, Y., & Haffner, P. (1998). Gradient-based learning applied to document recognition. Proc. IEEE, 86(11).
- Krizhevsky, A., Sutskever, I., & Hinton, G. E. (2012). ImageNet classification with deep convolutional neural networks. NeurIPS.
- Simonyan, K., & Zisserman, A. (2015). Very deep convolutional networks for large-scale image recognition. ICLR. arXiv:1409.1556.
- Szegedy, C., et al. (2015). Going deeper with convolutions. CVPR.
- He, K., et al. (2016). Deep residual learning for image recognition. CVPR. arXiv:1512.03385.
- Huang, G., et al. (2017). Densely connected convolutional networks. CVPR.
- Tan, M., & Le, Q. (2019). EfficientNet. ICML. arXiv:1905.11946.
- Howard, A., et al. (2017). MobileNets. arXiv:1704.04861. Chollet, F. (2017). Xception. CVPR. Zhang, X., et al. (2018). ShuffleNet. CVPR.
- Liu, Z., et al. (2022). A ConvNet for the 2020s (ConvNeXt). CVPR. arXiv:2201.03545.
- Luo, W., et al. (2016). Understanding the effective receptive field in deep convolutional neural networks. NeurIPS.
- Dumoulin, V., & Visin, F. (2016). A guide to convolution arithmetic for deep learning. arXiv:1603.07285.
⬅️ Module 10 · 🗺️ Curriculum · 🏠 Home · Module 12 ➡️
🏠 Home · 🗺️ Curriculum · 🧭 Learning paths · ❓ Question bank · 📖 Glossary · 📚 References · ✏️ Contributing
🏠 Home · 🗺️ Curriculum · 🧭 Learning paths
❓ Question bank · 📖 Glossary · 📚 References
Jump to module:
01 02 03 04 05 06 07 08 09 10 11 12
13 14 15 16 17 18 19 20 21 22 23 24