Skip to content

Module 11

Anurag Prasad edited this page Nov 9, 2026 · 8 revisions

Module 11 — Convolutional Neural Networks and Advanced CNN Architectures

⬅️ 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


Overview and learning goals

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

Beginner: the big picture

Instead of connecting every pixel to every neuron, a CNN slides a small filter (e.g. $3\times3$) across the image and computes the same weighted sum at each location, producing a feature map. Early filters detect edges and colours; deeper ones combine them into textures, parts and objects.

Edge-detecting filters applied to a synthetic image

Figure 11.1 — A synthetic image filtered with Sobel kernels: $K_x$ responds to vertical edges, $K_y$ to horizontal edges. Original figure (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"]
Loading

Core concepts and derivations

Fully connected versus convolutional models

A $224\times224\times3$ image has 150,528 inputs; one dense layer to 1,000 units needs $\approx1.5\times10^8$ weights and ignores spatial structure. A $3\times3$ conv with 64 output channels needs $3\cdot3\cdot3\cdot64+64=1{,}792$ parameters and is reused at every location.

Grids, channels, filters and feature maps

Input $X\in\mathbb{R}^{C_{in}\times H\times W}$; a layer has $C_{out}$ filters $K\in\mathbb{R}^{C_{in}\times k\times k}$. Output channel $o$ at $(i,j)$:

$$ Y_{o,i,j}=b_o+\sum_{c=1}^{C_{in}}\sum_{u=0}^{k-1}\sum_{v=0}^{k-1}K_{o,c,u,v},X_{c,,si+u,,sj+v}. $$

(Deep-learning "convolution" is technically cross-correlation, without kernel flipping; it makes no difference for learned filters.) Parameters: $C_{out}(C_{in}k^2+1)$.

1D, 2D and 3D convolution

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.

Kernel size, stride, padding, dilation and output size

For input size $n$, kernel $k$, padding $p$, stride $s$, dilation $d$:

$$ n_{out}=\Bigl\lfloor\frac{n+2p-d(k-1)-1}{s}\Bigr\rfloor+1 . $$

"Same" padding ($p=\frac{k-1}2$, $s=1$) preserves size. Example: AlexNet's first layer, $n=224$, $k=11$, $s=4$, $p=2$: $\lfloor\frac{224+4-11}{4}\rfloor+1=55$. Dilation spaces kernel taps to enlarge the field without more parameters. Transposed convolution upsamples (decoders, GAN generators).

Receptive field and parameter count

The receptive field $r$ and cumulative stride ("jump") $j$ obey $r_\ell=r_{\ell-1}+(k_\ell-1)j_{\ell-1}$, $j_\ell=j_{\ell-1}s_\ell$, $r_0=j_0=1$. Three stacked $3\times3$ stride-1 layers give $r=7$ — the same as one $7\times7$ layer but with $27C^2$ rather than $49C^2$ parameters and two extra nonlinearities (the VGG argument). Effective receptive fields are Gaussian-shaped and smaller than the theoretical size (Luo et al. 2016).

Pooling and downsampling

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.

Flattening and classification heads

After feature extraction: global average pool → linear → softmax (modern), or flatten → dense layers (AlexNet/VGG). Detection and segmentation heads keep spatial maps.

Convolution backpropagation and shared-filter gradients

With upstream gradient $G=\partial L/\partial Y$: the kernel gradient is the correlation of the input with $G$, $\ \partial L/\partial K_{o,c,u,v}=\sum_{i,j}G_{o,i,j}X_{c,i+u,j+v}$ — summed over all positions, because the filter is shared; the input gradient is the "full" convolution of $G$ with the spatially flipped kernel. Biases accumulate $\sum_{i,j}G_{o,i,j}$.

Locality, weight sharing and translation equivariance

Shifting the input shifts the feature map: $\mathrm{conv}(T_a x)=T_a,\mathrm{conv}(x)$ (equivariance). Pooling and global pooling add approximate invariance. Striding and boundary effects break exact equivariance, and CNNs are not rotation- or scale-equivariant unless designed to be.

Architecture families

Model Key idea
LeNet-5 (1998) conv–pool–dense; digit recognition
AlexNet (2012) ReLU, dropout, GPUs, large-scale ImageNet
VGG (2014) stacks of $3\times3$ convs, depth
Inception/GoogLeNet multi-scale parallel branches, $1\times1$ bottlenecks
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 ($k^2C_{in}$ weights) and a $1\times1$ pointwise mix ($C_{in}C_{out}$). Cost ratio versus a standard conv: $\frac{1}{C_{out}}+\frac1{k^2}\approx\frac19$ for $k=3$ and large $C_{out}$.

Signals, volumes and benchmark datasets

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

Worked example

A $3\times3$ patch $\begin{pmatrix}1&2&3\4&5&6\7&8&9\end{pmatrix}$ with kernel $\begin{pmatrix}1&0&-1\1&0&-1\1&0&-1\end{pmatrix}$ gives $(1-3)+(4-6)+(7-9)=-6$. The response is negative because intensity increases from left to right (the kernel computes left minus right); a patch that darkens to the right would respond positively, and a flat patch gives $0$. A $5\times5$ input, $3\times3$ kernel, $s=1,p=0$ yields a $3\times3$ map ($\lfloor\frac{5-3}{1}\rfloor+1$); with $p=1$ it stays $5\times5$.

Parameters: $64\to128$ channels, $3\times3$: $128(64\cdot9+1)=73{,}856$; depthwise separable: $64\cdot9+64\cdot128=8{,}768$ (plus biases) — about $8.4\times$ fewer.

Implementation

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

Advanced topics

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

Pitfalls and best practices

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

Conceptual questions and answers

Q1. Why do CNNs need fewer parameters than dense networks on images?

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 $n=32$, $k=5$, $p=0$, $s=1$.

$\lfloor(32-5)/1\rfloor+1=28$.

Q3. Why stack small kernels instead of using one large kernel?

Same receptive field with fewer parameters ($27C^2$ vs $49C^2$ for $7\times7$) and more nonlinearities, giving more expressive features.

Q4. Why is the kernel gradient summed over spatial positions?

The same kernel weights are used at every location, so each location contributes to their gradient.

Q5. Equivariance versus invariance?

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?

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?

About $\frac1{C_{out}}+\frac1{k^2}$ of the cost: roughly 8–9× for $3\times3$ kernels.

Q8. Why use global average pooling?

It removes huge dense layers, reduces overfitting, handles variable input size and gives class-activation interpretability.

Sources and further reading

  • 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 ➡️

🎓 Deep Learning Hub

🏠 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

Part 1 · Mathematical foundations
Part 2 · Neural network fundamentals
Part 3 · Training deep networks
Part 4 · Core architectures
Part 5 · Representation and generative learning
Part 6 · Specialised, modern and responsible deep learning
Reference and meta

Clone this wiki locally