示例#1
0
 def _register_coco_2017_if_not_present(self, ):
     if 'coco_2017_train_copy' not in DatasetCatalog.keys():
         register_coco_instances(
             'coco_2017_train_copy', _get_builtin_metadata('coco'),
             "/scratch/ssd001/home/skhandel/FewshotDetection/WSASOD/data/data_utils/data/MSCOCO2017/annotations/instances_train2017.json",
             "/scratch/ssd001/home/skhandel/FewshotDetection/WSASOD/data/data_utils/data/MSCOCO2017/images/train2017/"
         )
     if 'coco_2017_val_copy' not in DatasetCatalog.keys():
         register_coco_instances(
             'coco_2017_val_copy', _get_builtin_metadata('coco'),
             "/scratch/ssd001/home/skhandel/FewshotDetection/WSASOD/data/data_utils/data/MSCOCO2017/annotations/instances_val2017.json",
             "/scratch/ssd001/home/skhandel/FewshotDetection/WSASOD/data/data_utils/data/MSCOCO2017/images/val2017/"
         )
示例#2
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))
示例#3
0
def register_all_coco_edge(root="datasets"):
    for name, (image_root, json_file, edge_root) in SPLITS_COCO_W_EDGE.items():
        # Assume pre-defined datasets live in `./datasets`.
        register_coco_edge_map(
            name, _get_builtin_metadata("coco"),
            os.path.join(root, image_root), os.path.join(root, edge_root),
            os.path.join(root, json_file)
            if "://" not in json_file else json_file)
示例#4
0
 def __init__(self, color_bgr=_COLOR_GREEN, r=5):
     self.color_bgr = color_bgr
     self.r = r
     self.metadata = _get_builtin_metadata("coco_person")
     # Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv.
     cmap = plt.get_cmap('rainbow')
     colors = [cmap(i) for i in np.linspace(0, 1, len(self.metadata['keypoint_connection_rules']) + 2)]
     self.colors = [(c[2] * 255, c[1] * 255, c[0] * 255) for c in colors]
示例#5
0
def register_all_coco(root):
    for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_COCO.items():
        for key, (image_root, json_file) in splits_per_dataset.items():
            # Assume pre-defined datasets live in `./datasets`.
            register_coco_instances(
                key,
                _get_builtin_metadata(dataset_name),
                os.path.join(root, json_file) if "://" not in json_file else json_file,
                os.path.join(root, image_root),
            )
示例#6
0
def register_cocodev(root="datasets"):
    for dataset_name, splits_per_dataset in COCODEV.items():
        for key, (image_root, json_file) in splits_per_dataset.items():
            # Assume pre-defined datasets live in `./datasets`.
            register_coco_instances(
                key,
                _get_builtin_metadata(dataset_name),
                os.path.join(root, json_file)
                if "://" not in json_file else json_file,
                os.path.join(root, image_root),
            )
示例#7
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
    )
示例#8
0
def _get_cityscapes_panoptic_meta(root):
    """Return metadata of the cityscapes panoptic segmentation dataset."""
    meta = _get_builtin_metadata("cityscapes")
    stuff_colors = [k["color"] for k in CITYSCAPES_CATEGORIES]
    thing_colors = [k["color"]
                    for k in CITYSCAPES_CATEGORIES if k["isthing"] == 1]
    panoptic_json = 'cityscapes/gtFine/cityscapes_panoptic_val.json'
    panoptic_root = 'cityscapes/gtFine/cityscapes_panoptic_val'
    ret = {"stuff_colors": stuff_colors, 'thing_colors': thing_colors,
           'panoptic_json': os.path.join(root, panoptic_json),
           'panoptic_root': os.path.join(root, panoptic_root)}
    meta.update(ret)
    return meta
示例#9
0
def register_rotated_coco(root):
    def _register(name, metadata, json_file, image_root):
        """
        Register a dataset in COCO's json annotation format for
        instance detection, instance segmentation and keypoint detection.
        (i.e., Type 1 and 2 in http://cocodataset.org/#format-data.
        `instances*.json` and `person_keypoints*.json` in the dataset).

        This is an example of how to register a new dataset.
        You can do something similar to this function, to register new datasets.

        Args:
            name (str): the name that identifies a dataset, e.g. "coco_2014_train".
            metadata (dict): extra metadata associated with this dataset.  You can
                leave it as an empty dict.
            json_file (str): path to the json instance annotation file.
            image_root (str or path-like): directory which contains all the images.
        """
        assert isinstance(name, str), name
        assert isinstance(json_file, (str, os.PathLike)), json_file
        assert isinstance(image_root, (str, os.PathLike)), image_root
        # 1. register a function which returns dicts
        DatasetCatalog.register(
            name, lambda: load_coco_json(json_file, image_root, name))

        # 2. Optionally, add metadata about this dataset,
        # since they might be useful in evaluation, visualization or logging
        MetadataCatalog.get(name).set(json_file=json_file,
                                      image_root=image_root,
                                      evaluator_type="rcoco",
                                      **metadata)

    SPLITS = {
        "rcoco_2017_train":
        ("coco/train2017", "coco/annotations/rbox_train2017.json"),
        "rcoco_2017_val":
        ("coco/val2017", "coco/annotations/rbox_val2017.json"),
    }
    for key, (image_root, json_file) in SPLITS.items():
        metadata = _get_builtin_metadata("coco")
        image_root = os.path.join(root, image_root)
        json_file = os.path.join(root, json_file)
        _register(key, metadata, json_file, image_root)
示例#10
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
        )
示例#11
0
    # 2. Optionally, add metadata about this dataset,
    # since they might be useful in evaluation, visualization or logging
    MetadataCatalog.get(name).set(
        json_file=json_file, image_root=image_root, evaluator_type="coco", **metadata
    )


_PREDEFINED_SPLITS_COCO = {
    "coco_2017_unlabeled": ("coco/unlabeled2017", "coco/annotations/image_info_unlabeled2017.json"),
}

for key, (image_root, json_file) in _PREDEFINED_SPLITS_COCO.items():
    register_coco_instances(
        key,
        _get_builtin_metadata('coco'),
        os.path.join("datasets", json_file) if "://" not in json_file else json_file,
        os.path.join("datasets", image_root),
    )

_PREDEFINED_SPLITS_XRAY = {
    "xary_coco_data": ("xray/", "xray/xray_train.json"),
    "xary_coco_data_val": ("xray/", "xray/xray_val.json"),
}

for key, (image_root, json_file) in _PREDEFINED_SPLITS_XRAY.items():
    register_coco_instances(
        key,
        _get_builtin_metadata('xray'),
        os.path.join("datasets", json_file) if "://" not in json_file else json_file,
        os.path.join("datasets", image_root),