PaddlePaddle

 paddle.vision / datasets / Cifar100


Cifar100

class paddle.vision. Cifar100 [源代码]

Cifar-100 数据集的实现,数据集包含100中类别.

参数

  • transform (callable) - 图片数据的预处理,若未 None 即为不做预处理。默认值为None。

  • download (bool) - 是否自定下载数据集文件。默认为 True

返回

Cifar100数据集实例

代码示例


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)

此页内容是否对您有帮助