What is the Fashion MNIST dataset in Keras?

The Fashion MNISTModified National Institute of Standards and Technology dataset is an alternative to the standard MNIST dataset in Keras.

What is the dataset about?

Instead of handwritten digits, it contains 70000 28x28 grayscale images of ten types of fashion items.

Training and test datasets

The training set has 60,000 images while the test set has 10,000. This dataset has been widely used in deep learning as it has been standardized and can represent modern computer vision tasks.

Fashion categories

The fashion categories are as follows.

Category

Label

Top/T-shirt

0

Trouser

1

Pullover

2

Dress

3

Coat

4

Sandal

5

Shirt

6

Sneaker

7

Bag

8

Ankle Boot

9

The load_data() function

The load_data() function is used to load the dataset from Keras.

tf.keras.datasets.fashion_mnist.load_data(path='fmnist.npz')

Arguments

  • path: the relative path where to cache the dataset locally. This parameter is optional.

Return value

It returns two tuples with NumPy arrays. The tuples are in the form (X_train, y_train), (X_test, y_test).

  • X_train: Training data that consists of grayscale images. It has the shape (60000, 28, 28) and the dtypeRepresents the type of the elements in a Tensor. of uint8. The pixel values vary from 0 to 255.

  • y_train: Training labels that consist of integers from 0-9 with the dtype of uint8. Each label corresponds to a fashion category. It has the shape (60000,).

  • X_test: Testing data that consists of grayscale images. It has the shape (10000, 28, 28) and dtype of uint8. The pixel values vary from 0 to 255.

  • y_test: Testing labels that consist of integers from 0-9 with the dtype of uint8. Each label corresponds to a fashion category. It has the shape (10000,).

Code

import tensorflow as tf
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()
print('Shape of X_train: ', X_train.shape)
print('Shape of y_train: ', y_train.shape)
print('Shape of X_test: ', X_test.shape)
print('Shape of y_test: ', y_test.shape)

Free Resources