Skip to content

Commit

Permalink
Add test for wrong attribute import in tracks (#3279)
Browse files Browse the repository at this point in the history
* add test for wrong attribute import in tracks

* fix annotation for test

* small fix

* fix annotattion for test

* add function to get data from task
  • Loading branch information
yasakova-anastasia authored Jun 10, 2021
1 parent dc9f679 commit 4b82336
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 10 deletions.
35 changes: 35 additions & 0 deletions cvat/apps/dataset_manager/tests/assets/annotations.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@
}
]
},
"CVAT for video 1.1 attributes in tracks": {
"version": 0,
"tags": [],
"shapes": [],
"tracks": [
{
"frame": 0,
"label_id": null,
"group": 0,
"source": "manual",
"shapes": [
{
"type": "polygon",
"occluded": false,
"z_order": 0,
"points": [25.04, 13.7, 35.85, 20.2, 16.65, 19.8],
"frame": 0,
"outside": true,
"attributes": []
},
{
"type": "polygon",
"occluded": false,
"z_order": 0,
"points": [25.04, 13.7, 35.85, 20.2, 16.65, 19.8],
"frame": 1,
"outside": false,
"attributes": [],
"keyframe": true
}
],
"attributes": []
}
]
},
"WiderFace 1.0": {
"version": 0,
"tags": [],
Expand Down
13 changes: 13 additions & 0 deletions cvat/apps/dataset_manager/tests/assets/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,18 @@
]
}
]
},
"many jobs": {
"name": "many jobs",
"overlap": 0,
"segment_size": 5,
"owner_id": 1,
"labels": [
{
"name": "car",
"color": "#2080c0",
"attributes": []
}
]
}
}
57 changes: 47 additions & 10 deletions cvat/apps/dataset_manager/tests/test_rest_api_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def _create_task(self, data, image_data):

return task

def _get_data_from_task(self, task_id, include_images):
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_images=include_images)
return Dataset.from_extractors(extractor)

def _get_request_with_data(self, path, data, user):
with ForceLogin(user, self.client):
response = self.client.get(path, data)
Expand Down Expand Up @@ -231,11 +238,45 @@ def test_api_v1_check_widerface_with_all_attributes(self):
self._create_annotations(task, f'{dump_format_name}', "random")

task_id = task["id"]
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_images=include_images)
data_from_task_before_upload = Dataset.from_extractors(extractor)
data_from_task_before_upload = self._get_data_from_task(task_id, include_images)

# dump annotations
url = self._generate_url_dump_tasks_annotations(task_id)
data = {
"format": dump_format_name,
"action": "download",
}
with TestDir() as test_dir:
file_zip_name = osp.join(test_dir, f'{test_name}_{dump_format_name}.zip')
self._download_file(url, data, self.admin, file_zip_name)
self._check_downloaded_file(file_zip_name)

# remove annotations
self._remove_annotations(url, self.admin)

# upload annotations
url = self._generate_url_upload_tasks_annotations(task_id, upload_format_name)
with open(file_zip_name, 'rb') as binary_file:
self._upload_file(url, binary_file, self.admin)

# equals annotations
data_from_task_after_upload = self._get_data_from_task(task_id, include_images)
compare_datasets(self, data_from_task_before_upload, data_from_task_after_upload)\

def test_api_v1_check_attribute_import_in_tracks(self):
test_name = self._testMethodName
dump_format_name = "CVAT for video 1.1"
upload_format_name = "CVAT 1.1"

for include_images in (False, True):
with self.subTest():
# create task with annotations
images = self._generate_task_images(13)
task = self._create_task(tasks["many jobs"], images)
self._create_annotations(task, f'{dump_format_name} attributes in tracks', "default")

task_id = task["id"]
data_from_task_before_upload = self._get_data_from_task(task_id, include_images)

# dump annotations
url = self._generate_url_dump_tasks_annotations(task_id)
Expand All @@ -257,9 +298,5 @@ def test_api_v1_check_widerface_with_all_attributes(self):
self._upload_file(url, binary_file, self.admin)

# equals annotations
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_images=include_images)
data_from_task_after_upload = Dataset.from_extractors(extractor)
data_from_task_after_upload = self._get_data_from_task(task_id, include_images)
compare_datasets(self, data_from_task_before_upload, data_from_task_after_upload)

0 comments on commit 4b82336

Please sign in to comment.