Keras datasets
MNIST is a classic handwritten-digit classification dataset.
The Classification Task
MNIST is a classic handwritten-digit classification dataset. It gives a neural-network example a concrete problem: receive an image of a handwritten digit and place that image into one of ten categories, from 0 through 9.
The central relationship is image to digit category. The image is the input, and the corresponding digit label identifies the category that the classifier should associate with that image.
Inside One Digit Image
Each MNIST image is grayscale and has dimensions of 28 × 28 pixels. The image is therefore represented as a rectangular arrangement of pixel positions. Each position contributes grayscale information about the handwritten digit shown in the image.
The important idea is that the classifier does not begin with the written character as a human-readable symbol. It begins with the image representation: a 28-by-28 grayscale arrangement. The visual pattern across those pixel positions is the information used for the digit-classification problem.
Matching Images to Labels
Every image has a corresponding digit label. The label is the category associated with that image, and the possible categories are 0 through 9. This pairing lets the classification example relate a visual input to the digit category it represents.
Tracing One Image and Its Category
Suppose a single MNIST example contains a 28 × 28 grayscale image of a handwritten digit and its corresponding label.
- 1Read the image
Treat the example's image as the input: a 28 × 28 arrangement of grayscale pixel information.
- 2Read the label
Treat the paired label as the correct digit category for that image. The category is one of 0 through 9.
- 3Connect the pair
Keep the image and its corresponding label together conceptually. The label tells the classification example which digit category belongs to that image.
One MNIST example is understood as an image-label pair: a grayscale handwritten-digit image connected to one digit category.
Four Dataset Outputs
The dataset is divided into training and test images, with corresponding labels. This creates four named roles: training images, training labels, test images, and test labels. The image collections contain the grayscale digit images, while the label collections contain the digit categories associated with those images.
| Collection | Contains | Role in the example |
|---|---|---|
| Training images | Grayscale handwritten-digit images | Part of the training data |
| Training labels | Digit categories corresponding to training images | Labels for the training data |
| Test images | Grayscale handwritten-digit images | Part of the test data |
| Test labels | Digit categories corresponding to test images | Labels for the test data |
The four MNIST collections separate images from labels and training data from test data.
Keras Data Access
Keras and the MNIST dataset provide a concrete starting point for seeing how a neural network can be used for handwritten-digit classification. Keras supplies MNIST in a form that separates the images from their corresponding labels and separates training data from test data.
The dataset-loading part of the example establishes the data source. It does not yet show the complete construction of the neural network. Its immediate job is to make the MNIST images and their labels available in their training and test roles.
Mistakes to Avoid
Common mistake Treating an MNIST image as a digit label
What it looks likeCalling the 28 × 28 grayscale image itself the category 7
Why it failsThe image is the input representation, while the corresponding label identifies one category from 0 through 9.
Do this insteadKeep the image and its corresponding digit label conceptually separate.
Common mistake Forgetting that each image has a corresponding label
What it looks likeDiscussing the image collection without considering the label collection
Why it failsClassification requires the relationship between a visual input and the digit category associated with it.
Do this insteadTrace each image together with its corresponding label.
Common mistake Confusing training collections with test collections
What it looks likeUsing one name for all four outputs
Why it failsKeras provides separate training images, training labels, test images, and test labels.
Do this insteadIdentify both dimensions of the organization: image versus label, and training versus test.
Common mistake Assuming the dataset-loading step is the whole neural network
What it looks likeExpecting access to MNIST to show the complete network construction
Why it failsThe dataset access establishes the data source; the complete neural-network construction is not shown at this stage.
Do this insteadUnderstand dataset access as the step that supplies data to the later neural-network workflow.
Check Your Understanding
A Keras-based handwritten-digit example receives an MNIST image. Describe the image representation, state the possible category labels, and name the four dataset collections that organize images and labels into training and test data.
Hints
- Start with the image dimensions and grayscale representation.
- The category set contains ten digit values.
- List one image collection and one label collection for training, then repeat for test.
What do you think happens?
Before looking at the dataset organization, predict whether Keras provides one combined collection or separate collections for images, labels, training data, and test data.
Reveal answer
Separate image and label collections, divided into training and test data
The MNIST data is organized as training images, training labels, test images, and test labels.
Key Takeaways
- 1MNIST is a classic dataset for handwritten-digit classification.
- 2Each image is grayscale and represented with dimensions of 28 × 28 pixels.
- 3The classifier places an image into one of ten digit categories, from 0 through 9.
- 4Images and their corresponding labels are separated into training and test collections.
- 5Keras supplies MNIST as a data source for a neural-network example; the dataset-access step comes before the complete neural-network construction.
At a glance
- MNIST contains grayscale handwritten-digit images for a ten-category classification problem.
- Each image has 28 × 28 pixels and is paired with a digit label from 0 through 9.
- The dataset separates training images, training labels, test images, and test labels.
- Keras provides access to MNIST so it can supply data to a neural-network classification example.