def test_frame_matching(self): task_paths = [ 'a.jpg', 'a/a.jpg', 'a/b.jpg', 'b/a.jpg', 'b/c.jpg', 'a/b/c.jpg', 'a/b/d.jpg', ] images = self._generate_task_images(task_paths) task = self._generate_task(images) task_data = TaskData(AnnotationIR(), Task.objects.get(pk=task["id"])) for input_path, expected, root in [ ('z.jpg', None, ''), # unknown item ('z/a.jpg', None, ''), # unknown item ('d.jpg', 'a/b/d.jpg', 'a/b'), # match with root hint ('b/d.jpg', 'a/b/d.jpg', 'a'), # match with root hint ] + list(zip(task_paths, task_paths, [None] * len(task_paths))): # exact matches with self.subTest(input=input_path): actual = task_data.match_frame(input_path, root) if actual is not None: actual = task_data.frame_info[actual]['path'] self.assertEqual(expected, actual)
def test_cant_make_abs_frame_id_from_unknown(self): images = self._generate_task_images(3) images['frame_filter'] = 'step=2' task = self._generate_task(images) task_data = TaskData(AnnotationIR(), Task.objects.get(pk=task['id'])) with self.assertRaisesRegex(ValueError, r'Unknown'): task_data.abs_frame_id(2) # the task has only 0 and 1 indices
def test_can_make_abs_frame_id_from_known(self): images = self._generate_task_images(6) images['frame_filter'] = 'step=2' images['start_frame'] = 1 task = self._generate_task(images) task_data = TaskData(AnnotationIR(), Task.objects.get(pk=task['id'])) self.assertEqual(5, task_data.abs_frame_id(2))
def test_dataset_root(self): for task_paths, dataset_paths, expected in [ ([ 'a.jpg', 'b/c/a.jpg' ], [ 'a.jpg', 'b/c/a.jpg' ], ''), ([ 'b/a.jpg', 'b/c/a.jpg' ], [ 'a.jpg', 'c/a.jpg' ], 'b'), # 'images from share' case ([ 'b/c/a.jpg' ], [ 'a.jpg' ], 'b/c'), # 'images from share' case ([ 'a.jpg' ], [ 'z.jpg' ], None), ]: with self.subTest(expected=expected): images = self._generate_task_images(task_paths) task = self._generate_task(images) task_data = TaskData(AnnotationIR(), Task.objects.get(pk=task["id"])) dataset = [ datumaro.components.extractor.DatasetItem( id=osp.splitext(p)[0]) for p in dataset_paths] root = find_dataset_root(dataset, task_data) self.assertEqual(expected, root)