Datasets:
image imagewidth (px) 28 28 | label class label 10
classes | id stringlengths 10 10 | font stringclasses 7
values |
|---|---|---|---|
00 | sample-000 | DejaVuSans-Bold | |
00 | sample-001 | DejaVuSans | |
11 | sample-002 | DejaVuSansMono-Bold | |
11 | sample-003 | DejaVuSansMono | |
22 | sample-004 | DejaVuSerif | |
22 | sample-005 | DejaVuSans-Bold | |
33 | sample-006 | DejaVuSansMono-BoldOblique | |
33 | sample-007 | DejaVuSerif-Bold | |
44 | sample-008 | DejaVuSansMono | |
44 | sample-009 | DejaVuSansMono | |
55 | sample-010 | DejaVuSansMono-BoldOblique | |
55 | sample-011 | DejaVuSansMono-Bold | |
66 | sample-012 | DejaVuSerif | |
66 | sample-013 | DejaVuSans | |
77 | sample-014 | DejaVuSerif-Bold | |
77 | sample-015 | DejaVuSans-Bold | |
88 | sample-016 | DejaVuSans-Bold | |
88 | sample-017 | DejaVuSans | |
99 | sample-018 | DejaVuSansMono-Bold | |
99 | sample-019 | DejaVuSansMono-Bold |
synthetic-mnist-20
20 synthetic MNIST-like images: 28x28 grayscale, white digit on black, exactly two per digit (0-9). No real handwriting is involved — every sample is a typeset glyph from a DejaVu font that has been distorted to look scanned.
How each sample is made
- The digit is drawn at 224x224 from one of 8 DejaVu faces (Sans, Serif and Mono, regular and bold, plus the two mono obliques) with a random stroke width of 0-2 px.
- The ink bounding box is cropped and scaled so the glyph's longest side is 17-21 px once downsampled — the range real MNIST digits occupy (~20 px of 28).
- Random rotation of up to +/-14 degrees, shear of up to +/-0.28, and +/-1.5 px jitter.
- Rotation and shear grow the bounding box, so the glyph is capped at 92% of the frame and its paste position clamped: nothing is ever clipped at the border.
- The glyph is centred on its ink centre of mass (MNIST's own preprocessing), then Lanczos-downsampled to 28x28.
- Gaussian blur (sigma ~0.55 px) and additive noise (sigma 3-8 levels) to mimic a scan.
Seed 2026 makes the whole thing deterministic; gen_mnist.py in this repo reproduces it
byte for byte, and asserts 20 balanced samples, sane ink coverage and a clean border.
What it is and is not
Measured on these 20 samples: ink fraction 0.11-0.33 of the frame and glyph extent 0.64-0.82 of the side. Real MNIST digits span roughly 0.71 of the side, so the sizing matches, and the bold faces sit at the heavy end of the ink range.
That makes it a reasonable stand-in for pipeline smoke tests — dataloaders, an eval loop, a Gradio demo, a training script that needs something 28x28. It is not a substitute for real MNIST for anything that depends on handwriting variability: all 20 glyphs are typeset, and with 20 examples a model can only overfit them.
Load
from datasets import load_dataset
ds = load_dataset("abidlabs/synthetic-mnist-20", split="train")
# image: 28x28 grayscale PIL image
# label: ClassLabel 0-9
# id: str, sample-000 .. sample-019
# font: str, the DejaVu face the glyph came from
The PNGs are also mirrored as an imagefolder at images/train/<digit>/<digit>_<n>.png.
Regenerate
python gen_mnist.py --out ./out # render + build parquet and preview locally
python gen_mnist.py --out ./out --upload # also push to this repo
Requires pillow, numpy, datasets and DejaVu fonts at
/usr/share/fonts/truetype/dejavu (present in debian-based images, e.g. apt install fonts-dejavu-core).
- Downloads last month
- 187
