def test_get_det_gt(self): image = Image.load_from_json(self.classes, self.data) objects_table = Table(np.array([ [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0], [2, 2, 2, 2, 2, 0, 0]]), self.columns) assert(image.get_objects() == objects_table) data = self.data.copy() data['objects'][0]['diff'] = 1 data['objects'][1]['trun'] = 1 image = Image.load_from_json(self.classes, data) objects_table = Table(np.array([ [0, 0, 0, 0, 0, 1, 0], [1, 1, 1, 1, 1, 0, 1], [2, 2, 2, 2, 2, 0, 0]]), self.columns) assert(image.get_objects( with_diff=True, with_trun=True) == objects_table) objects_table = Table(np.array([ [1, 1, 1, 1, 1, 0, 1], [2, 2, 2, 2, 2, 0, 0]]), self.columns) assert(image.get_objects( with_diff=False, with_trun=True) == objects_table) # this should be default behavior assert(image.get_objects() == objects_table) objects_table = Table(np.array([ [2, 2, 2, 2, 2, 0, 0]]), self.columns) assert(image.get_objects( with_diff=False, with_trun=False) == objects_table) objects_table = Table(np.array([ [0, 0, 0, 0, 0, 1, 0], [2, 2, 2, 2, 2, 0, 0]]), self.columns) assert(image.get_objects( with_diff=True, with_trun=False) == objects_table) # What if everything is filtered out? data['objects'] = data['objects'][:-1] objects_table = Table(np.array([ [0, 0, 0, 0, 0, 1, 0], [1, 1, 1, 1, 1, 0, 1]]), self.columns) image = Image.load_from_json(self.classes, data) assert(image.get_objects( with_diff=True, with_trun=True) == objects_table) assert( image.get_objects(with_diff=False, with_trun=False).shape[0] == 0)
def test_load_json_data(self): image = Image.load_from_json(self.classes, self.data) assert(image.width == 640 and image.height == 480) assert(image.classes == ['A', 'B', 'C']) assert(image.name == 'test_image') objects_table = Table(np.array([ [0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0], [2, 2, 2, 2, 2, 0, 0]]), self.columns) assert(image.objects_table == objects_table)
def test_get_cls_counts_and_gt(self): data = self.data.copy() image = Image.load_from_json(self.classes, data) assert(np.all(image.get_cls_counts() == np.array([1, 1, 1]))) assert(np.all(image.get_cls_gt() == np.array([True, True, True]))) assert(image.contains_class('A')) assert(image.contains_class('B')) data['objects'][0]['class'] = 'B' image = Image.load_from_json(self.classes, data) # doesn't actually have to be Series, can be ndarray for comparison assert(np.all(image.get_cls_counts() == np.array([0, 2, 1]))) assert(np.all(image.get_cls_gt() == np.array([False, True, True]))) assert(not image.contains_class('A')) assert(image.contains_class('B')) data['objects'] = [] image = Image.load_from_json(self.classes, data) assert(np.all(image.get_cls_counts() == np.array([0, 0, 0]))) assert(np.all(image.get_cls_gt() == np.array([False, False, False]))) assert(not image.contains_class('A')) assert(not image.contains_class('B'))
def load_from_json(self, filename): """ Load all parameters of the dataset from a JSON file. Parameters ---------- filename: string path to JSON data file Returns ------- self """ with open(filename) as f: json_data = json.load(f) self.classes = json_data['classes'] self.images = [Image.load_from_json( self.classes, image) for image in json_data['images']] return self.after_load()