예제 #1
0
def register_dataset_instance(image_dir,
                              gt_dir,
                              splits=["train", "val"],
                              dataset_name="cityscapes",
                              from_json=True):
    for split in splits:
        # use Cityscapes annotation format as metadata
        # CITYSCAPES_THING_CLASSES = ["person", "rider", "car", "truck", "bus", "train", "motorcycle", "bicycle"]
        meta = builtin_meta._get_builtin_metadata("cityscapes")

        dataset_instance_name = str(dataset_name) + "_instance_" + str(split)
        image_split_dir = os.path.join(image_dir, split)
        gt_split_dir = os.path.join(gt_dir, split)
        # from_json = True if ground truth json annotation file is available
        DatasetCatalog.register(
            dataset_instance_name,
            lambda x=image_split_dir, y=gt_split_dir:
            load_cityscapes_instances(
                x, y, from_json=from_json, to_polygons=True))
        MetadataCatalog.get(dataset_instance_name).set(
            image_dir=image_split_dir,
            gt_dir=gt_split_dir,
            evaluator_type="cityscapes_instance",
            **meta)
        print("finish registering {} to DatasetCatalog.".format(
            dataset_instance_name))
예제 #2
0
def register_all_cityscapes(root):
    for key, (image_dir, gt_dir) in _RAW_CITYSCAPES_SPLITS.items():
        meta = _get_builtin_metadata("cityscapes")
        image_dir = os.path.join(root, image_dir)
        gt_dir = os.path.join(root, gt_dir)

        inst_key = key.format(task="instance_seg")
        DatasetCatalog.register(
            inst_key,
            lambda x=image_dir, y=gt_dir: load_cityscapes_instances(
                x, y, from_json=True, to_polygons=True),
        )
        MetadataCatalog.get(inst_key).set(image_dir=image_dir,
                                          gt_dir=gt_dir,
                                          evaluator_type="cityscapes",
                                          **meta)

        sem_key = key.format(task="sem_seg")
        DatasetCatalog.register(
            sem_key,
            lambda x=image_dir, y=gt_dir: load_cityscapes_semantic(x, y))
        MetadataCatalog.get(sem_key).set(image_dir=image_dir,
                                         gt_dir=gt_dir,
                                         evaluator_type="sem_seg",
                                         **meta)
예제 #3
0
def register_a_cityscapes(image_dir, gt_dir, dataset_name):
    meta = _get_builtin_metadata("cityscapes")
    DatasetCatalog.register(
        dataset_name,
        lambda x=image_dir, y=gt_dir: load_cityscapes_instances(
            x, y, from_json=True, to_polygons=True),
    )
    MetadataCatalog.get(dataset_name).set(image_dir=image_dir,
                                          gt_dir=gt_dir,
                                          evaluator_type="cityscapes",
                                          **meta)