-
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 VOC2012Segmentation dataset
- Loading branch information
Showing
4 changed files
with
178 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 VOC2012Segmentation.""" | ||
|
||
from .loader import VOC2012Segmentation | ||
|
||
__all__ = ["VOC2012Segmentation"] |
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,95 @@ | ||
{ | ||
"SEMANTIC_MASK": { | ||
"categories": [ | ||
{ | ||
"name": "background", | ||
"categoryId": 0 | ||
}, | ||
{ | ||
"name": "aeroplane", | ||
"categoryId": 1 | ||
}, | ||
{ | ||
"name": "bicycle", | ||
"categoryId": 2 | ||
}, | ||
{ | ||
"name": "bird", | ||
"categoryId": 3 | ||
}, | ||
{ | ||
"name": "boat", | ||
"categoryId": 4 | ||
}, | ||
{ | ||
"name": "bottle", | ||
"categoryId": 5 | ||
}, | ||
{ | ||
"name": "bus", | ||
"categoryId": 6 | ||
}, | ||
{ | ||
"name": "car", | ||
"categoryId": 7 | ||
}, | ||
{ | ||
"name": "cat", | ||
"categoryId": 8 | ||
}, | ||
{ | ||
"name": "chair", | ||
"categoryId": 9 | ||
}, | ||
{ | ||
"name": "cow", | ||
"categoryId": 10 | ||
}, | ||
{ | ||
"name": "diningtable", | ||
"categoryId": 11 | ||
}, | ||
{ | ||
"name": "dog", | ||
"categoryId": 12 | ||
}, | ||
{ | ||
"name": "horse", | ||
"categoryId": 13 | ||
}, | ||
{ | ||
"name": "motorbike", | ||
"categoryId": 14 | ||
}, | ||
{ | ||
"name": "person", | ||
"categoryId": 15 | ||
}, | ||
{ | ||
"name": "pottedplant", | ||
"categoryId": 16 | ||
}, | ||
{ | ||
"name": "sheep", | ||
"categoryId": 17 | ||
}, | ||
{ | ||
"name": "sofa", | ||
"categoryId": 18 | ||
}, | ||
{ | ||
"name": "train", | ||
"categoryId": 19 | ||
}, | ||
{ | ||
"name": "tvmonitor", | ||
"categoryId": 20 | ||
}, | ||
{ | ||
"name": "void", | ||
"categoryId": 255 | ||
} | ||
] | ||
}, | ||
"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,70 @@ | ||
#!/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 | ||
|
||
_SEGMENT_NAMES = ("train", "val") | ||
DATASET_NAME = "VOC2012Segmentation" | ||
|
||
|
||
def VOC2012Segmentation(path: str) -> Dataset: | ||
"""Dataloader of the 'VOC2012Segmentation'_ dataset. | ||
.. _VOC2012Segmentation: http://host.robots.ox.ac.uk/pascal/VOC/voc2012/ | ||
The file structure should be like:: | ||
<path>/ | ||
JPEGImages/ | ||
<image_name>.jpg | ||
... | ||
SegmentationClass/ | ||
<mask_name>.png | ||
... | ||
SegmentationObject/ | ||
<mask_name>.png | ||
... | ||
ImageSets/ | ||
Segmentation/ | ||
train.txt | ||
val.txt | ||
... | ||
... | ||
... | ||
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)) | ||
|
||
image_path = os.path.join(root_path, "JPEGImages") | ||
semantic_mask_path = os.path.join(root_path, "SegmentationClass") | ||
instance_mask_path = os.path.join(root_path, "SegmentationObject") | ||
image_set_path = os.path.join(root_path, "ImageSets", "Segmentation") | ||
|
||
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) | ||
with open(os.path.join(image_set_path, f"{segment_name}.txt")) as fp: | ||
for stem in fp: | ||
stem = stem.strip() | ||
data = Data(os.path.join(image_path, f"{stem}.jpg")) | ||
label = data.label | ||
label.semantic_mask = SemanticMask(os.path.join(semantic_mask_path, f"{stem}.png")) | ||
label.instance_mask = InstanceMask(os.path.join(instance_mask_path, f"{stem}.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