MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / Places365Standard

Class Places365Standard

tensorpack/dataflow/dataset/places.py:10–66  ·  view source on GitHub ↗

The Places365-Standard Dataset, in low resolution format only. Produces BGR images of shape (256, 256, 3) in range [0, 255].

Source from the content-addressed store, hash-verified

8
9
10class Places365Standard(RNGDataFlow):
11 """
12 The Places365-Standard Dataset, in low resolution format only.
13 Produces BGR images of shape (256, 256, 3) in range [0, 255].
14 """
15 def __init__(self, dir, name, shuffle=None):
16 """
17 Args:
18 dir: path to the Places365-Standard dataset in its "easy directory
19 structure". See http://places2.csail.mit.edu/download.html
20 name: one of "train" or "val"
21 shuffle (bool): shuffle the dataset. Defaults to True if name=='train'.
22 """
23 assert name in ['train', 'val'], name
24 dir = os.path.expanduser(dir)
25 assert os.path.isdir(dir), dir
26 self.name = name
27 if shuffle is None:
28 shuffle = name == 'train'
29 self.shuffle = shuffle
30
31 label_file = os.path.join(dir, name + ".txt")
32 all_files = []
33 labels = set()
34 with open(label_file) as f:
35 for line in f:
36 filepath = os.path.join(dir, line.strip())
37 line = line.strip().split("/")
38 label = line[1]
39 all_files.append((filepath, label))
40 labels.add(label)
41 self._labels = sorted(labels)
42 # class ids are sorted alphabetically:
43 # https://github.com/CSAILVision/places365/blob/master/categories_places365.txt
44 labelmap = {label: id for id, label in enumerate(self._labels)}
45 self._files = [(path, labelmap[x]) for path, x in all_files]
46 logger.info("Found {} images in {}.".format(len(self._files), label_file))
47
48 def get_label_names(self):
49 """
50 Returns:
51 [str]: name of each class.
52 """
53 return self._labels
54
55 def __len__(self):
56 return len(self._files)
57
58 def __iter__(self):
59 idxs = np.arange(len(self._files))
60 if self.shuffle:
61 self.rng.shuffle(idxs)
62 for k in idxs:
63 fname, label = self._files[k]
64 im = cv2.imread(fname, cv2.IMREAD_COLOR)
65 assert im is not None, fname
66 yield [im, label]
67

Callers 1

places.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…