VOC2012¶
- class paddle.vision.datasets. VOC2012 ( data_file=None, mode='train', transform=None, download=True, backend=None ) [source]
- 
         Implementation of VOC2012 dataset. - Parameters
- 
           - data_file (str, optional) – Path to data file, can be set None if - downloadis True. Default: None, default data path: ~/.cache/paddle/dataset/voc2012.
- mode (str, optional) – Either train or test mode. Default ‘train’. 
- transform (Callable, optional) – Transform to perform on image, None for no transform. Default: None. 
- download (bool, optional) – Download dataset automatically if - data_fileis 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.vision.get_image_backend, default backend is ‘pil’. Default: None. 
 
- Returns
- 
           Dataset. An instance of VOC2012 dataset. 
 Examples import itertools import paddle.vision.transforms as T from paddle.vision.datasets import VOC2012 voc2012 = VOC2012() print(len(voc2012)) # 2913 for i in range(5): # only show first 5 images img, label = voc2012[i] # do something with img and label print(type(img), img.size) # <class 'PIL.JpegImagePlugin.JpegImageFile'> (500, 281) print(type(label), label.size) # <class 'PIL.PngImagePlugin.PngImageFile'> (500, 281) transform = T.Compose( [ T.ToTensor(), T.Normalize( mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5], to_rgb=True, ), ] ) voc2012_test = VOC2012( mode="test", transform=transform, # apply transform to every image backend="cv2", # use OpenCV as image transform backend ) print(len(voc2012_test)) # 1464 for img, label in itertools.islice(iter(voc2012_test), 5): # only show first 5 images # do something with img and label print(type(img), img.shape) # <class 'paddle.Tensor'> [3, 281, 500] print(type(label), label.shape) # <class 'numpy.ndarray'> (281, 500) 
