MCPcopy Create free account
hub / github.com/lingeringlight/START / __init__

Method __init__

data/datasets.py:37–65  ·  view source on GitHub ↗
(self, root, train=True, transform=None)

Source from the content-addressed store, hash-verified

35 """
36
37 def __init__(self, root, train=True, transform=None):
38 self.root = root
39 self.phase = 'train' if train else 'test'
40 # self.resize = resize
41 self.num_classes = 196
42
43 self.images = []
44 self.labels = []
45
46 list_path = os.path.join(root, 'cars_anno.pkl')
47
48 list_mat = pickle.load(open(list_path, 'rb'))
49 num_inst = len(list_mat['annotations']['relative_im_path'][0])
50 for i in range(num_inst):
51 if self.phase == 'train' and list_mat['annotations']['test'][0][i].item() == 0:
52 path = list_mat['annotations']['relative_im_path'][0][i].item()
53 label = list_mat['annotations']['class'][0][i].item()
54 self.images.append(path)
55 self.labels.append(label)
56 elif self.phase != 'train' and list_mat['annotations']['test'][0][i].item() == 1:
57 path = list_mat['annotations']['relative_im_path'][0][i].item()
58 label = list_mat['annotations']['class'][0][i].item()
59 self.images.append(path)
60 self.labels.append(label)
61
62 print('Car Dataset with {} instances for {} phase'.format(len(self.images), self.phase))
63
64 # transform
65 self.transform = transform
66
67 def __getitem__(self, item):
68 # image

Callers

nothing calls this directly

Calls 1

printFunction · 0.85

Tested by

no test coverage detected