Example #1
0
def CCPDGreen(path: str) -> Dataset:
    """`CCPDGreen <https://github.com/detectRecog/CCPD>`_ dataset.

    The file structure should be like::

        <path>
            ccpd_green/
                train/
                test/
                val/

    Arguments:
        path: The root directory of the dataset.

    Returns:
        Loaded :class: `~tensorbay.dataset.dataset.Dataset` instance.

    """
    root_path = os.path.join(os.path.abspath(os.path.expanduser(path)), "ccpd_green")

    dataset = Dataset(DATASET_NAME_CCPDGREEN)
    dataset.load_catalog(os.path.join(os.path.dirname(__file__), "catalog.json"))

    for segment_name in _CCPDGREEN_SEGMENTS:
        segment = dataset.create_segment(segment_name)
        for image_path in glob(os.path.join(root_path, segment_name, "*.jpg")):
            data = Data(image_path)
            data.label.polygon = _get_polygons(image_path)
            segment.append(data)
    return dataset
Example #2
0
def _get_ccpd_image_path(root_path: str, segment_head: str, segment_tail: str) -> Iterator[str]:
    if segment_tail == "base":
        file_path = os.path.join(root_path, "splits", f"{segment_head}.txt")
        with open(file_path, encoding="utf-8") as fp:
            for image_path in fp:
                yield os.path.join(root_path, image_path.strip())
    else:
        for image_path in glob(os.path.join(root_path, f"ccpd_{segment_tail}", "*.jpg")):
            yield image_path
def OxfordIIITPet(path: str) -> Dataset:
    """`OxfordIIITPet <https://www.robots.ox.ac.uk/~vgg/data/pets/>`_ dataset.

    The file structure should be like::

        <path>
            annotations/
                trimaps/
                    Bombay_113.png
                    Bombay_114.png
                    ...
                xmls/
                    Birman_174.xml
                    Birman_175.xml
                    ...
                list.txt
                test.txt
                trainval.txt
                README
            images/
                Bombay_117.jpg
                Bombay_118.jpg
                ...

    Arguments:
        path: The root directory of the dataset.

    Returns:
        Loaded :class: `~tensorbay.dataset.dataset.Dataset` instance.

    """
    root_path = os.path.abspath(os.path.expanduser(path))
    dataset = Dataset(DATASET_NAME)
    dataset.load_catalog(
        os.path.join(os.path.dirname(__file__), "catalog.json"))
    trainval_segment = dataset.create_segment("trainval")
    test_segment = dataset.create_segment("test")
    annotation_path = os.path.join(root_path, "annotations")
    for image_path in glob(os.path.join(root_path, "images", "*.jpg")):
        image_name = os.path.splitext(os.path.basename(image_path))[0]
        name = "Cat" if image_name.istitle() else "Dog"
        category, num = image_name.rsplit("_", 1)

        data = Data(image_path,
                    target_remote_path=f"{category}_{num.zfill(3)}.jpg")
        label = data.label
        label.classification = Classification(category=f"{name}.{category}")
        label.semantic_mask = SemanticMask(
            os.path.join(annotation_path, "trimaps", f"{image_name}.png"))
        xml_path = os.path.join(annotation_path, "xmls", f"{image_name}.xml")
        if os.path.exists(xml_path):
            label.box2d = _get_box_label(xml_path)
            trainval_segment.append(data)
        else:
            test_segment.append(data)
    return dataset
Example #4
0
def COCO2017(path: str) -> Dataset:
    """`COCO2017 <https://cocodataset.org/#home>`_ dataset.

    The file structure should be like::

        <path>
            annotations/
                panoptic_train2017/
                    000000116037.png
                    000000116040.png
                    ...
                panoptic_val2017/
                instances_train2017.json
                instances_val2017.json
                panoptic_train2017.json
                panoptic_val2017.json
                person_keypoints_train2017.json
                person_keypoints_val2017.json
            train2017/
                000000116026.jpg
                000000116031.jpg
                ...
            test2017/
            val2017/
            unlabeled2017/

    Arguments:
        path: The root directory of the dataset.

    Returns:
        Loaded :class: `~tensorbay.dataset.dataset.Dataset` instance.

    """
    root_path = os.path.abspath(os.path.expanduser(path))
    dataset = Dataset(DATASET_NAME)
    dataset.load_catalog(
        os.path.join(os.path.dirname(__file__), "catalog.json"))

    for segment_name in _LABELED_SEGMENT_NAMES:
        segment = dataset.create_segment(segment_name)
        annotation_path = os.path.join(root_path, "annotations")
        task_information = _get_information(annotation_path, segment_name)
        categories = task_information["categories"]
        for image_path in glob(
                os.path.join(root_path, f"{segment_name}2017", "*.jpg")):
            data = Data(image_path)
            image_stem = os.path.splitext(os.path.basename(image_path))[0]
            image_id = int(image_stem)

            label = _get_instance_label(
                task_information["instances_annotations"], image_id,
                categories)
            label.keypoints2d = _get_keypoints2d(
                task_information["person_keypoints_annotations"], image_id,
                categories)
            label.box2d.extend(
                _get_panoptic_box2d(task_information["panoptic_annotations"],
                                    image_id, categories))
            label.panoptic_mask = _get_panoptic_mask(
                annotation_path,
                segment_name,
                image_stem,
                task_information["panoptic_annotations"],
                image_id,
            )
            data.label = label
            segment.append(data)

    for segment_name in _UNLABELED_SEGMENT_NAMES:
        segment = dataset.create_segment(segment_name)
        for image_path in glob(
                os.path.join(root_path, f"{segment_name}2017", "*.jpg")):
            segment.append(Data(image_path))

    return dataset