Flowers¶
- class paddle.vision.datasets. Flowers ( data_file=None, label_file=None, setid_file=None, mode='train', transform=None, download=True, backend=None ) [源代码] ¶
Flowers102 数据集的实现。
参数¶
data_file (str,可选) - 数据文件路径,如果
download
参数设置为True
,data_file
参数可以设置为None
。默认值为None
,默认存放在:~/.cache/paddle/dataset/flowers
。label_file (str,可选) - 标签文件路径,如果
download
参数设置为True
,label_file
参数可以设置为None
。默认值为None
,默认存放在:~/.cache/paddle/dataset/flowers
。setid_file (str,可选) - 子数据集下标划分文件路径,如果
download
参数设置为True
,setid_file
参数可以设置为None
。默认值为None
,默认存放在:~/.cache/paddle/dataset/flowers
。mode (str,可选) -
'train'
或'test'
模式两者之一,默认值为'train'
。transform (Callable,可选) - 图片数据的预处理,若为
None
即为不做预处理。默认值为None
。download (bool,可选) - 当
data_file
是None
时,该参数决定是否自动下载数据集文件。默认值为True
。backend (str,可选) - 指定要返回的图像类型:PIL.Image 或 numpy.ndarray。必须是 {'pil','cv2'} 中的值。如果未设置此选项,将从 paddle.vision.get_image_backend 获得这个值。默认值为
None
。
代码示例¶
>>> import itertools
>>> import paddle.vision.transforms as T
>>> from paddle.vision.datasets import Flowers
>>> flowers = Flowers()
>>> print(len(flowers))
6149
>>> for i in range(5): # only show first 5 images
... img, label = flowers[i]
... # do something with img and label
... print(type(img), img.size, label)
... # <class 'PIL.JpegImagePlugin.JpegImageFile'> (523, 500) [1]
>>> 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,
... ),
... ]
... )
>>> flowers_test = Flowers(
... mode="test",
... transform=transform, # apply transform to every image
... backend="cv2", # use OpenCV as image transform backend
... )
>>> print(len(flowers_test))
1020
>>> for img, label in itertools.islice(iter(flowers_test), 5): # only show first 5 images
... # do something with img and label
... print(type(img), img.shape, label)
... # <class 'paddle.Tensor'> [3, 64, 96] [1]