Counting MNIST

A simple synthetic dataset and baseline model for visual counting. The task is to count the number of even digits given a 100x100 image, each with up to 5 randomly chosen MNIST digits.

We use rejection sampling to ensure digits are separated by at least 28 pixels. Reproduced with details from Learning to count with deep object features.

View it on Github:

Example Images

Six images of hand drawn numbers randomly placed.

Distribution Graph

Graph showing the distribution of even numbers in the set. Slopes downward at an approximate 45 degree angle from left to right.


  1. Clone repo: git clone [email protected]:fomorians/counting-mnist.git
  2. Generate TFRecords: python -m counting_mnist.create_dataset
  3. Train baseline: python -m counting_mnist.main


Model Accuracy
Always Predict Zero Even Digits 33%
Uniform Count Predictions 12%
Baseline Model 85%

NOTE: This is not a competitive dataset, it’s intended to be simple place to start for validating ideas in counting models.