コード例 #1
0
ファイル: project.py プロジェクト: nerdinand/cvat
    def init_from_db(self):
        self.reset()

        for task in self.db_tasks:
            annotation = TaskAnnotation(pk=task.id)
            annotation.init_from_db()
            self.annotation_irs[task.id] = annotation.ir_data
コード例 #2
0
    def test_api_v2_dump_and_upload_several_jobs(self):
        job_test_cases = ["first", "all"]
        with TestDir() as test_dir:
            task_data = self.copy_pcd_file_and_get_task_data(test_dir)
            task = self._create_task(self.task_many_jobs, task_data)
            task_id = task["id"]
            annotation = self._get_tmp_annotation(task, self.cuboid_example)

            for format_name, job_test_case in itertools.product(
                    self.format_names, job_test_cases):
                with self.subTest(format=f"{format_name}_{job_test_case}"):
                    jobs = self._get_jobs(task_id)
                    if job_test_case == "all":
                        for job in jobs:
                            response = self._put_api_v2_job_id_annotations(
                                job["id"], annotation)
                            self.assertEqual(response.status_code,
                                             status.HTTP_200_OK)
                    else:
                        response = self._put_api_v2_job_id_annotations(
                            jobs[1]["id"], annotation)
                        self.assertEqual(response.status_code,
                                         status.HTTP_200_OK)
                    task_ann_prev = TaskAnnotation(task_id)
                    task_ann_prev.init_from_db()
                    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._remove_annotations(task_id)
コード例 #3
0
    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)
        dm_dataset = datumaro.components.project.Dataset.from_extractors(extractor)
        self.assertEqual(4, len(dm_dataset.get("image_1").annotations))
コード例 #4
0
ファイル: test_formats.py プロジェクト: z80020100/cvat
    def test_no_outside_shapes_in_per_frame_export(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"]))

        outside_count = 0
        for f in task_data.group_by_frame(include_empty=True):
            for ann in f.labeled_shapes:
                if getattr(ann, 'outside', None):
                    outside_count += 1
        self.assertEqual(0, outside_count)
コード例 #5
0
    def test_api_v2_dump_and_upload_empty_annotation(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"]
            task_ann_prev = TaskAnnotation(task_id)
            task_ann_prev.init_from_db()

            for format_name in self.format_names:
                with self.subTest(format=f"{format_name}"):
                    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))

                    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()

                    self.assertEqual(len(task_ann.data["shapes"]), 0)
                    self.assertEqual(task_ann_prev.data["shapes"],
                                     task_ann.data["shapes"])
コード例 #6
0
    def test_api_v2_remove_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"]
            jobs = self._get_jobs(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_v2_job_id_annotations(
                        jobs[0]["id"], annotation, CREATE_ACTION, self.admin)
                    self.assertEqual(response.status_code, status.HTTP_200_OK)

                    task_ann_prev = TaskAnnotation(task_id)
                    task_ann_prev.init_from_db()
                    annotation["shapes"][0]["id"] = task_ann_prev.data[
                        "shapes"][0]["id"]
                    response = self._patch_api_v2_job_id_annotations(
                        jobs[0]["id"], annotation, DELETE_ACTION, user)
                    self.assertEqual(response.status_code, edata["code"])

                    if edata["annotation_changed"]:
                        task_ann = TaskAnnotation(task_id)
                        task_ann.init_from_db()
                        self.assertTrue(len(task_ann.data["shapes"]) == 0)
コード例 #7
0
    def test_api_v2_update_annotation_in_task(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)
            response = self._put_api_v2_task_id_annotations(
                task_id, annotation)
            self.assertEqual(response.status_code, status.HTTP_200_OK)

            for user, edata in list(self.expected_action.items()):
                with self.subTest(format=edata["name"]):
                    task_ann_prev = TaskAnnotation(task_id)
                    task_ann_prev.init_from_db()
                    annotation["shapes"][0]["points"] = [
                        x + 0.1 for x in annotation["shapes"][0]["points"]
                    ]
                    annotation["shapes"][0]["id"] = task_ann_prev.data[
                        "shapes"][0]["id"]
                    response = self._patch_api_v2_task_id_annotations(
                        task_id, annotation, UPDATE_ACTION, user)
                    self.assertEqual(response.status_code, edata["code"],
                                     task_id)

                    if edata["annotation_changed"]:
                        task_ann = TaskAnnotation(task_id)
                        task_ann.init_from_db()
                        self.assertEqual(task_ann.data["shapes"],
                                         annotation["shapes"])
コード例 #8
0
    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)
コード例 #9
0
 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)
コード例 #10
0
ファイル: test_formats.py プロジェクト: z80020100/cvat
    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)
コード例 #11
0
    def test_api_v2_rewrite_annotation(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:
                with self.subTest(format=f"{format_name}"):
                    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()
                    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)
                    # rewrite annotation
                    annotation_copy = copy.deepcopy(annotation)
                    annotation_copy["shapes"][0]["points"] = [0] * 16
                    response = self._put_api_v2_task_id_annotations(
                        task_id, annotation_copy)
                    self.assertEqual(response.status_code, status.HTTP_200_OK)

                    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(len(task_ann_prev.data["shapes"]),
                                     len(task_ann.data["shapes"]))
                    self.assertEqual(task_ann_prev.data["shapes"],
                                     task_ann.data["shapes"])
コード例 #12
0
    def _test_can_import_annotations(self, task, import_format):
        with tempfile.TemporaryDirectory() as temp_dir:
            file_path = osp.join(temp_dir, import_format)

            export_format = import_format
            if import_format == "CVAT 1.1":
                export_format = "CVAT for images 1.1"

            dm.task.export_task(task["id"], file_path, export_format)
            expected_ann = TaskAnnotation(task["id"])
            expected_ann.init_from_db()

            dm.task.import_task_annotations(task["id"], file_path,
                                            import_format)
            actual_ann = TaskAnnotation(task["id"])
            actual_ann.init_from_db()

            self.assertEqual(len(expected_ann.data), len(actual_ann.data))