Face and digit classification
Three classifiers for handwritten digits and faces, two of them built from scratch, compared on accuracy and speed.
- 9.60%error on digits with the PyTorch network, using all the training data
- 9.73%error on faces with the PyTorch network
Every image is a grid of characters. Each cell becomes one feature: 0 for blank, 1 for ink. A digit is 28 by 28, so 784 features; a face is 70 by 60, so 4,200.
We built three classifiers on those features. A perceptron learns one weight per feature for each class and nudges the weights whenever it guesses wrong. A three-layer neural network (input, two hidden layers, output) was written from scratch with NumPy, forward pass, backpropagation and gradient descent included. The third is the same shape of network in PyTorch, trained with the Adam optimizer.
Each one was trained on 10%, 20% and so on up to 100% of the training data, five times per step with fresh random samples, and tested on the full test set for error and training time.
Images
Pixels as 0s and 1s
Perceptron
From scratch
Neural network
From scratch, NumPy
Neural network
PyTorch
Learning curves
Error and time by data size
- Images to Perceptron
- Images to Neural network
- Images to Neural network
- Perceptron to Learning curves
- Neural network to Learning curves
- Neural network to Learning curves
See it work
What the classifier sees
The first image in the digit test set, labelled 9, drawn exactly as stored: each dark cell is a 1 and each blank cell a 0, 784 features in all.
Results with all the training data
| Classifier | Digit error | Face error | Digit training time |
|---|---|---|---|
| Perceptron | 22.06% | 15.20% | 0.07 s |
| Neural network from scratch | 12.82% | 16.40% | 1.23 s |
| Neural network in PyTorch | 9.60% | 9.73% | 3.45 s |
Mean over five runs, from the project's results file.