The data
The German Traffic Sign Recognition Benchmark contains photos of real signs taken from a moving car, cropped and shrunk to 32×32 pixels: 34,799 for training, 4,410 for validation and 12,630 for testing. The photos vary a lot in lighting, angle and sharpness, and the classes are very uneven. Common signs like the 50 km/h limit have about ten times as many training examples as rare ones like the 20 km/h limit.
Preprocessing and augmentation
Each image goes through the same three steps:
- Convert to grayscale. Shapes and symbols matter more than color here, and using one channel instead of three makes the model smaller.
- Spread the brightness values across the full range, so dark and washed-out photos end up with similar contrast.
- Scale pixel values to between 0 and 1 according to brightness.
During training, each batch was also randomly shifted (up to 10%), zoomed (up to 20%), sheared and rotated (up to 10°), so the model saw slightly different versions of every sign. That's why the model is resistant to minor changes but still fails on more drastic ones.
The model
A modified version of LeNet, a classic convolutional network design, built with Keras. The convolutional layers learn small visual patterns (edges, curves, shapes and symbols) and the dense layers combine them into a decision. It has about 620,000 weights in total.
| Layer | Details | Output size |
|---|---|---|
| Convolution | 60 filters, 5×5, ReLU | 28×28×60 |
| Convolution | 60 filters, 5×5, ReLU | 24×24×60 |
| Max pooling | 2×2 | 12×12×60 |
| Convolution | 30 filters, 3×3, ReLU | 10×10×30 |
| Convolution | 30 filters, 3×3, ReLU | 8×8×30 |
| Max pooling | 2×2 | 4×4×30 |
| Dense | 960 units, ReLU, 50% dropout | 960 |
| Dense | Softmax | 43 classes |
Trained for 10 epochs with the Adam optimizer (learning rate 0.001) in batches of 50. It reaches … accuracy on the 12,630-image test set, which it never saw during training. In the browser, the network runs in a few dozen lines of plain JavaScript using the exported weights, with no machine learning library.
Where it gets confused
The grid below compares every test image's actual sign (rows) with the model's prediction (columns). Correct answers fall on the grey diagonal, and every red square is a mistake: the darker the red, the more often it happened. Hover over a square to see which signs it compares.
Most common mistakes
Click one to load that exact image into the demo.