Concepts / Keras datasets

Keras datasets

MNIST is a classic handwritten-digit classification dataset.

  • Programming

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.

Key point

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.

Handwritten images28 × 28 grayscale pixelsDigit classifierone of ten categoriesDigit labels0 through 9inputcorrect category
What kinds of examples and labels make up the MNIST handwritten-digit dataset?

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.

Digit image28 × 28 pixelsPixel rowpositions across the imagePixel positiongrayscale valueDigit shapevisual patterncontainscontainscontributes to
What does one handwritten digit look like as data, and how do its pixel positions and grayscale values represent 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.

Image A28 × 28 grayscale pixelsDigit labelone category from 0 through9Image B28 × 28 grayscale pixelsDigit labelone category from 0 through9corresponds tocorresponds to
How does each image connect to the correct digit label used for classification?
Worked example

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.

  1. 1
    Read the image

    Treat the example's image as the input: a 28 × 28 arrangement of grayscale pixel information.

  2. 2
    Read the label

    Treat the paired label as the correct digit category for that image. The category is one of 0 through 9.

  3. 3
    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.

Result

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.

Training imageshandwritten digit imagesTest imageshandwritten digit imagesNeural-networkexampleclassification workflowTraining labelscorresponding digitcategoriesTest labelscorresponding digitcategoriestraining inputtraining categoriestest inputtest categories
What is contained in each of the four MNIST outputs, and how are the training and test sets used differently?
CollectionContainsRole in the example
Training imagesGrayscale handwritten-digit imagesPart of the training data
Training labelsDigit categories corresponding to training imagesLabels for the training data
Test imagesGrayscale handwritten-digit imagesPart of the test data
Test labelsDigit categories corresponding to test imagesLabels 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.

Kerasdataset accessMNISThandwritten digitsTraining dataimages and labelsNeural-networkexampledigit classificationTest dataimages and labelsprovides access toseparatesseparatessupplies training collectionssupplies test collections
How does Keras provide access to MNIST for a neural-network example?
Key point

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 like

    Calling the 28 × 28 grayscale image itself the category 7

    Why it fails

    The image is the input representation, while the corresponding label identifies one category from 0 through 9.

    Do this instead

    Keep the image and its corresponding digit label conceptually separate.

  • Common mistake

    Forgetting that each image has a corresponding label

    What it looks like

    Discussing the image collection without considering the label collection

    Why it fails

    Classification requires the relationship between a visual input and the digit category associated with it.

    Do this instead

    Trace each image together with its corresponding label.

  • Common mistake

    Confusing training collections with test collections

    What it looks like

    Using one name for all four outputs

    Why it fails

    Keras provides separate training images, training labels, test images, and test labels.

    Do this instead

    Identify 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 like

    Expecting access to MNIST to show the complete network construction

    Why it fails

    The dataset access establishes the data source; the complete neural-network construction is not shown at this stage.

    Do this instead

    Understand dataset access as the step that supplies data to the later neural-network workflow.

Check Your Understanding

EASY

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.

  • One combined collection only

  • Separate image and label collections, divided into training and test data

  • Only image collections, without labels

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

  1. 1
    MNIST is a classic dataset for handwritten-digit classification.
  2. 2
    Each image is grayscale and represented with dimensions of 28 × 28 pixels.
  3. 3
    The classifier places an image into one of ten digit categories, from 0 through 9.
  4. 4
    Images and their corresponding labels are separated into training and test collections.
  5. 5
    Keras 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.

Related concepts

More concepts starting with K