Cifar100¶
- class paddle.vision.datasets. Cifar100 ( data_file=None, mode='train', transform=None, download=True, backend=None ) [source]
-
Implementation of Cifar-100 dataset, which has 100 categories.
- Parameters
-
data_file (str, optional) – path to data file, can be set None if
download
is True. Default: None, default data path: ~/.cache/paddle/dataset/cifarmode (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) – download dataset automatically if
data_file
is None. 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 Cifar100 dataset.
Examples
>>> >>> import itertools >>> import paddle.vision.transforms as T >>> from paddle.vision.datasets import Cifar100 >>> cifar100 = Cifar100() >>> print(len(cifar100)) 50000 >>> for i in range(5): # only show first 5 images ... img, label = cifar100[i] ... # do something with img and label ... print(type(img), img.size, label) ... # <class 'PIL.Image.Image'> (32, 32) 19 >>> transform = T.Compose( ... [ ... T.Resize(64), ... T.ToTensor(), ... T.Normalize( ... mean=[0.5, 0.5, 0.5], ... std=[0.5, 0.5, 0.5], ... to_rgb=True, ... ), ... ] ... ) >>> cifar100_test = Cifar100( ... mode="test", ... transform=transform, # apply transform to every image ... backend="cv2", # use OpenCV as image transform backend ... ) >>> print(len(cifar100_test)) 10000 >>> for img, label in itertools.islice(iter(cifar100_test), 5): # only show first 5 images ... # do something with img and label ... print(type(img), img.shape, label) ... # <class 'paddle.Tensor'> [3, 64, 64] 49