RoboticsUnit 5 · Generative models & scaling · Day 28

CS231n: Convolutional Neural Networks for Visual Recognition

The Stanford course notes that taught a generation how a CNN really works: shapes, strides, padding, parameter counts and memory. This is the bookkeeping you need before you can design or debug any vision model.

AuthorsStanford CS231n. Notes primarily by Andrej Karpathy, course led by Fei-Fei Li
Year / venue2015 onwards · Stanford course notes
Core ideaLocal connectivity + weight sharing
Study time4–6 h

Original: cs231n.github.io, ConvNets notes · Code, notebook and exercises: 30u30 Day 28

Start here (no maths needed)

This free Stanford course explains, step by step, how computer vision networks look at pictures, and how to work out their sizes so they fit on a real machine.

Think of it like this

Picture a stamp that checks for one pattern, like a vertical line. You press it at every spot on a page, moving it a few squares at a time, and write down how well each spot matches. A vision network does exactly that with many different stamps. The course teaches you to work out how many spots you get, and how much storage all of it needs.

How it works

  1. A picture is a grid of numbers: width, height and colour.
  2. A small filter (the "stamp") slides across the picture and gives a score at each spot.
  3. Many filters make many score maps. Each looks for a different pattern.
  4. Pooling shrinks the maps, keeping the strongest scores.
  5. After several rounds, the last layers turn the maps into an answer, like "cat".

Why robots care

A robot's computer has limited memory and must answer fast, often many times a second. If you add a depth camera or change the picture size, the network's shapes change. The sums in this course tell you whether the network still fits, and how long it will take to run.

Try it

Words to know

Filter
A small grid of learned numbers that looks for one pattern.
Stride
How many pixels the filter jumps each time it moves.
Padding
Extra blank border added around a picture so the filter fits.
Pooling
Shrinking a map by keeping the biggest value in each small patch.
Parameters
The learned numbers stored inside the network.

Going deeper: everything below is the full version, with some maths. On a first read, skim the headings and the "Why it matters for robotics" box, and come back for the rest later.

1. Summary

TL;DR

This isn't a paper. It is the "Convolutional Neural Networks" chapter of Stanford's CS231n notes. It explains ConvNets as stacks of 3-D volumes (width × height × depth) and spells out the arithmetic: how big each layer's output is, how many weights it has, and where memory and compute go. Its two central ideas are local connectivity (each neuron looks at a small patch) and parameter sharing (the same filter is used at every position). The notes finish with practical rules (small 3×3 filters, stride 1, padding that preserves size, 2×2 pooling) and case studies from LeNet to ResNet.

2. The core idea

A conv layer takes a volume W₁ × H₁ × D₁ and has four hyperparameters: number of filters K, filter size F, stride S and zero-padding P. It produces:

W₂ = (W₁ − F + 2P) / S + 1          # same for H₂; must be an integer
D₂ = K
weights = (F · F · D₁) · K,   biases = K

"same" padding with stride 1:  P = (F − 1) / 2
pooling (F, S):  W₂ = (W₁ − F) / S + 1,  no weights

im2col. Real implementations stretch every receptive field into a column (for AlexNet conv1, a 363 × 3025 matrix) and every filter into a row (96 × 363). The whole layer then becomes one big matrix multiply, which BLAS and GPUs do very fast. The price is memory, because overlapping patches are copied.

3. Deep dive

Interactive: conv layer calculator

Interactive: output size and parameters

The strip shows one row of the padded input (padding greyed out) and where each filter placement lands. Red means the filter doesn't fit evenly.

Output
–
Parameters
–
Multiply-adds
–

Design rules the notes recommend

Memory is the real bottleneck

The VGG-16 walkthrough is the most useful part of the notes. Activations are huge early (224×224×64 values per layer, for two layers). Parameters are huge late (the first FC layer alone holds about 100M weights). During training you also store gradients for both, plus optimiser state, roughly three times the parameter memory. Count values, multiply by 4 bytes, then decide your batch size. This explains why ResNet (Day 09) uses global average pooling instead of big FC layers, and why dilated networks (Day 11) pay so much for keeping full resolution.

Limitations

4. Why it matters for robotics

5. How to study it

  1. Read the ConvNets notes end to end (about 2 h). Redo the AlexNet and VGG arithmetic on paper as you go.
  2. In the 30u30 Day 28 folder, read implementation.py: a naive conv forward pass, im2col, pooling, and a small NumPy CNN. Run train_minimal.py and check the im2col output against the naive version.
  3. Work through notebook.ipynb, then the five exercises: naive conv forward, max-pool forward and backward, output sizes, VGG-style parameter counts and filter visualisation.
  4. Use the calculator above to check your exercise 3 and 4 answers.
  5. Stretch: do the official CS231n assignments (linked from the course site), especially the conv-net and batch-norm parts of assignment 2.

6. Self-check

Input 32×32×3, ten 5×5 filters, stride 1, padding 2. Output shape and parameter count?

(32 − 5 + 4)/1 + 1 = 32, so 32×32×10. Weights: 5·5·3·10 = 750, plus 10 biases, giving 760.

Why can't you use F = 3, S = 2, P = 0 on a 10-wide input?

(10 − 3)/2 + 1 = 4.5 isn't an integer. The filter doesn't tile the input evenly.

Where does VGG-16 use most of its memory, and most of its parameters?

Memory: the early conv layers, which have large spatial activations. Parameters: the first FC layer, with about 100M of roughly 138M.

What is a 1×1 convolution good for?

It mixes channels at each pixel. Use it to change depth cheaply, as in ResNet's bottleneck blocks.

What does im2col trade off?

It turns convolution into one fast matrix multiply, at the cost of memory to hold duplicated overlapping patches.

7. Further reading