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) – path to data file, can be set None if
download
is True. Default None, default data path: ~/.cache/paddle/dataset/cifarmode (str) – ‘train’, ‘test’ mode. Default ‘train’.
transform (callable) – transform to perform on image, None for no transform.
download (bool) – download dataset automatically if
data_file
is None. Default Truebackend (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
-
instance of cifar-100 dataset
- Return type
-
Dataset
Examples
import paddle import paddle.nn as nn from paddle.vision.datasets import Cifar100 from paddle.vision.transforms import Normalize class SimpleNet(paddle.nn.Layer): def __init__(self): super(SimpleNet, self).__init__() self.fc = nn.Sequential( nn.Linear(3072, 10), nn.Softmax()) def forward(self, image, label): image = paddle.reshape(image, (1, -1)) return self.fc(image), label normalize = Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5], data_format='HWC') cifar100 = Cifar100(mode='train', transform=normalize) for i in range(10): image, label = cifar100[i] image = paddle.to_tensor(image) label = paddle.to_tensor(label) model = SimpleNet() image, label = model(image, label) print(image.numpy().shape, label.numpy().shape)