This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 304
Add ADE20K dataset #429
Merged
Merged
Add ADE20K dataset #429
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
30c3893
Add ADE20K dataset
mitmul 30e8496
Fix test
mitmul f4d8f71
flake8
mitmul 1ecb49f
Fix a typo
mitmul 07ccec5
fix test
mitmul 8c676b9
Separate test dataset
mitmul 91585af
update tests
mitmul 7f913ee
update doc
mitmul 70826ad
fix test
mitmul d0a4d8d
Fix some
mitmul 9f70102
Fix test
mitmul 7797bd5
Merge branch 'master' of github.com:chainer/chainercv into add-ade20k
mitmul f9b719c
follow reviews
mitmul 5b5af14
Fix test
mitmul 1394f6f
Reflect reviews
mitmul 5c69e06
flake8
mitmul d6bc134
import os
mitmul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Empty file.
81 changes: 81 additions & 0 deletions
81
chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py
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,81 @@ | ||
import glob | ||
import os | ||
|
||
import numpy as np | ||
|
||
from chainer import dataset | ||
from chainer.dataset import download | ||
from chainercv import utils | ||
from chainercv.utils import read_image | ||
|
||
root = 'pfnet/chainercv/ade20k' | ||
url = 'http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip' | ||
|
||
|
||
def get_ade20k(): | ||
data_root = download.get_dataset_directory(root) | ||
cache_path = utils.cached_download(url) | ||
utils.extractall(cache_path, data_root, os.path.splitext(url)[1]) | ||
return data_root | ||
|
||
|
||
class ADE20KSemanticSegmentationDataset(dataset.DatasetMixin): | ||
|
||
"""Semantic segmentation dataset for `ADE20K`_. | ||
|
||
This is ADE20K dataset distributed in MIT Scene Parsing Benchmark website. | ||
It has 20,210 training images and 2,000 validation images. | ||
|
||
.. _`MIT Scene Parsing Benchmark`: http://sceneparsing.csail.mit.edu/ | ||
|
||
Args: | ||
data_dir (string): Path to the dataset directory. The directory should | ||
contain the :obj:`ADEChallengeData2016` directory. And that | ||
directory should contain at least :obj:`images` and | ||
:obj:`annotations` directries. If :obj:`auto` is given, the dataset | ||
is automatically downloaded into | ||
:obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/ade20k`. | ||
split ({'train', 'val'}): Select from dataset splits used in | ||
MIT Scene Parsing Benchmark dataset (ADE20K). | ||
|
||
""" | ||
|
||
def __init__(self, data_dir='auto', split='train'): | ||
if data_dir is 'auto': | ||
data_dir = get_ade20k() | ||
|
||
if split == 'train' or split == 'val': | ||
img_dir = os.path.join( | ||
data_dir, 'ADEChallengeData2016', 'images', | ||
'training' if split == 'train' else 'validation') | ||
label_dir = os.path.join( | ||
data_dir, 'ADEChallengeData2016', 'annotations', | ||
'training' if split == 'train' else 'validation') | ||
else: | ||
raise ValueError( | ||
'Please give \'split\' argument with either \'train\' or ' | ||
'\'val\'.') | ||
|
||
self.img_paths = sorted(glob.glob(os.path.join(img_dir, '*.jpg'))) | ||
self.label_paths = sorted(glob.glob(os.path.join(label_dir, '*.png'))) | ||
|
||
def __len__(self): | ||
return len(self.img_paths) | ||
|
||
def get_example(self, i): | ||
"""Returns the i-th example. | ||
|
||
Args: | ||
i (int): The index of the example. | ||
|
||
Returns: | ||
Returns a tuple consited of a color image and a label whose shapes | ||
are (3, H, W) and (H, W), respectively. H and W are height and | ||
width of the image. The dtype of the color image is | ||
:obj:`numpy.float32` and the dtype of the label image is | ||
:obj:`numpy.int32`. | ||
|
||
""" | ||
img = read_image(self.img_paths[i]) | ||
label = read_image(self.label_paths[i], dtype=np.int32, color=False)[0] | ||
return img, label |
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,58 @@ | ||
import glob | ||
import os | ||
|
||
from chainer import dataset | ||
from chainer.dataset import download | ||
from chainercv import utils | ||
from chainercv.utils import read_image | ||
|
||
root = 'pfnet/chainercv/ade20k' | ||
url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip' | ||
|
||
|
||
def get_ade20k(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about moving this function under |
||
data_root = download.get_dataset_directory(root) | ||
cache_path = utils.cached_download(url) | ||
utils.extractall(cache_path, data_root, os.path.splitext(url)[1]) | ||
return data_root | ||
|
||
|
||
class ADE20KTestImageDataset(dataset.DatasetMixin): | ||
|
||
"""Image dataset for test split of `ADE20K`_. | ||
|
||
This is an image dataset of test split in ADE20K dataset distributed at | ||
MIT Scene Parsing Benchmark website. It has 3,352 test images. | ||
|
||
.. _`MIT Scene Parsing Benchmark`: http://sceneparsing.csail.mit.edu/ | ||
|
||
Args: | ||
data_dir (string): Path to the dataset directory. The directory should | ||
contain the :obj:`release_test` dir. If :obj:`auto` is given, the | ||
dataset is automatically downloaded into | ||
:obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/ade20k`. | ||
|
||
""" | ||
|
||
def __init__(self, data_dir='auto'): | ||
if data_dir is 'auto': | ||
data_dir = get_ade20k() | ||
img_dir = os.path.join(data_dir, 'release_test', 'testing') | ||
self.img_paths = sorted(glob.glob(os.path.join(img_dir, '*.jpg'))) | ||
|
||
def __len__(self): | ||
return len(self.img_paths) | ||
|
||
def get_example(self, i): | ||
"""Returns the i-th example. | ||
|
||
Args: | ||
i (int): The index of the example. | ||
|
||
Returns: | ||
Returns a color image whose shape is (3, H, W). H and W are height | ||
and width of the image. The dtype of the image is | ||
:obj:`numpy.float32`. | ||
|
||
""" | ||
return read_image(self.img_paths[i]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to our naming convention,
ade20k_label_colors
should beade20k_semantic_segmentation_label_colors
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/chainer/chainercv/blob/master/chainercv/datasets/cityscapes/cityscapes_utils.py#L53
You think this is a problem also?
label_names
should be changed as well because it can be different from the one used by Instance Segmentation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is also a problem. Thank you for pointing out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To summarize:
ade_label_colors
-->ade_semantic_segmentation_label_colors
ade_label_names
-->ade_semantic_segmentation_label_names
cityscapes_label_colors
-->cityscapes_semantic_segmentation_label_colors
cityscapes_label_names
-->cityscapes_semantic_segmentation_label_names
Objects for CamVid need not be changed because this dataset only contains semantic segmentation data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for summarizing.
I agree with you.