v2.6.0
Datasets ⭐
EXAMPLE CODE
MNIST
Load MNIST dataset in Python fast with one line of code. Stream MNIST while training models in PyTorch & TensorFlow. MNIST comprises 60 000 handwritten digits.
Visualization of the MNIST Test Dataset on the Activeloop Platform

MNIST dataset

What is MNIST Dataset?

The MNIST (Modified National Institute of Standards and Technology database) dataset contains a training set of 60,000 images and a test set of 10,000 images of handwritten digits. The handwritten digit images have been size-normalized and centered in a fixed size of 28×28 pixels. The MNIST digits dataset is often used by data scientists who want to try machine learning techniques and pattern recognition methods on real-world data while spending minimal effort on preprocessing and formatting.

Download MNIST Dataset in Python

Instead of downloading the MNIST dataset in Python, you can effortlessly load it in Python via our open-source package Hub with just one line of code.

Load MNIST Dataset Training Subset in Python

1
import hub
2
ds = hub.load("hub://activeloop/mnist-train")
Copied!

Load MNIST Dataset Testing Subset in Python

1
import hub
2
ds = hub.load("hub://activeloop/mnist-test")
Copied!

MNIST Dataset Structure

MNIST Data Fields

  • image: tensor containing the 28x28 image.
  • label: an integer between 0 and 9 representing the digit.

MNIST Data Splits

How to use MNIST Dataset with PyTorch and TensorFlow in Python

Train a model on MNIST dataset with PyTorch in Python

Let's use Hub's built-in PyTorch one-line dataloader to connect the data to the compute:
1
dataloader = ds.pytorch(num_workers=0, batch_size=4, shuffle=False)
Copied!

Train a model on MNIST dataset with TensorFlow in Python

1
dataloader = ds.tensorflow()
Copied!

MNIST Dataset Creation

Data Collection and Normalization Information
The original images from MNIST were size-normalized to fit a 20x20 pixel box, while the aspect ratio was preserved. As a result, the images contain grey levels (i.e., pixels don't simply have a value of black and white, but a level of greyness from 0 to 255) due to the anti-aliasing technique used by the normalization algorithm.
Next, the images were centered in a 28x28 pixel image by computing the center of mass of the pixels, and translating the image so as to position this point at the center of the 28x28 field.

Additional Information about MNIST Dataset

MNIST Dataset Description

  • Repository: N/A
  • Paper: Y. LeCun, L. Bottou, Y. Bengio and P. Haffner: Gradient-Based Learning Applied to Document Recognition, Proceedings of the IEEE, 86(11):2278-2324, November 1998
  • Point of Contact: http://yann.lecun.com/

MNIST Dataset Curators

Chris Burges, Corinna Cortes and Yann LeCun

MNIST Dataset Licensing Information

MNIST Dataset Citation Information

1
@article{lecun2010mnist,
2
title={MNIST handwritten digit database},
3
author={LeCun, Yann and Cortes, Corinna and Burges, CJ},
4
journal={ATT Labs [Online]. Available: http://yann.lecun.com/exdb/mnist},
5
volume={2},
6
year={2010}
7
}
Copied!

MNIST Dataset FAQs

What is the MNIST dataset for Python?

The MNIST dataset (Modified National Institute of Standards and Technology database) is one of the most popular datasets in machine learning. MNIST is a dataset of 60,000 square 28×28 pixel images of handwritten single digits between 0 and 9. The images are in grayscale format.

What is the MNIST dataset used for?

MNIST is used as a "hello world" example by data scientists worldwide. Typically, MNIST dataset is used as a benchmark dataset, or as a proof-of-concept for training and testing purposes in the field of machine learning.
How to download the MNIST dataset in Python?
You can load MNIST dataset fast with one line of code using the open-source package Activeloop Hub in Python. See detailed instructions on how to load MNIST dataset training subset or MNIST dataset testing subset in Python.

How can I use MNIST dataset in PyTorch or TensorFlow?

You can stream MNIST dataset while training a model in PyTorch or TensorFlow with one line of code using the open-source package Activeloop Hub in Python. See detailed instructions on how to train a model on MNIST dataset with PyTorch in Python or train a model on MNIST dataset with TensorFlow in Python.

Should I work with MNIST dataset in CSV?

No. CSV is not optimized for working with image data, especially for machine learning workflows. Instead of downloading MNIST dataset CSV, you easily load, version-control, query, and manipulate MNIST for machine learning purposes using Activeloop Hub.

How to create an Image Dataset like MNIST dataset?

With Activeloop Hub, creating image datasets like the MNIST digits dataset is simple. Simple datasets like MNIST can be created automatically by allowing Hub parse the legacy files into Hub dataset format. More complex datasets can be created manually.

MNIST vs Fashion-MNIST. What is the difference between MNIST and Fashion-MNIST?

MNIST and Fashion-MNIST dataset are two separate datasets. However, the Fashion-MNIST dataset is meant to be an MNIST dataset alternative. Fashion-MNIST comprises pictures of clothing items and was published in 2017 by Zalando, a German online retailer. Both datasets are of the same size: 60 000 photos in the training set, as well as 10 000 pictures of clothing in the validation set of the dataset.

What is the size of each image in the MNIST dataset?

MNIST dataset image size is constant across all images of the dataset. Each MNIST dataset image is a fixed-size 28×28 pixel square image.