def test_api_v1_upload_annotation_with_attributes(self): with TestDir() as test_dir: task_data = self.copy_pcd_file_and_get_task_data(test_dir) task = self._create_task(self.task_with_attributes, task_data) task_id = task["id"] for format_name in self.format_names: annotation = self._get_tmp_annotation(task, self.cuboid_example) response = self._put_api_v1_task_id_annotations(task_id, annotation) self.assertEqual(response.status_code, status.HTTP_200_OK) task_ann_prev = TaskAnnotation(task_id) task_ann_prev.init_from_db() with self.subTest(format=f"{format_name}_dump"): url = self._generate_url_dump_tasks_annotations(task_id) file_name = osp.join(test_dir, f"{format_name}.zip") data = { "format": format_name, "action": "download", } self._download_file(url, data, self.admin, file_name) self.assertTrue(osp.exists(file_name)) self._remove_annotations(task_id) with self.subTest(format=f"{format_name}_upload"): file_name = osp.join(test_dir, f"{format_name}.zip") url = self._generate_url_upload_tasks_annotations(task_id, format_name) with open(file_name, 'rb') as binary_file: self._upload_file(url, binary_file, self.admin) task_ann = TaskAnnotation(task_id) task_ann.init_from_db() task_ann_prev.data["shapes"][0].pop("id") task_ann.data["shapes"][0].pop("id") self.assertEqual(task_ann_prev.data["shapes"][0]["attributes"], task_ann.data["shapes"][0]["attributes"])
def test_can_skip_outside(self): images = self._generate_task_images(3) task = self._generate_task(images) self._generate_annotations(task) task_ann = TaskAnnotation(task["id"]) task_ann.init_from_db() task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task["id"])) extractor = CvatTaskDataExtractor(task_data, include_outside=False) dm_dataset = datumaro.components.project.Dataset.from_extractors(extractor) self.assertEqual(4, len(dm_dataset.get("image_1").annotations)) extractor = CvatTaskDataExtractor(task_data, include_outside=True) dm_dataset = datumaro.components.project.Dataset.from_extractors(extractor) self.assertEqual(5, len(dm_dataset.get("image_1").annotations))
def test_api_v2_export_dataset(self): with TestDir() as test_dir: task_data = self.copy_pcd_file_and_get_task_data(test_dir) task = self._create_task(self.task, task_data) task_id = task["id"] for format_name in self.format_names: annotation = self._get_tmp_annotation(task, self.cuboid_example) response = self._put_api_v2_task_id_annotations( task_id, annotation) self.assertEqual(response.status_code, status.HTTP_200_OK) task_ann_prev = TaskAnnotation(task_id) task_ann_prev.init_from_db() for user, edata in list(self.expected_dump_upload.items()): with self.subTest( format=f"{format_name}_{edata['name']}_export"): url = self._generate_url_dump_dataset(task_id) file_name = osp.join( test_dir, f"{format_name}_{edata['name']}.zip") data = { "format": format_name, } response = self._get_request_with_data(url, data, user) self.assertEqual(response.status_code, edata['accept code']) response = self._get_request_with_data(url, data, user) self.assertEqual(response.status_code, edata['create code']) data = { "format": format_name, "action": "download", } response = self._get_request_with_data(url, data, user) self.assertEqual(response.status_code, edata['code']) if response.status_code == status.HTTP_200_OK: content = io.BytesIO(b"".join( response.streaming_content)) with open(file_name, "wb") as f: f.write(content.getvalue()) self.assertEqual(osp.exists(file_name), edata['file_exists']) self._check_dump_content(content, task_ann_prev.data, format_name, related_files=False)
def test_api_v1_create_annotation_in_job(self): with TestDir() as test_dir: task_data = self.copy_pcd_file_and_get_task_data(test_dir) task = self._create_task(self.task, task_data) task_id = task["id"] annotation = self._get_tmp_annotation(task, self.cuboid_example) for user, edata in list(self.expected_action.items()): with self.subTest(format=edata["name"]): response = self._patch_api_v1_task_id_annotations(task_id, annotation, CREATE_ACTION, user) self.assertEqual(response.status_code, edata["code"]) if edata["annotation_changed"]: task_ann = TaskAnnotation(task_id) task_ann.init_from_db() task_shape = task_ann.data["shapes"][0] task_shape.pop("id") self.assertEqual(task_shape, annotation["shapes"][0]) self._remove_annotations(task_id)
def test_frames_outside_are_not_generated(self): # https://github.com/openvinotoolkit/cvat/issues/2827 images = self._generate_task_images(10) images['start_frame'] = 0 task = self._generate_task(images, overlap=3, segment_size=6) annotations = { "version": 0, "tags": [], "shapes": [], "tracks": [ { "frame": 6, "label_id": task["labels"][0]["id"], "group": None, "source": "manual", "attributes": [], "shapes": [ { "frame": 6, "points": [1.0, 2.1, 100, 300.222], "type": "rectangle", "occluded": False, "outside": False, "attributes": [], }, ] }, ] } self._put_api_v1_job_id_annotations( task["segments"][2]["jobs"][0]["id"], annotations) task_ann = TaskAnnotation(task["id"]) task_ann.init_from_db() task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task['id'])) i = -1 for i, frame in enumerate(task_data.group_by_frame()): self.assertTrue(frame.frame in range(6, 10)) self.assertEqual(i + 1, 4)