A small neural network that learns to read handwritten digits, written in plain C++ with no ML libraries.
./scripts/download_data.shThis puts the four MNIST files in data/.
cmake -B build
cmake --build buildFor a debug build with AddressSanitizer and UBSan:
cmake -B build-debug -DCMAKE_BUILD_TYPE=Debug
cmake --build build-debugRun from the repo root (the data paths are relative):
./build/mnistMLP (784 → 64 → 10, ReLU + softmax) trained with SGD, learning rate 0.01, 10 epochs, on an 80/20 train/val split of the 60k training set:
| Model | Loss | Train | Val | Test |
|---|---|---|---|---|
| MLP + SGD | 0.0245 | 99.20% | 97.18% | 97.38% |
Test accuracy is measured on the separate 10k MNIST test set.