docs/en/datasets/classify/mnist.md
The MNIST (Modified National Institute of Standards and Technology) dataset is an image classification benchmark of 70,000 28x28 grayscale images of handwritten digits spanning 10 classes — the digits 0 through 9. It ships with a predefined split of 60,000 training and 10,000 test images and has long served as the standard benchmark for evaluating machine learning and computer vision algorithms. For the harder clothing-image equivalent, see the related Fashion-MNIST dataset; for color images, see CIFAR-10.
MNIST ships with an official, predefined split, so no automatic or manual partitioning is needed:
!!! note "Validation split"
MNIST has no separate validation folder, so Ultralytics uses the 10,000-image test set as the validation split during training by default.
Each image is labeled with its corresponding digit (0–9), making MNIST a supervised dataset ideal for classification tasks.
MNIST is widely used to train and evaluate image classification models, from classic Convolutional Neural Networks (CNNs) and Support Vector Machines (SVMs) to modern deep architectures. Its small grayscale images and 10 digit classes make it a fast, reproducible benchmark for algorithm comparison and computer vision experimentation.
Some common applications include:
Train a YOLO classification model on MNIST for 100 epochs at an image size of 28. The dataset downloads and caches automatically on first use; if you prefer full control over preprocessing, the original gzip archives are also available from the MNIST database. For the full list of available arguments, see the Training page and the image classification task guide.
!!! example "Train Example"
=== "Python"
```python
from ultralytics import YOLO
# Load a model
model = YOLO("yolo26n-cls.pt") # load a pretrained model (recommended for training)
# Train the model
results = model.train(data="mnist", epochs=100, imgsz=28)
```
=== "CLI"
```bash
# Start training from a pretrained *.pt model
yolo classify train data=mnist model=yolo26n-cls.pt epochs=100 imgsz=28
```
!!! tip "Quick tests with MNIST160"
Ultralytics also exposes `data="mnist160"`, a 160-image slice containing the first eight images of each digit (0–9) from both the train and test splits. It mirrors the MNIST directory structure, so you can swap datasets without changing any other arguments — ideal for CI pipelines or sanity checks before committing to the full 70,000-image dataset.
=== "CLI"
```bash
yolo classify train data=mnist160 model=yolo26n-cls.pt epochs=5 imgsz=28
```
Sample images from the MNIST dataset:
The samples show the range of handwriting styles the dataset captures across the 10 digit classes.
If you use the MNIST dataset in your research or development work, please cite the following paper:
!!! quote ""
=== "BibTeX"
```bibtex
@article{lecun2010mnist,
title={MNIST handwritten digit database},
author={LeCun, Yann and Cortes, Corinna and Burges, CJ},
journal={ATT Labs [Online]},
volume={2},
year={2010}
}
```
We would like to acknowledge Yann LeCun, Corinna Cortes, and Christopher J.C. Burges for creating and maintaining the MNIST dataset as a valuable resource for the machine learning and computer vision research community. For more information about the MNIST dataset and its creators, visit the MNIST dataset website.
The MNIST dataset is a benchmark of 70,000 28x28 grayscale images of handwritten digits, split into 60,000 training and 10,000 test images across the 10 classes 0–9. It is the standard reference for evaluating image classification algorithms — its small, uniform format lets researchers and engineers compare methods and track progress with minimal setup, which is why it remains a common first benchmark in machine learning.
MNIST has 10 classes — the handwritten digits 0 through 9 — and 70,000 grayscale images in total, each 28x28 pixels. It ships with a predefined split of 60,000 training and 10,000 test images, with a roughly even number of examples per digit.
To train an Ultralytics YOLO model on MNIST, use the code snippets below. The dataset downloads automatically on first use. For a detailed list of available training arguments, refer to the Training page.
!!! example "Train Example"
=== "Python"
```python
from ultralytics import YOLO
# Load a model
model = YOLO("yolo26n-cls.pt") # load a pretrained model (recommended for training)
# Train the model
results = model.train(data="mnist", epochs=100, imgsz=28)
```
=== "CLI"
```bash
# Start training from a pretrained *.pt model
yolo classify train data=mnist model=yolo26n-cls.pt epochs=100 imgsz=28
```
MNIST ships with a predefined split of 60,000 training images and 10,000 test images. Unlike folder-based classification datasets that Ultralytics splits automatically, MNIST's official partition is used as-is, and the test set serves as the validation split during training by default.
The MNIST dataset contains only handwritten digits, whereas the Extended MNIST (EMNIST) dataset includes both digits and uppercase and lowercase letters. EMNIST was developed as a successor to MNIST and uses the same 28x28 pixel format, making it compatible with tools and models designed for the original MNIST dataset. This broader range of characters makes EMNIST useful for a wider variety of machine learning applications.
Yes. Ultralytics Platform lets you upload datasets, train image classification models, and deploy them without extensive coding. It is a convenient way to run MNIST experiments in the cloud — see the classification datasets overview for related options.
MNIST is simpler than many modern datasets like CIFAR-10 or ImageNet, making it ideal for beginners and quick experimentation. While more complex datasets offer greater challenges with color images and diverse object categories, MNIST remains valuable for its simplicity, small file size, and historical significance in the development of machine learning algorithms. For a harder drop-in replacement with the same structure, see Fashion-MNIST, which features clothing items instead of digits.