IMAGE CLASSIFICATION · LECTURE 4
CNN architectures and Vision Transformers
Count the numbers the model can learn independently.
Reveal the weights, then the bias. Count each box once.
Inputs and computed outputs do not add trainable parameters.
Two. Each has its own learnable storage slot.
No. Still 5: zero is a value the parameter can take.
No. The same 5 parameters are reused for every example.
One dense layer: 16 input values and 4 output values.
16 weights will connect to each output.
The input values are data. The connection weights are trainable.
Dense layer: input count × output count + one bias per output.
Keep 16 inputs and 4 outputs. Give each output a separate 2 × 2 region.
4 weights will connect to each output.
The input values are data. The connection weights are trainable.
Locality reduces the number of connections. These four weight sets are still independent.
One 2 × 2 filter uses the same weights and bias at all four positions.
Bias b = 0
Stored once
4 + 1 = 5weights + bias
Zero-valued coefficients count.
Used at four positions
4 × 4 = 16multiplications
Move the filter. Its parameter count stays at 5.
Change w₁ once. All four positions use its new value.
RGB input · two 2 × 2 filters · stride 2 · no padding · bias enabled
Each filter spans all input channels and produces one output map.
H × W = image positions. C = channels at each position.
Why do we need assumptions?
The dark dots are three observed examples. Predict the output at x = 3.
At x = 3: 3
At x = 3: 9
Both fit the observed examples but disagree on this unseen input.
An assumption or preference that guides predictions beyond the training examples.
The bias parameter b is different: it is a learned offset.
An assumption helps when it matches the task.
Locality: one output reads a small neighborhood.
6 × 6 image · 2 × 2 filter · stride 2 · no padding · one channel
Change a pixel outside the window. Can it change this selected output?
Selected response = −1(0) + 1(1) − 1(0) + 1(1) + 0 = 2
Same image. Same 9 outputs. Different assumptions.
6 × 6 input · each local window is 2 × 2 · stride 2 → 3 × 3 = 9 outputs
9 × (36 + 1) = 333
9 × (4 + 1) = 45
1 × (4 + 1) = 5
One bank, reused ↓
9 separate banks.
Each has 36 weights and 1 bias.
What we gainThe same detector at every position, with fewer parameters.
What we restrictOne local layer cannot directly connect distant positions.
ImageNet · 2012 · ReLU in hidden layers · no BatchNorm
5 convolutional + 3 fully connected weighted layers. LRN follows conv 1 and 2.
ReLU keeps positive responses sensitive to change.
OptimizationAt z = 3: ReLU slope = 1; tanh slope ≈ 0.010.
Nearly flat activations weaken the learning signal.
For positive inputs, ReLU keeps slope 1 even when tanh becomes nearly flat.
This can speed training. Negative ReLU inputs have zero slope.
Faster training does not guarantee better test accuracy.
Two GPUs made a wider network feasible.
Capacity and computationFirst-layer widths are illustrated; the boxes are not memory-usage meters.
A wide network needs more memory.
Split filters across two GPUs to train a wider network.
More filters give the network capacity to learn more patterns.
The model grew; changing hardware alone does not improve predictions.
3 × 3 max pooling, stride 2: retain a nearby peak.
Spatial reductionMove the 9. Predict the orange output before clicking.
Large feature maps require more computation.
Keep the largest value in each 3 × 3 window.
Smaller maps reduce work. A peak can move within a window without changing its maximum.
Each channel is pooled separately. No trainable weights.
Change the training view; keep the class target.
GeneralizationA teaching photo, transformed for illustration. No model prediction is shown.
The model may rely too much on an object’s exact position.
Crops and flips vary the view while keeping the class target.
This can help with similar changes at test time.
Use transformations that preserve the label.
Train the classifier with different available features.
GeneralizationMask A: 2(1) + 0(−0.5) + 1(2) + 0(1) = 4.
The classifier may rely on a few features together.
Randomly zero hidden activations during training. The weights remain stored.
Learning with different feature subsets can reduce overfitting.
AlexNet used a 0.5 drop probability in its first two fully connected layers.
Local response normalization (LRN)
Historical normalization4 ÷ (2 + 0.0001 × 26)^0.75 = 2.376
Several channels can respond strongly at one position.
Divide by a quantity based on five neighboring channel responses.
Stronger neighbors suppress the selected response.
Historical AlexNet component. LRN differs from BatchNorm.
The complete system achieved a major improvement.
Historical benchmark7-model ensemble; two models used extra ImageNet pretraining.
Top-5 error: the correct class is absent from the top five predictions.
The winning entry combined seven networks and multiple test views.
The gain belongs to the complete system.
AlexNet showed what a large CNN can do. What could greater depth add?
These comparisons use different setups. Their gains cannot be added to explain the competition result.
Read the AlexNet paper ↗Read the dropout paper ↗AlexNet showed that learned CNN features can succeed at ImageNet scale.
weighted layers
5 conv + 3 FCDoes greater network depth
improve image recognition?
8 conv + 3 FC
Configuration A10 conv + 3 FC
Configuration B13 conv + 3 FC
Configuration D · VGG-1616 conv + 3 FC
Configuration E · VGG-19Use small 3 × 3 filters, the same channel stages and the same three-layer classifier.
One tested model: VGG-16 (D) · Each box: Conv + ReLU · conv stride 1, padding 1 · pool 2 × 2, stride 2
Pool after each of the five blocks: 224 → 112 → 56 → 28 → 14 → 7.
Blue area: input pixels that can affect one output position
C: channels in every layer · stride 1 · no pooling between layers · biases excluded
Same receptive-field extent; fewer weights and more nonlinearities under these assumptions.
Small filters let us add more layers and ReLUs.
1 convolution + 1 ReLU
3 convolutions + 3 ReLUs
Each ReLU keeps positive responses; the next layer recombines them.
Both use a 7 × 7 input region and can compute different functions.
VGG processes fine detail before reducing the map size.
The first convolution reduces spatial size.
Two Conv → ReLU operations at 224 × 224.
Then 2 × 2, stride-2 pooling gives 112 × 112.
Possible benefitMore processing before spatial detail is reduced.
CostLarger maps require more computation.
Next: did these deeper networks reduce recognition errors?
Return to the question: does greater depth reduce recognition errors?
ImageNet validation · train/test scale 256 · dense evaluation + horizontal flip
11 → 16 layers: 2.6 percentage points less error.19 layers does not improve this fixed-scale result.
VGG-16 · one 3 × 3 convolution · 64 → 64 channels
VGG-16 · 224 × 224 input · batch 1 · individual float32 tensors, not peak memory
Small filters enable depth; the full network still has substantial storage costs.
VGG and Inception explored different questions in 2014.
How much nearby context should one output use?
Same incoming feature grid · every convolution spans all input channels
Different filters. Matching output height and width.
Naïve module · shapes: H × W × C · bar widths show channel counts
Toy: 3 input channels, 1 × 1 filters
Toy: 3 → 2 channels · stride 1, padding 0 · before activation
A 1 × 1 filter mixes channels at the same pixel. H and W stay unchanged.
Each filter has its own weights. Reuse them at every position.
Same 8 parameters at every position · outputs change with the input
Can the 5 × 5 branch start with fewer channels?
28 × 28 at every step · convolution MACs
Reduce channels before the costly spatial convolutions.
28 × 28 × (64 + 128 + 32 + 32) = 28 × 28 × 256
Stride 1 throughout · padding: 1×1 → 0; 3×3 / pool → 1; 5×5 → 2
GoogLeNet stacks nine Inception modules.
Within a module: keep spatial size. Between groups: downsample.
Where do the final 1,024 channels come from?
384 + 384 + 128 + 128 = 1,024 channels
Branch widths are design choices · every feature map here is 7 × 7
Summarize each feature map with one average.
Repeat for every channel: 7 × 7 × 1,024 → 1 × 1 × 1,024
Global average pooling · no trainable parameters
Why average before the classifier?
49× fewer weights in this linear head
Same final feature tensor and 1,000 classes · biases excluded from both counts
From image features to a class prediction.
Next question: how can we make a deep network easier to train?
After the break: BatchNorm (2015), then residual connections
Earlier weights shape what later layers receive.
What happens here when the earlier weights are updated?
Toy example · one channel · 2 images, 2 values each
Same images. Updated weights. Different internal values.
“Internal covariate shift”: changing internal activation distributions.
Original BatchNorm motivation · Ioffe & Szegedy, 2015
Why can a change of scale affect optimization?
A larger gradient gives a larger update at the same learning rate.
Isolate one factor: hold ∂L/∂z = 0.1 fixed. In training, this derivative can change too.
BatchNorm makes normalization part of the network.
Next: compute it on the same four activation values.
ICS was the original hypothesis. Later work also links BN to smoother optimization.
Measure → normalize → apply learned scale and offset.
Convolution → BatchNorm → ReLU
Same operation. Different source of statistics.
μB, σB2
Update running estimates →μrunning, σrunning2
Keep estimates fixedγ,β: learned per channel · used in both modes
C channels → 2C trainable parameters
How many training steps to reach the same 72.2% accuracy?
ImageNet · single-crop top-1 validation accuracy · 2015 Inception variant
Without BatchNorm: 31.0 million steps.
ImageNet · plain CNNs · both networks already use BatchNorm
Can adding layers make the training fit worse?
The extra capacity has not produced a better training fit.
Extra layers should be able to keep a useful representation.
Make “keep what already works” easy to represent.
Identity is an available option; training still has to find useful weights.
Keep a compatible input path; learn the change F(x).
A zero residual preserves the input at the addition.
Same shape: copy the input.
Identity shortcut: 0 learned parameters.
Illustrative block · BN omitted
The branch changes shape. Can we still add x?
Addition requires matching height, width and channels.
Match the shortcut with a learned 1 × 1 convolution.
Stride 2: 56 → 28. 128 filters: 64 → 128 channels.
The projection transforms x; it is not an exact copy.
Both paths learn weights. Their structures are different.
If F(x)=0, the sum is Wsx: the projected input.
ImageNet · same 18-layer and 34-layer comparison
Table 2 · ten-crop validation · parameter-free shortcuts (option A)
Here, residual connections improved training and validation error.
Convolution applies the same learned kernel to a local neighborhood.
Start with one image.
Attention needs position information to distinguish image locations.
A token is a feature vector. Select a token to inspect its features.
One query compares with every key, including its own token’s key.
Choose a query and work through its calculation.
One query produces one output vector.
Each token enters with D features.
Follow the same image all the way to the classifier.
Inductive bias: built-in assumptions that guide learning.
| Image MLP | CNN | Vision Transformer | |
|---|---|---|---|
| Connections | Dense pixel connections | Local, shared filters | Global token attention |
| Position | Fixed input slots | 2D feature grid | Added position vectors |
ViT still builds in patches, shared operations and position vectors.
Keep the image size fixed. Change the patch width.

