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.
Read the image: Treat the example's image as the input: a 28 × 28 arrangement of grayscale pixel information.
Read the label: Treat the paired label as the correct digit category for that image. The category is one of 0 through 9.
Connect 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
Treating an MNIST image as a digit label
The image is the input representation, while the corresponding label identifies one category from 0 through 9.
Fix:
Keep the image and its corresponding digit label conceptually separate.Forgetting that each image has a corresponding label
Classification requires the relationship between a visual input and the digit category associated with it.
Fix:
Trace each image together with its corresponding label.Confusing training collections with test collections
Keras provides separate training images, training labels, test images, and test labels.
Fix:
Identify both dimensions of the organization: image versus label, and training versus test.Assuming the dataset-loading step is the whole neural network
The dataset access establishes the data source; the complete neural-network construction is not shown at this stage.
Fix:
Understand 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
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
- MNIST is a classic dataset for handwritten-digit classification.
- Each image is grayscale and represented with dimensions of 28 × 28 pixels.
- The classifier places an image into one of ten digit categories, from 0 through 9.
- Images and their corresponding labels are separated into training and test collections.
- Keras supplies MNIST as a data source for a neural-network example; the dataset-access step comes before the complete neural-network construction.
Key Takeaways
- 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.