Skip to content

Commit

Permalink
CityscapesGTFine
Browse files Browse the repository at this point in the history
  • Loading branch information
watsonvv committed Dec 15, 2021
1 parent 0561368 commit 9a58767
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tensorbay/opendataset/CityscapesGTFine/__init__.py
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 CIHP."""

from tensorbay.opendataset.CIHP.loader import CIHP

__all__ = ["CIHP"]
29 changes: 29 additions & 0 deletions tensorbay/opendataset/CityscapesGTFine/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"SEMANTIC_MASK": {
"categories": [
{ "name": "Background", "categoryId": 0 },
{ "name": "Hat", "categoryId": 1 },
{ "name": "Hair", "categoryId": 2 },
{ "name": "Glove", "categoryId": 3 },
{ "name": "Sunglasses", "categoryId": 4 },
{ "name": "UpperClothes", "categoryId": 5 },
{ "name": "Dress", "categoryId": 6 },
{ "name": "Coat", "categoryId": 7 },
{ "name": "Socks", "categoryId": 8 },
{ "name": "Pants", "categoryId": 9 },
{ "name": "Torso-skin", "categoryId": 10 },
{ "name": "Scarf", "categoryId": 11 },
{ "name": "Skirt", "categoryId": 12 },
{ "name": "Face", "categoryId": 13 },
{ "name": "Left-arm", "categoryId": 14 },
{ "name": "Right-arm", "categoryId": 15 },
{ "name": "Left-leg", "categoryId": 16 },
{ "name": "Right-leg", "categoryId": 17 },
{ "name": "Left-shoe", "categoryId": 18 },
{ "name": "Right-shoe", "categoryId": 19 }
]
},
"INSTANCE_MASK": {
"categories": [{ "name": "Background", "categoryId": 0 }]
}
}
87 changes: 87 additions & 0 deletions tensorbay/opendataset/CityscapesGTFine/loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python3
#
# Copyright 2021 Graviti. Licensed under MIT License.
#
# pylint: disable=invalid-name

"""Dataloader of CIHP dataset."""

import os

from tensorbay.dataset import Data, Dataset
from tensorbay.label import InstanceMask, SemanticMask

DATASET_NAME = "CIHP"
_SEGMENTS_INFO = {"train": "Training", "val": "Validation", "test": "Testing"}


def CIHP(path: str) -> Dataset:
"""`CIHP <https://github.com/Engineering-Course/CIHP_PGN>`_ dataset.
The file structure should be like::
<path>
Testing/
Images/
0000002.jpg
...
test_id.txt
Training/
Images/
0000006.jpg
...
Category_ids/
0000006.png
...
Instance_ids/
0000006.png
...
train_id.txt
Validation/
Images/
0000001.jpg
...
Category_ids/
0000001.png
...
Instance_ids/
0000001.png
...
val_id.txt
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)), "instance-level_human_parsing"
)

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

for segment_name, segment_path in _SEGMENTS_INFO.items():
segment = dataset.create_segment(segment_name)
segment_abspath = os.path.join(root_path, segment_path)
image_path = os.path.join(segment_abspath, "Images")
with open(
os.path.join(segment_abspath, f"{segment_name}_id.txt"), "r", encoding="utf-8"
) as fp:
if segment_name == "test":
for stem in fp:
segment.append(Data(os.path.join(image_path, f"{stem.rstrip()}.jpg")))
else:
category_path = os.path.join(segment_abspath, "Category_ids")
instance_path = os.path.join(segment_abspath, "Instance_ids")
for stem in fp:
stem = stem.rstrip()
data = Data(os.path.join(image_path, f"{stem}.jpg"))
label = data.label
png_filename = f"{stem}.png"
label.semantic_mask = SemanticMask(os.path.join(category_path, png_filename))
label.instance_mask = InstanceMask(os.path.join(instance_path, png_filename))
segment.append(data)
return dataset

0 comments on commit 9a58767

Please sign in to comment.