VOC2012

class paddle.vision.datasets. VOC2012 ( data_file=None, mode='train', transform=None, download=True, backend=None ) [source]

Implementation of VOC2012 dataset

To speed up the download, we put the data on https://dataset.bj.bcebos.com/voc/VOCtrainval_11-May-2012.tar. Original data can get from http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar.

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

  • mode (str) – ‘train’, ‘valid’ or ‘test’ mode. Default ‘train’.

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

Examples

import paddle
from paddle.vision.datasets import VOC2012
from paddle.vision.transforms import Normalize

class SimpleNet(paddle.nn.Layer):
    def __init__(self):
        super(SimpleNet, self).__init__()

    def forward(self, image, label):
        return paddle.sum(image), label


normalize = Normalize(mean=[0.5, 0.5, 0.5],
                      std=[0.5, 0.5, 0.5],
                      data_format='HWC')
voc2012 = VOC2012(mode='train', transform=normalize, backend='cv2')

for i in range(10):
    image, label= voc2012[i]
    image = paddle.cast(paddle.to_tensor(image), 'float32')
    label = paddle.to_tensor(label)

    model = SimpleNet()
    image, label= model(image, label)
    print(image.numpy().shape, label.numpy().shape)