-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(opendataset): add dataloader for the CityscapesGTFine dataset
- Loading branch information
Showing
8 changed files
with
177 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ tensorbay.opendataset | |
CCPD | ||
CCPDGreen | ||
CIHP | ||
CityscapesGTFine | ||
COCO2017 | ||
COVIDChestXRay | ||
COVID_CT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2021 Graviti. Licensed under MIT License. | ||
# | ||
# pylint: disable=invalid-name | ||
|
||
"""Dataloader of the CityscapesGTFine dataset.""" | ||
|
||
from tensorbay.opendataset.Cityscapes.loader import CityscapesGTFine | ||
|
||
__all__ = ["CityscapesGTFine"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"SEMANTIC_MASK": { | ||
"categories": [ | ||
{ "name": "void", "categoryId": 0 }, | ||
{ "name": "flat", "categoryId": 1 }, | ||
{ "name": "construction", "categoryId": 2 }, | ||
{ "name": "object", "categoryId": 3 }, | ||
{ "name": "nature", "categoryId": 4 }, | ||
{ "name": "sky", "categoryId": 5 }, | ||
{ "name": "human", "categoryId": 6 }, | ||
{ "name": "vehicle", "categoryId": 7 } | ||
] | ||
}, | ||
"INSTANCE_MASK": { | ||
"categories": [{ "name": "Background", "categoryId": 0 }] | ||
}, | ||
"POLYGON": { | ||
"categories": [ | ||
{ "name": "unlabeled" }, | ||
{ "name": "ego vehicle" }, | ||
{ "name": "rectification border" }, | ||
{ "name": "out of roi" }, | ||
{ "name": "static" }, | ||
{ "name": "dynamic" }, | ||
{ "name": "ground" }, | ||
{ "name": "road" }, | ||
{ "name": "sidewalk" }, | ||
{ "name": "parking" }, | ||
{ "name": "rail track" }, | ||
{ "name": "building" }, | ||
{ "name": "wall" }, | ||
{ "name": "fence" }, | ||
{ "name": "guard rail" }, | ||
{ "name": "bridge" }, | ||
{ "name": "tunnel" }, | ||
{ "name": "pole" }, | ||
{ "name": "polegroup" }, | ||
{ "name": "traffic light" }, | ||
{ "name": "traffic sign" }, | ||
{ "name": "vegetation" }, | ||
{ "name": "terrain" }, | ||
{ "name": "sky" }, | ||
{ "name": "person" }, | ||
{ "name": "rider" }, | ||
{ "name": "car" }, | ||
{ "name": "truck" }, | ||
{ "name": "bus" }, | ||
{ "name": "caravan" }, | ||
{ "name": "trailer" }, | ||
{ "name": "train" }, | ||
{ "name": "motorcycle" }, | ||
{ "name": "bicycle" }, | ||
{ "name": "license plate" } | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2021 Graviti. Licensed under MIT License. | ||
# | ||
# pylint: disable=invalid-name | ||
|
||
"""Dataloader of the CityscapesGTFine dataset.""" | ||
|
||
import json | ||
import os | ||
from glob import glob | ||
from typing import List | ||
|
||
from tensorbay.dataset import Data, Dataset | ||
from tensorbay.label import InstanceMask, LabeledPolygon, SemanticMask | ||
|
||
DATASET_NAME = "CityscapesGTFine" | ||
_SEGMENT_NAMES = {"test", "train", "val"} | ||
|
||
|
||
def CityscapesGTFine(path: str) -> Dataset: | ||
"""`CityscapesGTFine <https://www.cityscapes-dataset.com/>`_ dataset. | ||
The file structure should be like:: | ||
<path> | ||
leftImg8bit/ | ||
test/ | ||
berlin/ | ||
berlin_000000_000019_leftImg8bit.png | ||
... | ||
... | ||
train/ | ||
aachen/ | ||
aachen_000000_000019_leftImg8bit.png | ||
... | ||
... | ||
val/ | ||
frankfurt/ | ||
frankfurt_000000_000019_leftImg8bit.png | ||
... | ||
... | ||
... | ||
gtFine/ | ||
test/ | ||
berlin/ | ||
berlin_000000_000019_gtFine_instanceIds.png | ||
berlin_000000_000019_gtFine_labelIds.png | ||
berlin_000000_000019_gtFine_polygons.json | ||
... | ||
... | ||
train/ | ||
aachen/ | ||
aachen_000000_000019_gtFine_instanceIds.png | ||
aachen_000000_000019_gtFine_labelIds.png | ||
aachen_000000_000019_gtFine_polygons.json | ||
... | ||
... | ||
val/ | ||
frankfurt/ | ||
frankfurt_000000_000019_gtFine_instanceIds.png | ||
frankfurt_000000_000019_gtFine_labelIds.png | ||
frankfurt_000000_000019_gtFine_polygons.json | ||
... | ||
... | ||
... | ||
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))) | ||
|
||
dataset = Dataset(DATASET_NAME) | ||
dataset.load_catalog(os.path.join(os.path.dirname(__file__), "catalog.json")) | ||
|
||
for segment_name in _SEGMENT_NAMES: | ||
segment = dataset.create_segment(segment_name) | ||
for image_path in glob(os.path.join(root_path, "leftImg8bit", segment_name, "*", "*.png")): | ||
city = image_path.split("_", 1)[0] | ||
image_prefix = image_path.rsplit("_", 1)[0] | ||
label_dir = os.path.join(root_path, "gtFine", segment_name, city) | ||
data = Data(image_path) | ||
# get semantic mask and instance mask | ||
label = data.label | ||
label.semantic_mask = SemanticMask( | ||
os.path.join(label_dir, f"{image_prefix}_gtFine_labelIds.png") | ||
) | ||
label.instance_mask = InstanceMask( | ||
os.path.join(label_dir, f"{image_prefix}_gtFine_instanceIds.png") | ||
) | ||
# get polygons | ||
polygons: List[LabeledPolygon] = [] | ||
with open( | ||
os.path.join(label_dir, f"{image_prefix}_gtFine_polygons.json"), | ||
encoding="utf-8", | ||
) as fp: | ||
objects = json.load(fp)["objects"] | ||
for obj in objects: | ||
polygons.append(LabeledPolygon(obj["polygon"], category=obj["label"])) | ||
label.polygon = polygons | ||
|
||
segment.append(data) | ||
return dataset |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters