-
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.
- Loading branch information
Showing
3 changed files
with
127 additions
and
0 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 |
---|---|---|
@@ -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"] |
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,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 }] | ||
} | ||
} |
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,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 |