Patch tokens196
With class token197
One score for each query and key pair.
Half the patch width → about 4× tokens → about 16× attention scores.
Learn on an earlier dataset. Then adapt to the target task.
ImageNet top-1 accuracy after transfer · 384-pixel evaluation · original ViT study
In this study, larger pretraining regimes especially help ViT-L.
Keep the feature extractor. Add a classifier for your classes.
Illustrative CIFAR-10 adaptation · 10 classes
Decide the split and selection rule before comparing models.
45,000 images
5,000 images
Keep separate until the end
Course CIFAR-10 split: training and validation come from the original training set.
Which choice uses test information too early?
Measured CIFAR-10 MLP · 45,000 training / 5,000 validation images
Training loss falls while validation loss rises.
Penalty strength λ: none, moderate, strong.
Small teaching experiment · two coordinates → 20 hidden units → two classes
Same architecture · same training setup
Training loss0.233
Validation loss0.681
Mean binary cross-entropy
Weight penalty excluded
Training loss is low. Validation loss is higher.
p≥0.5 → class 1
p<0.5 → class 0
Change the image while keeping useful evidence for its class.


Can we still justify the label “horse”?
Measured recipe: random 32 × 32 crop after 4-pixel padding + horizontal flip.
Validate the transformation on the task.
Same MLP, split, start and 40 epochs
No augmentationRandom crop + flip
Freeze each selected checkpoint
5,000 images in each condition


This paired run gains 0.48 pp on original images and 7.56 pp after the shift.
Before reading validation results, check the evaluation setup.
| Operation | Training | Evaluation |
|---|---|---|
| Input pipeline | Random crop + flip | Fixed preprocessing |
| BatchNorm | Use batch statistics | Use stored training statistics |
| Dropout | Mask + rescale | Pass activations unchanged |
| Parameters | Compute gradients and update | Keep parameters fixed |
Set layer mode, preprocessing and gradient tracking separately.
| true ↓ / predicted → | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 airplane | ||||||||||
| 1 automobile | ||||||||||
| 2 bird | ||||||||||
| 3 cat | ||||||||||
| 4 deer | ||||||||||
| 5 dog | ||||||||||
| 6 frog | ||||||||||
| 7 horse | ||||||||||
| 8 ship | ||||||||||
| 9 truck |
CIFAR-10 · 5,000 validation images · CNN
Select a cell. The diagonal counts correct predictions.
For one class, separate correct predictions, false alarms and misses.
Look at the image before seeing the model’s answer.
Use validation evidence to choose the next model to test.