MNIST

class paddle.vision.datasets. MNIST ( image_path=None, label_path=None, mode='train', transform=None, download=True, backend=None ) [source]

Implementation of MNIST dataset

Parameters
  • image_path (str) – path to image file, can be set None if download is True. Default None, default data path: ~/.cache/paddle/dataset/mnist

  • label_path (str) – path to label file, can be set None if download is True. Default None, default data path: ~/.cache/paddle/dataset/mnist

  • mode (str) – ‘train’ or ‘test’ mode. Default ‘train’.

  • download (bool) – download dataset automatically if image_path label_path is not set. Default True

  • backend (str, optional) – Specifies which type of image to be returned: PIL.Image or numpy.ndarray. Should be one of {‘pil’, ‘cv2’}. If this option is not set, will get backend from paddle.vsion.get_image_backend , default backend is ‘pil’. Default: None.

Returns

MNIST Dataset.

Return type

Dataset

Examples

from paddle.vision.datasets import MNIST

mnist = MNIST(mode='test')

for i in range(len(mnist)):
    sample = mnist[i]
    print(sample[0].size, sample[1])

Used in the guide/tutorials