FashionMNIST¶
- class paddle.vision.datasets. FashionMNIST ( image_path=None, label_path=None, mode='train', transform=None, download=True, backend=None ) [source]
-
Implementation of Fashion-MNIST dataset.
- Parameters
-
image_path (str, optional) – Path to image file, can be set None if
download
is True. Default: None, default data path: ~/.cache/paddle/dataset/fashion-mnist.label_path (str, optional) – Path to label file, can be set None if
download
is True. Default: None, default data path: ~/.cache/paddle/dataset/fashion-mnist.mode (str, optional) – Either train or test mode. Default ‘train’.
transform (Callable, optional) – Transform to perform on image, None for no transform. Default: None.
download (bool, optional) – Whether to 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.vision.get_image_backend, default backend is ‘pil’. Default: None.
- Returns
-
Dataset. An instance of FashionMNIST dataset.
Examples
>>> import itertools >>> import paddle.vision.transforms as T >>> from paddle.vision.datasets import FashionMNIST >>> fashion_mnist = FashionMNIST() >>> print(len(fashion_mnist)) 60000 >>> for i in range(5): # only show first 5 images ... img, label = fashion_mnist[i] ... # do something with img and label ... print(type(img), img.size, label) ... # <class 'PIL.Image.Image'> (28, 28) [9] >>> transform = T.Compose( ... [ ... T.ToTensor(), ... T.Normalize( ... mean=[127.5], ... std=[127.5], ... ), ... ] ... ) >>> fashion_mnist_test = FashionMNIST( ... mode="test", ... transform=transform, # apply transform to every image ... backend="cv2", # use OpenCV as image transform backend ... ) >>> print(len(fashion_mnist_test)) 10000 >>> for img, label in itertools.islice(iter(fashion_mnist_test), 5): # only show first 5 images ... # do something with img and label ... print(type(img), img.shape, label) ... # <class 'paddle.Tensor'> [1, 28, 28] [9]