Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
do not use lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu2172 committed Jun 20, 2018
1 parent 6665fbf commit a263992
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ def __init__(self, data_dir='auto', split='train'):
self.img_paths = sorted(glob.glob(os.path.join(img_dir, '*.jpg')))
self.label_paths = sorted(glob.glob(os.path.join(label_dir, '*.png')))

self.add_getter('img', lambda i: read_image(self.img_paths[i]))
self.add_getter('iabel', lambda i: read_image(
self.label_paths[i], dtype=np.int32, color=False)[0])
self.add_getter('img', self._get_image)
self.add_getter('label', self._get_label)

def __len__(self):
return len(self.img_paths)

def _get_image(self, i):
return read_image(self.img_paths[i])

def _get_label(self, i):
return read_image(
self.label_paths[i], dtype=np.int32, color=False)[0]
7 changes: 5 additions & 2 deletions chainercv/datasets/ade20k/ade20k_test_image_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import glob
mport glob
import os

from chainercv.chainer_experimental.datasets.sliceable import GetterDataset
Expand Down Expand Up @@ -41,8 +41,11 @@ def __init__(self, data_dir='auto'):
img_dir = os.path.join(data_dir, 'release_test', 'testing')
self.img_paths = sorted(glob.glob(os.path.join(img_dir, '*.jpg')))

self.add_getter('img', lambda i: read_image(self.img_paths[i]))
self.add_getter('img', self._get_image)
self.keys = 'img' # do not return tuple

def __len__(self):
return len(self.img_paths)

def _get_image(self, i):
return read_image(self.img_paths[i])
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ def __init__(self, data_dir='auto', label_resolution=None, split='train',
img_path = os.path.join(img_dir, city_dname, img_path)
self.img_paths.append(img_path)

self.add_getter('img', lambda i: read_image(self.img_paths[i]))
self.add_getter('img', self._get_image)
self.add_getter('label', self._get_label)

def __len__(self):
return len(self.img_paths)

def _get_image(self, i):
return read_image(self.img_paths[i])

def _get_label(self, i):
label_orig = read_image(
self.label_paths[i], dtype=np.int32, color=False)[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ def __init__(self, data_dir='auto'):
os.path.join(city_dname, '*_leftImg8bit.png'))):
self.img_paths.append(img_path)

self.add_getter('img', lambda i: read_image(self.img_paths[i]))
self.add_getter('img', self._get_image)
self.keys = 'img' # do not return tuple

def __len__(self):
return len(self.img_paths)

def _get_image(self, i):
return read_image(self.img_paths[i])
5 changes: 4 additions & 1 deletion chainercv/datasets/cub/cub_label_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ def __init__(self, data_dir='auto', return_bb=False,
d_label in open(image_class_labels_file)]
self._labels = np.array(labels, dtype=np.int32)

self.add_getter('label', lambda i: self._labels[i])
self.add_getter('label', self._get_label)

keys = ('img', 'label')
if return_bb:
keys += ('bb',)
if return_prob_map:
keys += ('prob_map',)
self.keys = keys

def _get_label(self, i):
return self._labels[i]
11 changes: 8 additions & 3 deletions chainercv/datasets/directory_parsing_label_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,14 @@ def __init__(self, root, check_img_file=None, color=True,
self.img_paths, self.labels = _parse_label_dataset(
root, label_names, check_img_file)

self.add_getter('img', lambda i:
read_image(self.img_paths[i], color=self.color))
self.add_getter('label', lambda i: self.labels[i])
self.add_getter('img', self._get_image)
self.add_getter('label', self._get_label)

def __len__(self):
return len(self.img_paths)

def _get_image(self, i):
return read_image(self.img_paths[i], color=self.color)

def _get_label(self, i):
return self.labels[i]
18 changes: 12 additions & 6 deletions chainercv/datasets/online_products/online_products_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,18 @@ def __init__(self, data_dir='auto', split='train'):
self.super_class_ids += [int(id_[2]) - 1 for id_ in ids_tmp]
self.paths += [os.path.join(data_dir, id_[3]) for id_ in ids_tmp]

self.add_getter('img', lambda i:
utils.read_image(self.paths[i], color=True))
self.add_getter('label', lambda i:
np.array(self.class_ids[i], np.int32))
self.add_getter('super_label', lambda i:
np.array(self.super_class_ids[i], np.int32))
self.add_getter('img', self._get_label)
self.add_getter('label', self._get_label)
self.add_getter('super_label', self._get_super_label)

def __len__(self):
return len(self.paths)

def _get_image(self, i):
return utils.read_image(self.paths[i], color=True)

def _get_label(self, i):
return np.array(self.class_ids[i], np.int32)

def _get_super_label(self, i):
return np.array(self.super_class_ids[i], np.int32)

0 comments on commit a263992

Please sign in to comment.