Skip to content

Fix missing source tag in project annotations #5408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ non-ascii paths while adding files from "Connected file share" (issue #4428)
- Fixed FBRS serverless function runtime error on images with alpha channel (<https://github.com/opencv/cvat/pull/5384>)
- Attaching manifest with custom name (<https://github.com/opencv/cvat/pull/5377>)
- Uploading non-zip annotaion files (<https://github.com/opencv/cvat/pull/5386>)
- Missing source tag in project annotations (<https://github.com/opencv/cvat/pull/5408>)

### Security
- TDB
Expand Down
8 changes: 3 additions & 5 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ def meta_for_task(db_task, host, label_mapping=None):
("height", str(db_task.data.video.height))
])

# Add source to dumped file
meta["source"] = str(osp.basename(db_task.data.video.path))

return meta

def _init_meta(self):
Expand All @@ -731,11 +734,6 @@ def _init_meta(self):
("dumped", str(timezone.localtime(timezone.now())))
])

if hasattr(self._db_task.data, "video"):
# Add source to dumped file
self._meta["source"] = str(
osp.basename(self._db_task.data.video.path))

def __len__(self):
return self._db_data.size

Expand Down
69 changes: 69 additions & 0 deletions tests/python/rest_api/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# SPDX-License-Identifier: MIT

import io
import xml.etree.ElementTree as ET
import zipfile
from copy import deepcopy
from http import HTTPStatus
from io import BytesIO
from itertools import groupby, product
from time import sleep

Expand Down Expand Up @@ -351,6 +354,22 @@ def test_if_org_role_can_create_project(self, find_users, role):
self._test_create_project_201(user["username"], spec, org_id=user["org"])


def _check_cvat_for_video_project_annotations_meta(content, values_to_be_checked):
document = ET.fromstring(content)
instance = list(document.find("meta"))[0]
assert instance.tag == "project"
assert instance.find("id").text == values_to_be_checked["pid"]
assert len(list(document.iter("task"))) == len(values_to_be_checked["tasks"])
tasks = document.iter("task")
for task_checking in values_to_be_checked["tasks"]:
task_meta = next(tasks)
assert task_meta.find("id").text == str(task_checking["id"])
assert task_meta.find("name").text == task_checking["name"]
assert task_meta.find("size").text == str(task_checking["size"])
assert task_meta.find("mode").text == task_checking["mode"]
assert task_meta.find("source").text


@pytest.mark.usefixtures("restore_db_per_function")
class TestImportExportDatasetProject:
def _test_export_project(self, username, pid, format_name):
Expand All @@ -359,6 +378,12 @@ def _test_export_project(self, username, pid, format_name):
api_client.projects_api.retrieve_dataset_endpoint, id=pid, format=format_name
)

def _export_annotations(self, username, pid, format_name):
with make_api_client(username) as api_client:
return export_dataset(
api_client.projects_api.retrieve_annotations_endpoint, id=pid, format=format_name
)

def _test_import_project(self, username, project_id, format_name, data):
with make_api_client(username) as api_client:
(_, response) = api_client.projects_api.create_dataset(
Expand Down Expand Up @@ -477,6 +502,50 @@ def test_can_import_export_dataset_with_some_format(self, format_name):

self._test_import_project(username, project_id, format_name, import_data)

@pytest.mark.parametrize("username, pid", [("admin1", 8)])
@pytest.mark.parametrize(
"anno_format, anno_file_name, check_func",
[
(
"CVAT for video 1.1",
"annotations.xml",
_check_cvat_for_video_project_annotations_meta,
),
],
)
def test_exported_project_dataset_structure(
self,
username,
pid,
anno_format,
anno_file_name,
check_func,
tasks,
projects,
annotations,
):
project = projects[pid]

values_to_be_checked = {
"pid": str(pid),
"name": project["name"],
"tasks": [
{
"id": tid,
"name": (task := tasks[tid])["name"],
"size": str(task["size"]),
"mode": task["mode"],
}
for tid in project["tasks"]
],
}

response = self._export_annotations(username, pid, anno_format)
assert response.data
with zipfile.ZipFile(BytesIO(response.data)) as zip_file:
content = zip_file.read(anno_file_name)
check_func(content, values_to_be_checked)


@pytest.mark.usefixtures("restore_db_per_function")
class TestPatchProjectLabel:
Expand Down
94 changes: 94 additions & 0 deletions tests/python/shared/assets/annotations.json
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,53 @@
}
],
"version": 0
},
"19": {
"shapes": [
{
"attributes": [],
"elements": [],
"frame": 0,
"group": 0,
"id": 44,
"label_id": 29,
"occluded": false,
"outside": false,
"points": [
479.97322623828586,
408.0053547523421,
942.6238286479238,
513.3868808567604
],
"rotation": 0.0,
"source": "manual",
"type": "rectangle",
"z_order": 0
},
{
"attributes": [],
"elements": [],
"frame": 0,
"group": 0,
"id": 43,
"label_id": 30,
"occluded": false,
"outside": false,
"points": [
120.81927710843593,
213.52074966532928,
258.7576974564945,
643.614457831327
],
"rotation": 0.0,
"source": "manual",
"type": "rectangle",
"z_order": 0
}
],
"tags": [],
"tracks": [],
"version": 0
}
},
"task": {
Expand Down Expand Up @@ -1418,6 +1465,53 @@
}
],
"version": 0
},
"15": {
"shapes": [
{
"attributes": [],
"elements": [],
"frame": 0,
"group": 0,
"id": 44,
"label_id": 29,
"occluded": false,
"outside": false,
"points": [
479.97322623828586,
408.0053547523421,
942.6238286479238,
513.3868808567604
],
"rotation": 0.0,
"source": "manual",
"type": "rectangle",
"z_order": 0
},
{
"attributes": [],
"elements": [],
"frame": 0,
"group": 0,
"id": 43,
"label_id": 30,
"occluded": false,
"outside": false,
"points": [
120.81927710843593,
213.52074966532928,
258.7576974564945,
643.614457831327
],
"rotation": 0.0,
"source": "manual",
"type": "rectangle",
"z_order": 0
}
],
"tags": [],
"tracks": [],
"version": 0
}
}
}
Binary file modified tests/python/shared/assets/cvat_db/cvat_data.tar.bz2
Binary file not shown.
Loading