Convolutional Neural Networks

How convolutions, pooling and stacked feature maps let a network learn edges, textures and objects with far fewer parameters than a dense layer.

Intermediate · about 14 hours · difficulty 3/5

Learn first: Debugging and Running Training Experiments

A dense layer treats each pixel as an unrelated input, which wastes parameters and ignores the fact that nearby pixels belong together. A convolution slides a small learned filter across the image, so the same weights detect a pattern wherever it appears. This built-in assumption (translation equivariance) is why CNNs learn vision tasks from modest data.

Building blocks

  • Kernel size, stride and padding decide the output shape. Practise computing it by hand: out = (in + 2*pad - kernel) / stride + 1.
  • Channels: each filter produces one feature map; a layer with 64 filters outputs 64 channels.
  • Pooling (max or average) and strided convolutions shrink spatial size so later layers see a wider receptive field.
  • Batch normalization and ReLU after each convolution are the standard recipe.
  • Global average pooling plus a linear layer turns feature maps into class scores.

Landmark architectures

LeNet showed the idea, AlexNet and VGG proved depth helps, and ResNet introduced skip connections that make very deep networks trainable. Today you will also meet EfficientNet, ConvNeXt and Vision Transformers (ViT), which split an image into patches and apply attention. You rarely design an architecture from scratch; you need to read one and know which knobs matter.

Inspecting what was learned

Visualize first-layer filters and feature maps, and use saliency methods such as Grad-CAM to check that the model looks at the object and not the background.

Good enough to move on when you can build a small CNN, predict every tensor shape through it, and explain why a residual connection helps optimization.

Key concepts

  • Convolution, stride and padding
  • Channels and feature maps
  • Pooling and receptive field
  • ResNet and skip connections
  • Global average pooling
  • Vision Transformers (ViT)
  • Grad-CAM and saliency maps

Mini project

Train a small CNN on CIFAR-10, then add residual blocks and batch normalization and compare accuracy and training curves. Plot Grad-CAM heatmaps for five correct and five wrong predictions.

Check yourself

A 32x32x3 image passes through a 3x3 convolution with 16 filters, stride 1 and padding 1, then 2x2 max pooling. What is the output shape and how many learnable weights did the convolution have?

Free resources