Case study · Computer vision
- Image classification
- CNN & transfer learning
- Vision Transformers
Who is in this photo?
3,023 news photos of 62 public figures. Three generations of computer vision answer the same question under the same rules: hand-designed edge features, a CNN that learns its own, and a network pretrained on a million images, then fine-tuned. Then a look inside how a Vision Transformer reads a face.
Step 01 · Faces as numbers
Every face is 35,250 numbers.
01 · aLook before you train
Each photo is a 125 × 94 grid of pixels with three colour channels: a (125, 94, 3) tensor of values between 0 and 1. The people are far from equal: one man has 530 photos, the rarest have 20. A model that always answers “George W Bush” scores 17.6%, which is why the main score here is macro-F1, where every person counts the same.
Photos per person · the ten most common
52 more people have between 20 and 52 photos each.
A stratified 70 / 15 / 15 split
All 62 people appear in every split, but that leaves only about 34 training photos per person, and as few as 14. The rarest people have just 3 photos to be tested on, so one mistake moves their score by 33 points.
01 · bHand-designed features
Edges carry identity. Fixed rules don't adapt.
Classical vision describes a face with rules a person chose. Grayscale, contrast equalisation, blur, Sobel gradients and Canny edges show where identity lives: around the eyes, nose, mouth and jaw. They also show the weakness: Canny's fixed thresholds draw a rich sketch of one face and almost nothing of another.

HOG (histograms of edge directions in 8 × 8 cells) shrinks each face 7×. A linear SVM on top reached 75.3% on validation in 36 seconds on a CPU: about 4× the majority baseline, before any deep learning.
Step 02 · Let the model learn the features
405,790 parameters, learned from scratch.
A CNN learns its own filters instead of using hand-picked ones. Mine has four convolution blocks (32 → 64 → 128 → 256 filters, each with batch normalisation and pooling), global average pooling and dropout. With so few photos per person, it also needs augmentation: random flips, small rotations, shifts, brightness and contrast changes, applied to training images only.
Solid: training accuracy (augmentation and dropout on, so it understates). Dashed: validation. Hover to read any epoch.
For the first eight or so epochs, validation accuracy sat near 2% while training improved, and validation loss spiked to almost 6. The likely culprit is batch normalisation: its running statistics lag behind fast-changing weights. Seven learning-rate cuts later the curves settled. A small min_delta on early stopping would have saved the last 70 nearly flat epochs; the next model uses one.
Step 03 · Borrow what's already learned The hard part
Pretrained alone wasn't enough.
MobileNetV2 has already learned edges, textures and shapes from over a million ImageNet photos. First I froze all of it and trained only a new 62-way head. It was worse than my own small CNN. Flip the switch to see what fine-tuning the top 40 layers did.
69.1%
validation accuracy · 79,422 trainable parameters
Generic ImageNet features (cats, cars, textures) can't tell two grey-suited men apart.
Mean recall by how many training photos a person had (test set)
Pretraining helped most where data was thinnest: +10 points over the CNN on the rarest people.
Against the CNN, fine-tuned MobileNetV2 was better on 24 people, worse on 16 and the same on 22. The average gain hides that churn. It also overfits more: 99% training accuracy against 88% on validation, because 1.7 million trainable parameters can memorise 2,116 photos. Early stopping with a minimum improvement caught it at epoch 27 of fine-tuning.
Step 04 · How a Vision Transformer sees
Cut the face into words. Let every word look at every other.
04 · aPatches and attention, by hand
A ViT doesn't slide filters. It cuts the image into 16 × 16 patches, flattens each into a token, and lets every token score every other one. I did it by hand on one face: 48 tokens of 768 values, a 48 × 48 attention matrix whose rows each sum to exactly 1.


ViT-Base/16 has 85.8 million parameters: 211 times my CNN and 37 times MobileNetV2. With 2,116 training photos it would have nothing to learn from. Knowing when not to use the fashionable model is part of the job.
04 · bThe cost of attention
Halve the patch, 16× the work.
Every token attends to every token, so the work grows with the square of the token count. For a standard 224 × 224 image in ViT-Base (12 layers × 12 heads), pick a patch size:
Pure arithmetic: tokens = (224 ÷ patch)² + 1, and each head scores tokens × tokens pairs.

Step 05 · The final exam
Probably better. Not proven better.
05 · aOne look at the test set
The 454 test photos played no part in training, early stopping or choosing models. Each finished model was scored on them once. The bar is test accuracy; the tick is the validation score it predicted.
Every model scored within 1.3 points of its validation estimate, so choices made on the validation set didn't overfit it.
05 · bIs the gap real?
Resample the test set 1,000 times.
A 4-point lead on 454 photos could be luck. Bootstrapping redraws the test set with replacement 1,000 times and records each difference. An interval that crosses zero means the lead can't be told apart from noise.
Points of difference with 95% bootstrap intervals. Both neural networks clearly beat HOG. MobileNetV2's accuracy lead over the CNN only just clears zero, and its macro-F1 lead doesn't.

Learned beats handmade
Both neural networks beat HOG by 7 to 11 points, with intervals well clear of zero.
The clear resultTransfer learning, modestly
Best on every metric and on the rarest people, trained faster than the CNN, but 5.8× larger, and its lead isn't proven.
The pickData is the real limit
About 34 photos per person caps every model. Possible near-duplicate news photos across splits may flatter all three scores.
The caveat
The lesson
A better number isn't a better model until the interval says so.
Python · TensorFlow / Keras · scikit-learn · scikit-image · OpenCV · PyTorch + Hugging Face (ViT). Labeled Faces in the Wild (Huang et al., 2007).