-
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(dataset): add dataloader for CIHP dataset
- Loading branch information
1 parent
b51a4c3
commit f7c32f1
Showing
4 changed files
with
135 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 .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,27 @@ | ||
{ | ||
"SEMANTIC_MASK": { | ||
"categories": [ | ||
{ "name": "Background" }, | ||
{ "name": "Hat" }, | ||
{ "name": "Hair" }, | ||
{ "name": "Glove" }, | ||
{ "name": "Sunglasses" }, | ||
{ "name": "UpperClothes" }, | ||
{ "name": "Dress" }, | ||
{ "name": "Coat" }, | ||
{ "name": "Socks" }, | ||
{ "name": "Pants" }, | ||
{ "name": "Torso-skin" }, | ||
{ "name": "Scarf" }, | ||
{ "name": "Skirt" }, | ||
{ "name": "Face" }, | ||
{ "name": "Left-arm" }, | ||
{ "name": "Right-arm" }, | ||
{ "name": "Left-leg" }, | ||
{ "name": "Right-leg" }, | ||
{ "name": "Left-shoe" }, | ||
{ "name": "Right-shoe" } | ||
] | ||
}, | ||
"INSTANCE_MASK": {} | ||
} |
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,96 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2021 Graviti. Licensed under MIT License. | ||
# | ||
# pylint: disable=invalid-name, missing-module-docstring | ||
|
||
import os | ||
|
||
from ...dataset import Data, Dataset | ||
from ...label import InstanceMask, SemanticMask | ||
|
||
DATASET_NAME = "CIHP" | ||
_SEGMENTS_INFO = (("train", "Training"), ("val", "Validation"), ("test", "Testing")) | ||
|
||
|
||
def CIHP(path: str) -> Dataset: | ||
"""Dataloader of the `CIHP`_ dataset. | ||
.. _CIHP: https://github.com/Engineering-Course/CIHP_PGN | ||
The file structure should be like:: | ||
<path> | ||
instance-level_human_parsing/ | ||
Testing/ | ||
Images/ | ||
0000002.jpg | ||
... | ||
test_id.txt | ||
Training/ | ||
Images/ | ||
0000006.jpg | ||
... | ||
Categories/ | ||
0000006.png | ||
... | ||
Human/ | ||
0000006.png | ||
... | ||
Instances/ | ||
0000006.png | ||
... | ||
train_id.txt | ||
Validation/ | ||
Images/ | ||
0000001.jpg | ||
... | ||
Categories/ | ||
0000001.png | ||
... | ||
Human/ | ||
0000001.png | ||
... | ||
Instances/ | ||
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_pathname in _SEGMENTS_INFO: | ||
segment = dataset.create_segment(segment_name) | ||
work_path = os.path.join(root_path, segment_pathname) | ||
image_path = os.path.join(work_path, "Images") | ||
if segment_name == "test": | ||
with open(os.path.join(work_path, "test_id.txt"), "r") as fp: | ||
for filename in fp: | ||
segment.append(Data(os.path.join(image_path, f"{filename.strip()}.jpg"))) | ||
else: | ||
category_path = os.path.join(work_path, "Category_ids") | ||
instance_path = os.path.join(work_path, "Instance_ids") | ||
with open(os.path.join(work_path, f"{segment_name}_id.txt"), "r") as fp: | ||
for filename in fp: | ||
filename = filename.strip() | ||
data = Data(os.path.join(image_path, f"{filename}.jpg")) | ||
label = data.label | ||
label.semantic_mask = SemanticMask( | ||
os.path.join(category_path, f"{filename}.png") | ||
) | ||
label.instance_mask = InstanceMask( | ||
os.path.join(instance_path, f"{filename}.png") | ||
) | ||
segment.append(data) | ||
return dataset |
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 |
---|---|---|
|
@@ -64,6 +64,7 @@ | |
"CarConnection", | ||
"CCPD", | ||
"CCPDGreen", | ||
"CIHP", | ||
"CoinImage", | ||
"COVIDChestXRay", | ||
"CompCars", | ||
|