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

Class Caltech101Silhouettes

tensorpack/dataflow/dataset/caltech101.py:24–72  ·  view source on GitHub ↗

Produces [image, label] in Caltech101 Silhouettes dataset, image is 28x28 in the range [0,1], label is an int in the range [0,100].

Source from the content-addressed store, hash-verified

22
23
24class Caltech101Silhouettes(RNGDataFlow):
25 """
26 Produces [image, label] in Caltech101 Silhouettes dataset,
27 image is 28x28 in the range [0,1], label is an int in the range [0,100].
28 """
29
30 _DIR_NAME = "caltech101_data"
31 _SOURCE_URL = "https://people.cs.umass.edu/~marlin/data/"
32
33 def __init__(self, name, shuffle=True, dir=None):
34 """
35 Args:
36 name (str): 'train', 'test', 'val'
37 shuffle (bool): shuffle the dataset
38 """
39 if dir is None:
40 dir = get_dataset_path(self._DIR_NAME)
41 assert name in ['train', 'test', 'val']
42 self.name = name
43 self.shuffle = shuffle
44
45 def get_images_and_labels(data_file):
46 f = maybe_download(self._SOURCE_URL + data_file, dir)
47 data = scipy.io.loadmat(f)
48 return data
49
50 self.data = get_images_and_labels("caltech101_silhouettes_28_split1.mat")
51
52 if self.name == "train":
53 self.images = self.data["train_data"].reshape((4100, 28, 28))
54 self.labels = self.data["train_labels"].ravel() - 1
55 elif self.name == "test":
56 self.images = self.data["test_data"].reshape((2307, 28, 28))
57 self.labels = self.data["test_labels"].ravel() - 1
58 else:
59 self.images = self.data["val_data"].reshape((2264, 28, 28))
60 self.labels = self.data["val_labels"].ravel() - 1
61
62 def __len__(self):
63 return self.images.shape[0]
64
65 def __iter__(self):
66 idxs = list(range(self.__len__()))
67 if self.shuffle:
68 self.rng.shuffle(idxs)
69 for k in idxs:
70 img = self.images[k]
71 label = self.labels[k]
72 yield [img, label]
73
74
75try:

Callers 1

caltech101.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…