def load_voc(self, dataset_dir, trainval, year='2012'):
    "Load a voc_year of the VOC dataset.\n        dataset_dir: The root directory of the VOC dataset, example: '/mnt/disk1/VOCdevkit'\n        trainval: 'train' or 'val' for Training or Validation\n        year: '2007' or '2012' for VOC dataset\n        "
    voc_year = ('VOC' + year)
    Segmentation = os.path.join(dataset_dir, voc_year, 'ImageSets', 'Segmentation')
    JPEGImages = os.path.join(dataset_dir, voc_year, 'JPEGImages')
    Annotations = os.path.join(dataset_dir, voc_year, 'Annotations')
    SegmentationClass = os.path.join(dataset_dir, voc_year, 'SegmentationClass')
    SegmentationObject = os.path.join(dataset_dir, voc_year, 'SegmentationObject')
    for (idx, class_name) in enumerate(VOC_CLASSES[1:]):
        self.add_class('voc', (idx + 1), class_name)
    assert (trainval in ['train', 'val'])
    annotation_file = os.path.join(Segmentation, (trainval + '.txt'))
    image_ids = []
    with open(annotation_file) as f:
        image_id_list = [line.strip() for line in f]
        image_ids += image_id_list
    for image_id in image_ids:
        image_file_name = '{}.jpg'.format(image_id)
        mask_file_name = '{}.png'.format(image_id)
        xml_file_name = '{}.xml'.format(image_id)
        image_path = os.path.join(JPEGImages, image_file_name)
        with open(os.path.join(Annotations, xml_file_name)) as f:
            soup = bs(f, 'lxml')
        objects = soup.find_all('object')
        image_contains_class_flag = False
        for obj in objects:
            class_name = obj.find('name').text
            if (class_name in VOC_CLASSES):
                image_contains_class_flag = True
                continue
        if image_contains_class_flag:
            class_mask_path = os.path.join(SegmentationClass, mask_file_name)
            object_mask_path = os.path.join(SegmentationObject, mask_file_name)
            self.add_image('voc', image_id=image_file_name, path=image_path, class_mask_path=class_mask_path, object_mask_path=object_mask_path)
Load a voc_year of the VOC dataset.
dataset_dir: The root directory of the VOC dataset, example: '/mnt/disk1/VOCdevkit'
trainval: 'train' or 'val' for Training or Validation
year: '2007' or '2012' for VOC dataset
def load_voc(self, dataset_dir, trainval, year='2012'):
    "Load a voc_year of the VOC dataset.\n        dataset_dir: The root directory of the VOC dataset, example: '/mnt/disk1/VOCdevkit'\n        trainval: 'train' or 'val' for Training or Validation\n        year: '2007' or '2012' for VOC dataset\n        "
    voc_year = ('VOC' + year)
    Segmentation = os.path.join(dataset_dir, voc_year, 'ImageSets', 'Segmentation')
    JPEGImages = os.path.join(dataset_dir, voc_year, 'JPEGImages')
    Annotations = os.path.join(dataset_dir, voc_year, 'Annotations')
    SegmentationClass = os.path.join(dataset_dir, voc_year, 'SegmentationClass')
    SegmentationObject = os.path.join(dataset_dir, voc_year, 'SegmentationObject')
    for (idx, class_name) in enumerate(VOC_CLASSES[1:]):
        self.add_class('voc', (idx + 1), class_name)
    assert (trainval in ['train', 'val'])
    annotation_file = os.path.join(Segmentation, (trainval + '.txt'))
    image_ids = []
    with open(annotation_file) as f:
        image_id_list = [line.strip() for line in f]
        image_ids += image_id_list
    for image_id in image_ids:
        image_file_name = '{}.jpg'.format(image_id)
        mask_file_name = '{}.png'.format(image_id)
        xml_file_name = '{}.xml'.format(image_id)
        image_path = os.path.join(JPEGImages, image_file_name)
        with open(os.path.join(Annotations, xml_file_name)) as f:
            soup = bs(f, 'lxml')
        objects = soup.find_all('object')
        image_contains_class_flag = False
        for obj in objects:
            class_name = obj.find('name').text
            if (class_name in VOC_CLASSES):
                image_contains_class_flag = True
                continue
        if image_contains_class_flag:
            class_mask_path = os.path.join(SegmentationClass, mask_file_name)
            object_mask_path = os.path.join(SegmentationObject, mask_file_name)
            self.add_image('voc', image_id=image_file_name, path=image_path, class_mask_path=class_mask_path, object_mask_path=object_mask_path)