From 30c389300efe6cb11ec626fc597032fd68b5f00f Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 15:05:45 +0900 Subject: [PATCH 01/16] Add ADE20K dataset --- chainercv/datasets/__init__.py | 3 + chainercv/datasets/ade20k/__init__.py | 0 .../ade20k_semantic_segmentation_dataset.py | 103 ++++++ chainercv/datasets/ade20k/ade20k_utils.py | 308 ++++++++++++++++++ .../ade20k_tests/test_ade20k.py | 31 ++ 5 files changed, 445 insertions(+) create mode 100644 chainercv/datasets/ade20k/__init__.py create mode 100644 chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py create mode 100644 chainercv/datasets/ade20k/ade20k_utils.py create mode 100644 tests/datasets_tests/ade20k_tests/test_ade20k.py diff --git a/chainercv/datasets/__init__.py b/chainercv/datasets/__init__.py index 00ec712eee..12d21652cc 100644 --- a/chainercv/datasets/__init__.py +++ b/chainercv/datasets/__init__.py @@ -1,3 +1,6 @@ +from chainercv.datasets.ade20k.ade20k_semantic_segmentation_dataset import ADE20KSemanticSegmentationDataset # NOQA +from chainercv.datasets.ade20k.ade20k_utils import ade20k_label_colors # NOQA +from chainercv.datasets.ade20k.ade20k_utils import ade20k_label_names # NOQA from chainercv.datasets.camvid.camvid_dataset import camvid_ignore_label_color # NOQA from chainercv.datasets.camvid.camvid_dataset import camvid_label_colors # NOQA from chainercv.datasets.camvid.camvid_dataset import camvid_label_names # NOQA diff --git a/chainercv/datasets/ade20k/__init__.py b/chainercv/datasets/ade20k/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py new file mode 100644 index 0000000000..175d97b747 --- /dev/null +++ b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py @@ -0,0 +1,103 @@ +import glob +import os +from multiprocessing import Pool + +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' +trainval_url = 'http://data.csail.mit.edu/places/ADEchallenge/' +trainval_url += 'ADEChallengeData2016.zip' +test_url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip' + + +def get_ade20k(): + p = Pool(2) + data_root = download.get_dataset_directory(root) + urls = [trainval_url, test_url] + ret = [p.apply_async(utils.cached_download, args=(url,)) for url in urls] + caches = [r.get() for r in ret] + args = [(cache_fn, data_root, os.path.splitext(url)[1]) + for cache_fn, url in zip(caches, urls)] + ret = [p.apply_async(utils.extractall, args=arg) for arg in args] + for r in ret: + r.get() + 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, 2,000 validation images, and 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 at least two directories, :obj:`annotations` and + :obj:`images`. If :obj:`auto` is given, the dataset is + automatically downloaded into + :obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/ade20k`. + split ({'train', 'val', 'test'}): Select from dataset splits used in + Cityscapes dataset. + + """ + + 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') + elif split == 'test': + img_dir = os.path.join(data_dir, 'release_test', 'testing') + else: + raise ValueError( + 'Please give \'split\' argument with either \'train\', ' + '\'val\', or \'test\'.') + + self.img_paths = sorted(glob.glob(os.path.join(img_dir, '*.jpg'))) + if split == 'train' or split == 'val': + self.label_paths = sorted( + glob.glob(os.path.join(label_dir, '*.png'))) + + self.split = split + + 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: + When :obj:`split` is either :obj:`train` or :obj:`val`, it returns + a tuple consited of a color image and a label whose shapes are + (3, H, W) and (H, W), respectively, while :obj:`split` is + :obj:`test`, it returns only the color image. 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]) + if self.split == 'train' or self.split == 'val': + label = read_image( + self.label_paths[i], dtype=np.int32, color=False)[0] + return img, label + else: + return img diff --git a/chainercv/datasets/ade20k/ade20k_utils.py b/chainercv/datasets/ade20k/ade20k_utils.py new file mode 100644 index 0000000000..e6c5f9a843 --- /dev/null +++ b/chainercv/datasets/ade20k/ade20k_utils.py @@ -0,0 +1,308 @@ +# The values used here are copied from CSAILVision/sceneparsing: +# https://github.com/CSAILVision/sceneparsing + +ade20k_label_names = [ + 'wall', + 'edifice', + 'sky', + 'flooring', + 'tree', + 'ceiling', + 'route', + 'bed ', + 'window ', + 'grass', + 'cabinet', + 'pavement', + 'soul', + 'ground', + 'door', + 'table', + 'mount', + 'life', + 'pall', + 'chair', + 'motorcar', + 'water', + 'picture', + 'lounge', + 'shelf', + 'house', + 'sea', + 'mirror', + 'carpeting', + 'field', + 'armchair', + 'seat', + 'fencing', + 'desk', + 'stone', + 'press', + 'lamp', + 'tub', + 'rail', + 'cushion', + 'stand', + 'box', + 'pillar', + 'sign', + 'dresser', + 'counter', + 'sand', + 'sink', + 'skyscraper', + 'fireplace', + 'icebox', + 'stand', + 'path', + 'steps', + 'runway', + 'vitrine', + 'table', + 'pillow', + 'screen', + 'staircase', + 'river', + 'span', + 'bookcase', + 'screen', + 'table', + 'throne', + 'flower', + 'book', + 'hill', + 'bench', + 'countertop', + 'stove', + 'tree', + 'island', + 'system', + 'chair', + 'boat', + 'bar', + 'machine', + 'shanty', + 'vehicle', + 'towel', + 'source', + 'motortruck', + 'tower', + 'pendent', + 'sunblind', + 'lamp', + 'kiosk', + 'box', + 'plane', + 'track', + 'clothes', + 'pole', + 'soil', + 'handrail', + 'stairway', + 'hassock', + 'bottle', + 'sideboard', + 'card', + 'stage', + 'van', + 'ship', + 'fountain', + 'transporter', + 'canopy', + 'machine', + 'toy', + 'natatorium', + 'stool', + 'cask', + 'handbasket', + 'falls', + 'shelter', + 'bag', + 'motorbike', + 'cradle', + 'oven', + 'ball', + 'food', + 'stair', + 'tank', + 'marque', + 'oven', + 'flowerpot', + 'fauna', + 'cycle ', + 'lake', + 'machine', + 'screen', + 'cover', + 'sculpture', + 'hood', + 'sconce', + 'vase', + 'stoplight', + 'tray', + 'bin', + 'fan', + 'dock', + 'screen', + 'plate', + 'device', + 'board', + 'shower', + 'radiator', + 'glass', + 'clock', + 'flag' +] + +ade20k_label_colors = [ + [120, 120, 120], + [180, 120, 120], + [6, 230, 230], + [80, 50, 50], + [4, 200, 3], + [120, 120, 80], + [140, 140, 140], + [204, 5, 255], + [230, 230, 230], + [4, 250, 7], + [224, 5, 255], + [235, 255, 7], + [150, 5, 61], + [120, 120, 70], + [8, 255, 51], + [255, 6, 82], + [143, 255, 140], + [204, 255, 4], + [255, 51, 7], + [204, 70, 3], + [0, 102, 200], + [61, 230, 250], + [255, 6, 51], + [11, 102, 255], + [255, 7, 71], + [255, 9, 224], + [9, 7, 230], + [220, 220, 220], + [255, 9, 92], + [112, 9, 255], + [8, 255, 214], + [7, 255, 224], + [255, 184, 6], + [10, 255, 71], + [255, 41, 10], + [7, 255, 255], + [224, 255, 8], + [102, 8, 255], + [255, 61, 6], + [255, 194, 7], + [255, 122, 8], + [0, 255, 20], + [255, 8, 41], + [255, 5, 153], + [6, 51, 255], + [235, 12, 255], + [160, 150, 20], + [0, 163, 255], + [140, 140, 140], + [250, 10, 15], + [20, 255, 0], + [31, 255, 0], + [255, 31, 0], + [255, 224, 0], + [153, 255, 0], + [0, 0, 255], + [255, 71, 0], + [0, 235, 255], + [0, 173, 255], + [31, 0, 255], + [11, 200, 200], + [255, 82, 0], + [0, 255, 245], + [0, 61, 255], + [0, 255, 112], + [0, 255, 133], + [255, 0, 0], + [255, 163, 0], + [255, 102, 0], + [194, 255, 0], + [0, 143, 255], + [51, 255, 0], + [0, 82, 255], + [0, 255, 41], + [0, 255, 173], + [10, 0, 255], + [173, 255, 0], + [0, 255, 153], + [255, 92, 0], + [255, 0, 255], + [255, 0, 245], + [255, 0, 102], + [255, 173, 0], + [255, 0, 20], + [255, 184, 184], + [0, 31, 255], + [0, 255, 61], + [0, 71, 255], + [255, 0, 204], + [0, 255, 194], + [0, 255, 82], + [0, 10, 255], + [0, 112, 255], + [51, 0, 255], + [0, 194, 255], + [0, 122, 255], + [0, 255, 163], + [255, 153, 0], + [0, 255, 10], + [255, 112, 0], + [143, 255, 0], + [82, 0, 255], + [163, 255, 0], + [255, 235, 0], + [8, 184, 170], + [133, 0, 255], + [0, 255, 92], + [184, 0, 255], + [255, 0, 31], + [0, 184, 255], + [0, 214, 255], + [255, 0, 112], + [92, 255, 0], + [0, 224, 255], + [112, 224, 255], + [70, 184, 160], + [163, 0, 255], + [153, 0, 255], + [71, 255, 0], + [255, 0, 163], + [255, 204, 0], + [255, 0, 143], + [0, 255, 235], + [133, 255, 0], + [255, 0, 235], + [245, 0, 255], + [255, 0, 122], + [255, 245, 0], + [10, 190, 212], + [214, 255, 0], + [0, 204, 255], + [20, 0, 255], + [255, 255, 0], + [0, 153, 255], + [0, 41, 255], + [0, 255, 204], + [41, 0, 255], + [41, 255, 0], + [173, 0, 255], + [0, 245, 255], + [71, 0, 255], + [122, 0, 255], + [0, 255, 184], + [0, 92, 255], + [184, 255, 0], + [0, 133, 255], + [255, 214, 0], + [25, 194, 194], + [102, 255, 0], + [92, 0, 255] +] diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py new file mode 100644 index 0000000000..1d3954a3e8 --- /dev/null +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -0,0 +1,31 @@ +import unittest + +from chainer import testing +from chainer.testing import attr +from chainercv.datasets import ADE20KSemanticSegmentationDataset +from chainercv.datasets import ade20k_label_names +from chainercv.utils import assert_is_semantic_segmentation_dataset +from chainercv.utils.testing.assertions.assert_is_image import assert_is_image + + +@testing.parameterize( + {'split': 'train'}, + {'split': 'val'}, + {'split': 'test'} +) +class TestCamVidDataset(unittest.TestCase): + + def setUp(self): + self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) + + @attr.slow + def test_camvid_dataset(self): + if self.split == 'train' or self.split == 'val': + assert_is_semantic_segmentation_dataset( + self.dataset, len(ade20k_label_names), n_example=10) + else: + for img in self.datast[:10]: + assert_is_image(img, color=True) + + +testing.run_module(__name__, __file__) From 30e84960fcd7afa652bb0b468467092d552163f4 Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 15:07:12 +0900 Subject: [PATCH 02/16] Fix test --- tests/datasets_tests/ade20k_tests/test_ade20k.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index 1d3954a3e8..ee75d0a699 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -13,7 +13,7 @@ {'split': 'val'}, {'split': 'test'} ) -class TestCamVidDataset(unittest.TestCase): +class TestADE20KDataset(unittest.TestCase): def setUp(self): self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) @@ -24,7 +24,7 @@ def test_camvid_dataset(self): assert_is_semantic_segmentation_dataset( self.dataset, len(ade20k_label_names), n_example=10) else: - for img in self.datast[:10]: + for img in self.dataset[:10]: assert_is_image(img, color=True) From f4d8f713103b5d19d1ce9ba8f5a187305c6bf0c0 Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 15:08:35 +0900 Subject: [PATCH 03/16] flake8 --- .../datasets/ade20k/ade20k_semantic_segmentation_dataset.py | 2 +- tests/datasets_tests/ade20k_tests/test_ade20k.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py index 175d97b747..dbdb4aa63c 100644 --- a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py @@ -1,6 +1,6 @@ import glob -import os from multiprocessing import Pool +import os import numpy as np diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index ee75d0a699..ec7d648647 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -2,8 +2,8 @@ from chainer import testing from chainer.testing import attr -from chainercv.datasets import ADE20KSemanticSegmentationDataset from chainercv.datasets import ade20k_label_names +from chainercv.datasets import ADE20KSemanticSegmentationDataset from chainercv.utils import assert_is_semantic_segmentation_dataset from chainercv.utils.testing.assertions.assert_is_image import assert_is_image From 1ecb49f708a3c033594db22b9c66fc58a89fbbbc Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 21:30:19 +0900 Subject: [PATCH 04/16] Fix a typo --- .../datasets/ade20k/ade20k_semantic_segmentation_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py index dbdb4aa63c..fde305a84e 100644 --- a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py @@ -46,7 +46,7 @@ class ADE20KSemanticSegmentationDataset(dataset.DatasetMixin): automatically downloaded into :obj:`$CHAINER_DATASET_ROOT/pfnet/chainercv/ade20k`. split ({'train', 'val', 'test'}): Select from dataset splits used in - Cityscapes dataset. + MIT Scene Parsing Benchmark dataset (ADE20K). """ From 07ccec5463f8b7e5e76edd0a6e1d980a124f2227 Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 21:32:42 +0900 Subject: [PATCH 05/16] fix test --- tests/datasets_tests/ade20k_tests/test_ade20k.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index ec7d648647..da13b3dc4a 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -19,7 +19,7 @@ def setUp(self): self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) @attr.slow - def test_camvid_dataset(self): + def test_ade20k_dataset(self): if self.split == 'train' or self.split == 'val': assert_is_semantic_segmentation_dataset( self.dataset, len(ade20k_label_names), n_example=10) From 8c676b9b61431b7215cc40513284f4d1264658ff Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 22:04:05 +0900 Subject: [PATCH 06/16] Separate test dataset --- .../ade20k_semantic_segmentation_dataset.py | 56 ++++++----------- .../ade20k/ade20k_test_image_dataset.py | 60 +++++++++++++++++++ 2 files changed, 77 insertions(+), 39 deletions(-) create mode 100644 chainercv/datasets/ade20k/ade20k_test_image_dataset.py diff --git a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py index fde305a84e..0ad8e9d7df 100644 --- a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py @@ -1,5 +1,4 @@ import glob -from multiprocessing import Pool import os import numpy as np @@ -10,22 +9,13 @@ from chainercv.utils import read_image root = 'pfnet/chainercv/ade20k' -trainval_url = 'http://data.csail.mit.edu/places/ADEchallenge/' -trainval_url += 'ADEChallengeData2016.zip' -test_url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip' +url = 'http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip' def get_ade20k(): - p = Pool(2) data_root = download.get_dataset_directory(root) - urls = [trainval_url, test_url] - ret = [p.apply_async(utils.cached_download, args=(url,)) for url in urls] - caches = [r.get() for r in ret] - args = [(cache_fn, data_root, os.path.splitext(url)[1]) - for cache_fn, url in zip(caches, urls)] - ret = [p.apply_async(utils.extractall, args=arg) for arg in args] - for r in ret: - r.get() + cache_fn = utils.cached_download(url) + utils.extractall(cache_fn, data_root, os.path.splitext(url)[1]) return data_root @@ -34,18 +24,18 @@ 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, 2,000 validation images, and 3,352 test - images. + 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 at least two directories, :obj:`annotations` and - :obj:`images`. If :obj:`auto` is given, the dataset is - automatically downloaded into + 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', 'test'}): Select from dataset splits used in + split ({'train', 'val'}): Select from dataset splits used in MIT Scene Parsing Benchmark dataset (ADE20K). """ @@ -61,19 +51,13 @@ def __init__(self, data_dir='auto', split='train'): label_dir = os.path.join( data_dir, 'ADEChallengeData2016', 'annotations', 'training' if split == 'train' else 'validation') - elif split == 'test': - img_dir = os.path.join(data_dir, 'release_test', 'testing') else: raise ValueError( - 'Please give \'split\' argument with either \'train\', ' - '\'val\', or \'test\'.') + 'Please give \'split\' argument with either \'train\' or ' + '\'val\'.') self.img_paths = sorted(glob.glob(os.path.join(img_dir, '*.jpg'))) - if split == 'train' or split == 'val': - self.label_paths = sorted( - glob.glob(os.path.join(label_dir, '*.png'))) - - self.split = split + self.label_paths = sorted(glob.glob(os.path.join(label_dir, '*.png'))) def __len__(self): return len(self.img_paths) @@ -85,19 +69,13 @@ def get_example(self, i): i (int): The index of the example. Returns: - When :obj:`split` is either :obj:`train` or :obj:`val`, it returns - a tuple consited of a color image and a label whose shapes are - (3, H, W) and (H, W), respectively, while :obj:`split` is - :obj:`test`, it returns only the color image. H and W are height - and width of the image. The dtype of the color image is + 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]) - if self.split == 'train' or self.split == 'val': - label = read_image( - self.label_paths[i], dtype=np.int32, color=False)[0] - return img, label - else: - return img + label = read_image(self.label_paths[i], dtype=np.int32, color=False)[0] + return img, label diff --git a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py new file mode 100644 index 0000000000..2005fce2ae --- /dev/null +++ b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py @@ -0,0 +1,60 @@ +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' +test_url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip' + + +def get_ade20k(): + data_root = download.get_dataset_directory(root) + cache_fn = utils.cached_download(test_url) + utils.extractall(cache_fn, data_root, os.path.splitext(test_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]) From 91585afeee9240536169460e8a379be147a35321 Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 22:06:30 +0900 Subject: [PATCH 07/16] update tests --- chainercv/datasets/__init__.py | 1 + chainercv/datasets/ade20k/ade20k_test_image_dataset.py | 8 +++----- tests/datasets_tests/ade20k_tests/test_ade20k.py | 6 +++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/chainercv/datasets/__init__.py b/chainercv/datasets/__init__.py index 12d21652cc..a3ac1af20e 100644 --- a/chainercv/datasets/__init__.py +++ b/chainercv/datasets/__init__.py @@ -1,4 +1,5 @@ from chainercv.datasets.ade20k.ade20k_semantic_segmentation_dataset import ADE20KSemanticSegmentationDataset # NOQA +from chainercv.datasets.ade20k.ade20k_test_image_dataset import ADE20KTestImageDataset # NOQA from chainercv.datasets.ade20k.ade20k_utils import ade20k_label_colors # NOQA from chainercv.datasets.ade20k.ade20k_utils import ade20k_label_names # NOQA from chainercv.datasets.camvid.camvid_dataset import camvid_ignore_label_color # NOQA diff --git a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py index 2005fce2ae..e85a0772e4 100644 --- a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py @@ -1,21 +1,19 @@ 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' -test_url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip' +url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip' def get_ade20k(): data_root = download.get_dataset_directory(root) - cache_fn = utils.cached_download(test_url) - utils.extractall(cache_fn, data_root, os.path.splitext(test_url)[1]) + cache_fn = utils.cached_download(url) + utils.extractall(cache_fn, data_root, os.path.splitext(url)[1]) return data_root diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index da13b3dc4a..38af88b430 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -4,6 +4,7 @@ from chainer.testing import attr from chainercv.datasets import ade20k_label_names from chainercv.datasets import ADE20KSemanticSegmentationDataset +from chainercv.datasets import ADE20KTestImageDataset from chainercv.utils import assert_is_semantic_segmentation_dataset from chainercv.utils.testing.assertions.assert_is_image import assert_is_image @@ -16,7 +17,10 @@ class TestADE20KDataset(unittest.TestCase): def setUp(self): - self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) + if self.split == 'train' or self.split == 'val': + self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) + else: + self.dataset = ADE20KTestImageDataset(split=self.split) @attr.slow def test_ade20k_dataset(self): From 7f913ee1a6e123985f65021d630595f942fe092d Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 22:07:57 +0900 Subject: [PATCH 08/16] update doc --- docs/source/reference/datasets.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/source/reference/datasets.rst b/docs/source/reference/datasets.rst index 82c2b0c0b4..333d0de86a 100644 --- a/docs/source/reference/datasets.rst +++ b/docs/source/reference/datasets.rst @@ -18,6 +18,17 @@ TransformDataset ~~~~~~~~~~~~~~~~ .. autoclass:: TransformDataset +ADE20K +------ + +ADE20KSemanticSegmentationDataset +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. autoclass:: ADE20KSemanticSegmentationDataset + +ADE20KTestImageDataset +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. autoclass:: ADE20KTestImageDataset + CamVid ------ From 70826adc238f1898f39f157795c1d7e8a5d2a7b3 Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Wed, 27 Sep 2017 22:14:28 +0900 Subject: [PATCH 09/16] fix test --- tests/datasets_tests/ade20k_tests/test_ade20k.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index 38af88b430..5d9ec10d60 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -20,7 +20,7 @@ def setUp(self): if self.split == 'train' or self.split == 'val': self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) else: - self.dataset = ADE20KTestImageDataset(split=self.split) + self.dataset = ADE20KTestImageDataset() @attr.slow def test_ade20k_dataset(self): From d0a4d8dea409cbc7f59a50a781c0951f2cfa342b Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Thu, 28 Sep 2017 11:27:39 +0900 Subject: [PATCH 10/16] Fix some --- .../ade20k_semantic_segmentation_dataset.py | 4 +- .../ade20k/ade20k_test_image_dataset.py | 4 +- chainercv/datasets/ade20k/ade20k_utils.py | 308 +++++++++--------- .../ade20k_tests/test_ade20k.py | 6 +- 4 files changed, 163 insertions(+), 159 deletions(-) diff --git a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py index 0ad8e9d7df..c411a3ee61 100644 --- a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py @@ -14,8 +14,8 @@ def get_ade20k(): data_root = download.get_dataset_directory(root) - cache_fn = utils.cached_download(url) - utils.extractall(cache_fn, data_root, os.path.splitext(url)[1]) + cache_path = utils.cached_download(url) + utils.extractall(cache_path, data_root, os.path.splitext(url)[1]) return data_root diff --git a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py index e85a0772e4..e162ce0efa 100644 --- a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py @@ -12,8 +12,8 @@ def get_ade20k(): data_root = download.get_dataset_directory(root) - cache_fn = utils.cached_download(url) - utils.extractall(cache_fn, data_root, os.path.splitext(url)[1]) + cache_path = utils.cached_download(url) + utils.extractall(cache_path, data_root, os.path.splitext(url)[1]) return data_root diff --git a/chainercv/datasets/ade20k/ade20k_utils.py b/chainercv/datasets/ade20k/ade20k_utils.py index e6c5f9a843..a46feb353e 100644 --- a/chainercv/datasets/ade20k/ade20k_utils.py +++ b/chainercv/datasets/ade20k/ade20k_utils.py @@ -1,7 +1,7 @@ # The values used here are copied from CSAILVision/sceneparsing: # https://github.com/CSAILVision/sceneparsing -ade20k_label_names = [ +ade20k_label_names = ( 'wall', 'edifice', 'sky', @@ -152,157 +152,157 @@ 'glass', 'clock', 'flag' -] +) -ade20k_label_colors = [ - [120, 120, 120], - [180, 120, 120], - [6, 230, 230], - [80, 50, 50], - [4, 200, 3], - [120, 120, 80], - [140, 140, 140], - [204, 5, 255], - [230, 230, 230], - [4, 250, 7], - [224, 5, 255], - [235, 255, 7], - [150, 5, 61], - [120, 120, 70], - [8, 255, 51], - [255, 6, 82], - [143, 255, 140], - [204, 255, 4], - [255, 51, 7], - [204, 70, 3], - [0, 102, 200], - [61, 230, 250], - [255, 6, 51], - [11, 102, 255], - [255, 7, 71], - [255, 9, 224], - [9, 7, 230], - [220, 220, 220], - [255, 9, 92], - [112, 9, 255], - [8, 255, 214], - [7, 255, 224], - [255, 184, 6], - [10, 255, 71], - [255, 41, 10], - [7, 255, 255], - [224, 255, 8], - [102, 8, 255], - [255, 61, 6], - [255, 194, 7], - [255, 122, 8], - [0, 255, 20], - [255, 8, 41], - [255, 5, 153], - [6, 51, 255], - [235, 12, 255], - [160, 150, 20], - [0, 163, 255], - [140, 140, 140], - [250, 10, 15], - [20, 255, 0], - [31, 255, 0], - [255, 31, 0], - [255, 224, 0], - [153, 255, 0], - [0, 0, 255], - [255, 71, 0], - [0, 235, 255], - [0, 173, 255], - [31, 0, 255], - [11, 200, 200], - [255, 82, 0], - [0, 255, 245], - [0, 61, 255], - [0, 255, 112], - [0, 255, 133], - [255, 0, 0], - [255, 163, 0], - [255, 102, 0], - [194, 255, 0], - [0, 143, 255], - [51, 255, 0], - [0, 82, 255], - [0, 255, 41], - [0, 255, 173], - [10, 0, 255], - [173, 255, 0], - [0, 255, 153], - [255, 92, 0], - [255, 0, 255], - [255, 0, 245], - [255, 0, 102], - [255, 173, 0], - [255, 0, 20], - [255, 184, 184], - [0, 31, 255], - [0, 255, 61], - [0, 71, 255], - [255, 0, 204], - [0, 255, 194], - [0, 255, 82], - [0, 10, 255], - [0, 112, 255], - [51, 0, 255], - [0, 194, 255], - [0, 122, 255], - [0, 255, 163], - [255, 153, 0], - [0, 255, 10], - [255, 112, 0], - [143, 255, 0], - [82, 0, 255], - [163, 255, 0], - [255, 235, 0], - [8, 184, 170], - [133, 0, 255], - [0, 255, 92], - [184, 0, 255], - [255, 0, 31], - [0, 184, 255], - [0, 214, 255], - [255, 0, 112], - [92, 255, 0], - [0, 224, 255], - [112, 224, 255], - [70, 184, 160], - [163, 0, 255], - [153, 0, 255], - [71, 255, 0], - [255, 0, 163], - [255, 204, 0], - [255, 0, 143], - [0, 255, 235], - [133, 255, 0], - [255, 0, 235], - [245, 0, 255], - [255, 0, 122], - [255, 245, 0], - [10, 190, 212], - [214, 255, 0], - [0, 204, 255], - [20, 0, 255], - [255, 255, 0], - [0, 153, 255], - [0, 41, 255], - [0, 255, 204], - [41, 0, 255], - [41, 255, 0], - [173, 0, 255], - [0, 245, 255], - [71, 0, 255], - [122, 0, 255], - [0, 255, 184], - [0, 92, 255], - [184, 255, 0], - [0, 133, 255], - [255, 214, 0], - [25, 194, 194], - [102, 255, 0], - [92, 0, 255] -] +ade20k_label_colors = ( + (120, 120, 120), + (180, 120, 120), + (6, 230, 230), + (80, 50, 50), + (4, 200, 3), + (120, 120, 80), + (140, 140, 140), + (204, 5, 255), + (230, 230, 230), + (4, 250, 7), + (224, 5, 255), + (235, 255, 7), + (150, 5, 61), + (120, 120, 70), + (8, 255, 51), + (255, 6, 82), + (143, 255, 140), + (204, 255, 4), + (255, 51, 7), + (204, 70, 3), + (0, 102, 200), + (61, 230, 250), + (255, 6, 51), + (11, 102, 255), + (255, 7, 71), + (255, 9, 224), + (9, 7, 230), + (220, 220, 220), + (255, 9, 92), + (112, 9, 255), + (8, 255, 214), + (7, 255, 224), + (255, 184, 6), + (10, 255, 71), + (255, 41, 10), + (7, 255, 255), + (224, 255, 8), + (102, 8, 255), + (255, 61, 6), + (255, 194, 7), + (255, 122, 8), + (0, 255, 20), + (255, 8, 41), + (255, 5, 153), + (6, 51, 255), + (235, 12, 255), + (160, 150, 20), + (0, 163, 255), + (140, 140, 140), + (250, 10, 15), + (20, 255, 0), + (31, 255, 0), + (255, 31, 0), + (255, 224, 0), + (153, 255, 0), + (0, 0, 255), + (255, 71, 0), + (0, 235, 255), + (0, 173, 255), + (31, 0, 255), + (11, 200, 200), + (255, 82, 0), + (0, 255, 245), + (0, 61, 255), + (0, 255, 112), + (0, 255, 133), + (255, 0, 0), + (255, 163, 0), + (255, 102, 0), + (194, 255, 0), + (0, 143, 255), + (51, 255, 0), + (0, 82, 255), + (0, 255, 41), + (0, 255, 173), + (10, 0, 255), + (173, 255, 0), + (0, 255, 153), + (255, 92, 0), + (255, 0, 255), + (255, 0, 245), + (255, 0, 102), + (255, 173, 0), + (255, 0, 20), + (255, 184, 184), + (0, 31, 255), + (0, 255, 61), + (0, 71, 255), + (255, 0, 204), + (0, 255, 194), + (0, 255, 82), + (0, 10, 255), + (0, 112, 255), + (51, 0, 255), + (0, 194, 255), + (0, 122, 255), + (0, 255, 163), + (255, 153, 0), + (0, 255, 10), + (255, 112, 0), + (143, 255, 0), + (82, 0, 255), + (163, 255, 0), + (255, 235, 0), + (8, 184, 170), + (133, 0, 255), + (0, 255, 92), + (184, 0, 255), + (255, 0, 31), + (0, 184, 255), + (0, 214, 255), + (255, 0, 112), + (92, 255, 0), + (0, 224, 255), + (112, 224, 255), + (70, 184, 160), + (163, 0, 255), + (153, 0, 255), + (71, 255, 0), + (255, 0, 163), + (255, 204, 0), + (255, 0, 143), + (0, 255, 235), + (133, 255, 0), + (255, 0, 235), + (245, 0, 255), + (255, 0, 122), + (255, 245, 0), + (10, 190, 212), + (214, 255, 0), + (0, 204, 255), + (20, 0, 255), + (255, 255, 0), + (0, 153, 255), + (0, 41, 255), + (0, 255, 204), + (41, 0, 255), + (41, 255, 0), + (173, 0, 255), + (0, 245, 255), + (71, 0, 255), + (122, 0, 255), + (0, 255, 184), + (0, 92, 255), + (184, 255, 0), + (0, 133, 255), + (255, 214, 0), + (25, 194, 194), + (102, 255, 0), + (92, 0, 255) +) diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index 5d9ec10d60..fdcc6158b4 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -2,6 +2,8 @@ from chainer import testing from chainer.testing import attr +import numpy as np + from chainercv.datasets import ade20k_label_names from chainercv.datasets import ADE20KSemanticSegmentationDataset from chainercv.datasets import ADE20KTestImageDataset @@ -28,7 +30,9 @@ def test_ade20k_dataset(self): assert_is_semantic_segmentation_dataset( self.dataset, len(ade20k_label_names), n_example=10) else: - for img in self.dataset[:10]: + idx = np.random.permutation(np.arange(len(self.dataset))) + for i in idx[:10]: + img = self.dataset[i] assert_is_image(img, color=True) From 9f701025e64b759ffef02fe717911659a9acbd50 Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Thu, 28 Sep 2017 12:34:48 +0900 Subject: [PATCH 11/16] Fix test --- tests/datasets_tests/ade20k_tests/test_ade20k.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index fdcc6158b4..cba7707aed 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -30,8 +30,8 @@ def test_ade20k_dataset(self): assert_is_semantic_segmentation_dataset( self.dataset, len(ade20k_label_names), n_example=10) else: - idx = np.random.permutation(np.arange(len(self.dataset))) - for i in idx[:10]: + indices = np.random.permutation(np.arange(len(self.dataset))) + for i in indices[:10]: img = self.dataset[i] assert_is_image(img, color=True) From f9b719c3b6f7a3b3944862437a7c2e5c58098bde Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Fri, 29 Sep 2017 17:43:11 +0900 Subject: [PATCH 12/16] follow reviews --- chainercv/datasets/__init__.py | 4 +-- chainercv/datasets/ade20k/ade20k_utils.py | 4 +-- .../ade20k_tests/test_ade20k.py | 31 ++++++++++--------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/chainercv/datasets/__init__.py b/chainercv/datasets/__init__.py index 24a98e83d4..51738f01fd 100644 --- a/chainercv/datasets/__init__.py +++ b/chainercv/datasets/__init__.py @@ -1,7 +1,7 @@ from chainercv.datasets.ade20k.ade20k_semantic_segmentation_dataset import ADE20KSemanticSegmentationDataset # NOQA from chainercv.datasets.ade20k.ade20k_test_image_dataset import ADE20KTestImageDataset # NOQA -from chainercv.datasets.ade20k.ade20k_utils import ade20k_label_colors # NOQA -from chainercv.datasets.ade20k.ade20k_utils import ade20k_label_names # NOQA +from chainercv.datasets.ade20k.ade20k_utils import ade20k_semantic_segmentation_label_colors # NOQA +from chainercv.datasets.ade20k.ade20k_utils import ade20k_semantic_segmentation_label_names # NOQA from chainercv.datasets.camvid.camvid_dataset import camvid_ignore_label_color # NOQA from chainercv.datasets.camvid.camvid_dataset import camvid_label_colors # NOQA from chainercv.datasets.camvid.camvid_dataset import camvid_label_names # NOQA diff --git a/chainercv/datasets/ade20k/ade20k_utils.py b/chainercv/datasets/ade20k/ade20k_utils.py index a46feb353e..49cf71faae 100644 --- a/chainercv/datasets/ade20k/ade20k_utils.py +++ b/chainercv/datasets/ade20k/ade20k_utils.py @@ -1,7 +1,7 @@ # The values used here are copied from CSAILVision/sceneparsing: # https://github.com/CSAILVision/sceneparsing -ade20k_label_names = ( +ade20k_semantic_segmentation_label_names = ( 'wall', 'edifice', 'sky', @@ -154,7 +154,7 @@ 'flag' ) -ade20k_label_colors = ( +ade20k_semantic_segmentation_label_colors = ( (120, 120, 120), (180, 120, 120), (6, 230, 230), diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index cba7707aed..698af84a88 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -14,26 +14,29 @@ @testing.parameterize( {'split': 'train'}, {'split': 'val'}, - {'split': 'test'} ) -class TestADE20KDataset(unittest.TestCase): +class TestADE20KSemanticSegmentationDataset(unittest.TestCase): def setUp(self): - if self.split == 'train' or self.split == 'val': - self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) - else: - self.dataset = ADE20KTestImageDataset() + self.dataset = ADE20KSemanticSegmentationDataset(split=self.split) @attr.slow def test_ade20k_dataset(self): - if self.split == 'train' or self.split == 'val': - assert_is_semantic_segmentation_dataset( - self.dataset, len(ade20k_label_names), n_example=10) - else: - indices = np.random.permutation(np.arange(len(self.dataset))) - for i in indices[:10]: - img = self.dataset[i] - assert_is_image(img, color=True) + assert_is_semantic_segmentation_dataset( + self.dataset, len(ade20k_label_names), n_example=10) + + +class TestADE20KTestImageDataset(unittest.TestCase): + + def setUp(self): + self.dataset = ADE20KTestImageDataset() + + @attr.slow + def test_ade20k_dataset(self): + indices = np.random.permutation(np.arange(len(self.dataset))) + for i in indices[:10]: + img = self.dataset[i] + assert_is_image(img, color=True) testing.run_module(__name__, __file__) From 5b5af14704f641af0dfdbc31e06a255adcac9998 Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Sat, 30 Sep 2017 13:06:35 +0900 Subject: [PATCH 13/16] Fix test --- tests/datasets_tests/ade20k_tests/test_ade20k.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/datasets_tests/ade20k_tests/test_ade20k.py b/tests/datasets_tests/ade20k_tests/test_ade20k.py index 698af84a88..bb2a8dfc95 100644 --- a/tests/datasets_tests/ade20k_tests/test_ade20k.py +++ b/tests/datasets_tests/ade20k_tests/test_ade20k.py @@ -4,7 +4,7 @@ from chainer.testing import attr import numpy as np -from chainercv.datasets import ade20k_label_names +from chainercv.datasets import ade20k_semantic_segmentation_label_names from chainercv.datasets import ADE20KSemanticSegmentationDataset from chainercv.datasets import ADE20KTestImageDataset from chainercv.utils import assert_is_semantic_segmentation_dataset @@ -23,7 +23,8 @@ def setUp(self): @attr.slow def test_ade20k_dataset(self): assert_is_semantic_segmentation_dataset( - self.dataset, len(ade20k_label_names), n_example=10) + self.dataset, len(ade20k_semantic_segmentation_label_names), + n_example=10) class TestADE20KTestImageDataset(unittest.TestCase): From 1394f6f676d61c3b1573a4a923041ece7595229b Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Thu, 5 Oct 2017 15:10:52 +0900 Subject: [PATCH 14/16] Reflect reviews --- .../ade20k/ade20k_semantic_segmentation_dataset.py | 9 +-------- chainercv/datasets/ade20k/ade20k_test_image_dataset.py | 9 +-------- chainercv/datasets/ade20k/ade20k_utils.py | 8 ++++++++ docs/source/reference/datasets.rst | 2 +- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py index c411a3ee61..9c443b4294 100644 --- a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py @@ -12,13 +12,6 @@ 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`_. @@ -42,7 +35,7 @@ class ADE20KSemanticSegmentationDataset(dataset.DatasetMixin): def __init__(self, data_dir='auto', split='train'): if data_dir is 'auto': - data_dir = get_ade20k() + data_dir = get_ade20k(root, url) if split == 'train' or split == 'val': img_dir = os.path.join( diff --git a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py index e162ce0efa..5db56f55c6 100644 --- a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py @@ -10,13 +10,6 @@ url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.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 ADE20KTestImageDataset(dataset.DatasetMixin): """Image dataset for test split of `ADE20K`_. @@ -36,7 +29,7 @@ class ADE20KTestImageDataset(dataset.DatasetMixin): def __init__(self, data_dir='auto'): if data_dir is 'auto': - data_dir = get_ade20k() + data_dir = get_ade20k(root, url) img_dir = os.path.join(data_dir, 'release_test', 'testing') self.img_paths = sorted(glob.glob(os.path.join(img_dir, '*.jpg'))) diff --git a/chainercv/datasets/ade20k/ade20k_utils.py b/chainercv/datasets/ade20k/ade20k_utils.py index 49cf71faae..65fd00773c 100644 --- a/chainercv/datasets/ade20k/ade20k_utils.py +++ b/chainercv/datasets/ade20k/ade20k_utils.py @@ -1,6 +1,14 @@ # The values used here are copied from CSAILVision/sceneparsing: # https://github.com/CSAILVision/sceneparsing + +def get_ade20k(root, url): + 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 + + ade20k_semantic_segmentation_label_names = ( 'wall', 'edifice', diff --git a/docs/source/reference/datasets.rst b/docs/source/reference/datasets.rst index 01b789b8d1..e305719718 100644 --- a/docs/source/reference/datasets.rst +++ b/docs/source/reference/datasets.rst @@ -26,7 +26,7 @@ ADE20KSemanticSegmentationDataset .. autoclass:: ADE20KSemanticSegmentationDataset ADE20KTestImageDataset -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~ .. autoclass:: ADE20KTestImageDataset CamVid From 5c69e06d9bd4a7de0f92cb8f192c44c4065afbee Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Thu, 5 Oct 2017 15:12:52 +0900 Subject: [PATCH 15/16] flake8 --- .../datasets/ade20k/ade20k_semantic_segmentation_dataset.py | 5 +++-- chainercv/datasets/ade20k/ade20k_test_image_dataset.py | 5 +++-- chainercv/datasets/ade20k/ade20k_utils.py | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py index 9c443b4294..2d2cd73320 100644 --- a/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_semantic_segmentation_dataset.py @@ -4,10 +4,11 @@ import numpy as np from chainer import dataset -from chainer.dataset import download -from chainercv import utils from chainercv.utils import read_image +from chainercv.datasets.ade20k.ade20k_utils import get_ade20k + + root = 'pfnet/chainercv/ade20k' url = 'http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip' diff --git a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py index 5db56f55c6..92984fab9a 100644 --- a/chainercv/datasets/ade20k/ade20k_test_image_dataset.py +++ b/chainercv/datasets/ade20k/ade20k_test_image_dataset.py @@ -2,10 +2,11 @@ import os from chainer import dataset -from chainer.dataset import download -from chainercv import utils from chainercv.utils import read_image +from chainercv.datasets.ade20k.ade20k_utils import get_ade20k + + root = 'pfnet/chainercv/ade20k' url = 'http://data.csail.mit.edu/places/ADEchallenge/release_test.zip' diff --git a/chainercv/datasets/ade20k/ade20k_utils.py b/chainercv/datasets/ade20k/ade20k_utils.py index 65fd00773c..0d22dd7d6b 100644 --- a/chainercv/datasets/ade20k/ade20k_utils.py +++ b/chainercv/datasets/ade20k/ade20k_utils.py @@ -1,6 +1,9 @@ # The values used here are copied from CSAILVision/sceneparsing: # https://github.com/CSAILVision/sceneparsing +from chainer.dataset import download +from chainercv import utils + def get_ade20k(root, url): data_root = download.get_dataset_directory(root) From d6bc1346606caa96b26c89dfb0c6b280408757ff Mon Sep 17 00:00:00 2001 From: Shunta Saito Date: Thu, 5 Oct 2017 15:13:29 +0900 Subject: [PATCH 16/16] import os --- chainercv/datasets/ade20k/ade20k_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chainercv/datasets/ade20k/ade20k_utils.py b/chainercv/datasets/ade20k/ade20k_utils.py index 0d22dd7d6b..9ac702edfe 100644 --- a/chainercv/datasets/ade20k/ade20k_utils.py +++ b/chainercv/datasets/ade20k/ade20k_utils.py @@ -1,6 +1,8 @@ # The values used here are copied from CSAILVision/sceneparsing: # https://github.com/CSAILVision/sceneparsing +import os + from chainer.dataset import download from chainercv import utils