Example #1
0
    def __init__(self,
                 image_sets,
                 flip=False,
                 proposal_files=None,
                 phase='train',
                 result_path=''):

        super(coco, self).__init__()

        image_dirs = {
            'train2014':
            os.path.join(config.dataset.dataset_path, 'coco_train2014'),
            'val2014':
            os.path.join(config.dataset.dataset_path, 'coco_val2014'),
            'minival2014':
            os.path.join(config.dataset.dataset_path, 'coco_val2014'),
            'valminusminival2014':
            os.path.join(config.dataset.dataset_path, 'coco_val2014'),
            'test2015':
            os.path.join(config.dataset.dataset_path, 'coco_test2015'),
            'test-dev2015':
            os.path.join(config.dataset.dataset_path, 'coco_test2015'),
            'train2017':
            os.path.join(config.dataset.dataset_path, 'images', 'train2017'),
            'val2017':
            os.path.join(config.dataset.dataset_path, 'images', 'val2017'),
            'test-dev2017':
            os.path.join(config.dataset.dataset_path, 'images', 'test2017'),
        }

        anno_files = {
            'train2014': 'instances_train2014.json',
            'val2014': 'instances_val2014.json',
            'minival2014': 'instances_minival2014.json',
            'valminusminival2014': 'instances_valminusminival2014.json',
            'test2015': 'image_info_test2015.json',
            'test-dev2015': 'image_info_test-dev2015.json',
            'train2017': 'instances_train2017.json',
            'val2017': 'instances_val2017.json',
            'test-dev2017': 'image_info_test-dev2017.json',
        }

        if image_sets[0] == 'test-dev2017':
            self.panoptic_json_file = os.path.join(
                config.dataset.dataset_path, 'annotations',
                'image_info_test-dev2017.json')
        else:
            self.panoptic_json_file = os.path.join(
                config.dataset.dataset_path, 'annotations',
                'panoptic_val2017_stff.json')
            self.panoptic_gt_folder = os.path.join(config.dataset.dataset_path,
                                                   'annotations',
                                                   'panoptic_val2017')

        if proposal_files is None:
            proposal_files = [None] * len(image_sets)

        if phase == 'train' and len(image_sets) > 1:
            # combine multiple datasets
            roidbs = []
            for image_set, proposal_file in zip(image_sets, proposal_files):
                dataset = JsonDataset('coco_' + image_set,
                                      image_dir=image_dirs[image_set],
                                      anno_file=os.path.join(
                                          config.dataset.dataset_path,
                                          'annotations',
                                          anno_files[image_set]))
                roidb = dataset.get_roidb(
                    gt=True,
                    proposal_file=proposal_file,
                    crowd_filter_thresh=config.train.crowd_filter_thresh)
                if flip:
                    if logger:
                        logger.info(
                            'Appending horizontally-flipped training examples...'
                        )
                    extend_with_flipped_entries(roidb, dataset)
                roidbs.append(roidb)
            roidb = roidbs[0]
            for r in roidbs[1:]:
                roidb.extend(r)
            roidb = filter_for_training(roidb)
            add_bbox_regression_targets(roidb)

        else:
            assert len(image_sets) == 1
            self.dataset = JsonDataset('coco_' + image_sets[0],
                                       image_dir=image_dirs[image_sets[0]],
                                       anno_file=os.path.join(
                                           config.dataset.dataset_path,
                                           'annotations',
                                           anno_files[image_sets[0]]))
            roidb = self.dataset.get_roidb(
                gt=True,
                proposal_file=proposal_files[0],
                crowd_filter_thresh=config.train.crowd_filter_thresh
                if phase != 'test' else 0)
            if flip:
                if logger:
                    logger.info(
                        'Appending horizontally-flipped training examples...')
                extend_with_flipped_entries(roidb, self.dataset)
            if phase != 'test':
                roidb = filter_for_training(roidb)
                add_bbox_regression_targets(roidb)

        self.roidb = roidb
        self.phase = phase
        self.flip = flip
        self.result_path = result_path
        self.num_classes = 81
Example #2
0
    def __init__(self,
                 image_sets,
                 flip=False,
                 proposal_files=None,
                 phase='train',
                 result_path=''):

        super(Cityscapes, self).__init__()

        self.image_dirs = {
            'train': os.path.join(config.dataset.dataset_path, 'images'),
            'val': os.path.join(config.dataset.dataset_path, 'images'),
            'test': os.path.join(config.dataset.dataset_path, 'images'),
            'train_extra': os.path.join(config.dataset.dataset_path, 'images'),
            'debug': os.path.join(config.dataset.dataset_path, 'images'),
        }

        self.anno_files = {
            'train': 'instancesonly_gtFine_train.json',
            'val': 'instancesonly_gtFine_val.json',
            'test': 'image_info_test.json',
            'train_extra': 'instancesonly_gtCoarse_train_extra.json',
            'debug': 'instancesonly_gtFine_debug.json',
        }

        self.panoptic_json_file = os.path.join(config.dataset.dataset_path,
                                               'annotations',
                                               'cityscapes_fine_val.json')
        self.panoptic_gt_folder = 'data/cityscapes/panoptic'

        self.flip = flip
        self.result_path = result_path
        self.num_classes = 9
        self.phase = phase
        self.image_sets = image_sets

        if image_sets[0] == 'demoVideo':
            assert len(image_sets) == 1
            assert phase == 'test'
            im_path = [
                _.strip()
                for _ in open('data/cityscapes/split/demoVideo_img.txt',
                              'r').readlines()
            ]
            self.roidb = [{'image': _, 'flipped': False} for _ in im_path]
            return

        if proposal_files is None:
            proposal_files = [None] * len(image_sets)

        if phase == 'train' and len(image_sets) > 1:
            # combine multiple datasets
            roidbs = []
            for image_set, proposal_file in zip(image_sets, proposal_files):
                dataset = JsonDataset('cityscapes_' + image_set,
                                      image_dir=self.image_dirs[image_set],
                                      anno_file=os.path.join(
                                          config.dataset.dataset_path,
                                          'annotations',
                                          self.anno_files[image_set]))
                roidb = dataset.get_roidb(
                    gt=True,
                    proposal_file=proposal_file,
                    crowd_filter_thresh=config.train.crowd_filter_thresh)
                if flip:
                    if logger:
                        logger.info(
                            'Appending horizontally-flipped training examples...'
                        )
                    extend_with_flipped_entries(roidb, dataset)
                roidbs.append(roidb)
            roidb = roidbs[0]
            for r in roidbs[1:]:
                roidb.extend(r)
            roidb = filter_for_training(roidb)
            add_bbox_regression_targets(roidb)

        else:
            assert len(image_sets) == 1
            self.dataset = JsonDataset(
                'cityscapes_' + image_sets[0],
                image_dir=self.image_dirs[image_sets[0]],
                anno_file=os.path.join(config.dataset.dataset_path,
                                       'annotations',
                                       self.anno_files[image_sets[0]]))
            roidb = self.dataset.get_roidb(
                gt=True,
                proposal_file=proposal_files[0],
                crowd_filter_thresh=config.train.crowd_filter_thresh
                if phase != 'test' else 0)
            if flip:
                if logger:
                    logger.info(
                        'Appending horizontally-flipped training examples...')
                extend_with_flipped_entries(roidb, self.dataset)
            if phase != 'test':
                roidb = filter_for_training(roidb)
                add_bbox_regression_targets(roidb)

        self.roidb = roidb