Cifar100
class paddle.vision.datasets.Cifar100
[源代码]
Cifar-100 数据集的实现,数据集包含100种类别.
参数
data_file (str) - 数据集文件路径,如果
download
参数设置为True
,data_file
参数可以设置为None
。默认值为None
,默认存放在:~/.cache/paddle/dataset/cifar
mode (str) -
'train'
或'test'
模式,默认为'train'
。transform (callable) - 图片数据的预处理,若为
None
即为不做预处理。默认值为None
。download (bool) - 当
data_file
是None
时,该参数决定是否自动下载数据集文件。默认为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)