class Cifar100 ( data_file=None, mode='train', transform=None, download=True, backend=None ) [source]

Implementation of Cifar-100 dataset, which has 100 categories.

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

  • mode (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 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.


instance of cifar-100 dataset

Return type



import paddle
import paddle.nn as nn
from import Cifar100
from import Normalize

class SimpleNet(paddle.nn.Layer):
    def __init__(self):
        super(SimpleNet, self).__init__()
        self.fc = nn.Sequential(
            nn.Linear(3072, 10),

    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],
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)