Skip to content
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

Fix dataset import for Datumaro format #4544

Merged
merged 22 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Resolve conflicts
  • Loading branch information
yasakova-anastasia committed Oct 19, 2022
commit 07b49722b1eff54f620f7e0f0dbd0bfbdee06bff
10 changes: 7 additions & 3 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,17 +1885,21 @@ def load_dataset_data(project_annotation, dataset: dm.Dataset, project_data):
'data_root': dataset.data_path + osp.sep,
}

data_root = None
for dataset_item in subset_dataset:
if dataset_item.image and dataset_item.image.has_data:
dataset_files['media'].append(dataset_item.image.path)
if data_root is None:
data_root = osp.splitext(dataset_item.image.path)[0].replace(dataset_item.id, '')
elif dataset_item.point_cloud:
dataset_files['media'].append(dataset_item.point_cloud)
if data_root is None:
data_root = osp.splitext(dataset_item.point_cloud)[0].replace(dataset_item.id, '')
if isinstance(dataset_item.related_images, list):
dataset_files['media'] += \
list(map(lambda ri: ri.path, dataset_item.related_images))

shortes_path = osp.commonpath(dataset_files['media'])
if shortes_path:
dataset_files['data_root'] = osp.abspath(shortes_path) + osp.sep
if len(dataset_files['media']):
dataset_files['data_root'] = data_root

project_annotation.add_task(task_fields, dataset_files, project_data)
2 changes: 1 addition & 1 deletion cvat/apps/dataset_manager/formats/vggface2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _import(src_file, instance_data, load_data_callback=None):

dataset = Dataset.import_from(tmp_dir, 'vgg_face2', env=dm_env)
if isinstance(instance_data, TaskData):
dataset.transform('rename', r"|([^/]+/)?(.+)|\2|")
dataset.transform('rename', regex=r"|([^/]+/)?(.+)|\2|")
if load_data_callback is not None:
load_data_callback(dataset, instance_data)
import_dm_annotations(dataset, instance_data)
70 changes: 69 additions & 1 deletion tests/python/rest_api/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,73 @@ def test_can_import_dataset_in_org(self, admin_user):

self._test_import_project(admin_user, project_id, "CVAT 1.1", import_data)

def test_can_export_and_import_dataset_with_skeletons_coco_keypoints(self, admin_user):
project_id = 5

response = self._test_export_project(admin_user, project_id, "COCO Keypoints 1.0")

tmp_file = io.BytesIO(response.data)
tmp_file.name = "dataset.zip"
import_data = {
"dataset_file": tmp_file,
}

self._test_import_project(admin_user, project_id, "COCO Keypoints 1.0", import_data)

def test_can_export_and_import_dataset_with_skeletons_cvat_for_images(self, admin_user):
project_id = 5

response = self._test_export_project(admin_user, project_id, "CVAT for images 1.1")

tmp_file = io.BytesIO(response.data)
tmp_file.name = "dataset.zip"
import_data = {
"dataset_file": tmp_file,
}

self._test_import_project(admin_user, project_id, "CVAT 1.1", import_data)

def test_can_export_and_import_dataset_with_skeletons_cvat_for_video(self, admin_user):
project_id = 5

response = self._test_export_project(admin_user, project_id, "CVAT for video 1.1")

tmp_file = io.BytesIO(response.data)
tmp_file.name = "dataset.zip"
import_data = {
"dataset_file": tmp_file,
}

self._test_import_project(admin_user, project_id, "CVAT 1.1", import_data)

def _test_can_get_project_backup(self, username, pid, **kwargs):
for _ in range(30):
response = get_method(username, f"projects/{pid}/backup", **kwargs)
response.raise_for_status()
if response.status_code == HTTPStatus.CREATED:
break
sleep(1)
response = get_method(username, f"projects/{pid}/backup", action="download", **kwargs)
assert response.status_code == HTTPStatus.OK
return response

def test_admin_can_get_project_backup_and_create_project_by_backup(self, admin_user):
project_id = 5
response = self._test_can_get_project_backup(admin_user, project_id)

tmp_file = io.BytesIO(response.content)
tmp_file.name = "dataset.zip"

import_data = {
"project_file": tmp_file,
}

with make_api_client(admin_user) as api_client:
(_, response) = api_client.projects_api.create_backup(
backup_write_request=deepcopy(import_data), _content_type="multipart/form-data"
)
assert response.status == HTTPStatus.ACCEPTED

def test_can_import_export_dataset_with_datumaro_format(self):
# https://github.com/opencv/cvat/issues/4410
username = 'admin1'
Expand All @@ -408,7 +475,8 @@ def test_can_import_export_dataset_with_datumaro_format(self):

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

zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.usefixtures('changedb')

@pytest.mark.usefixtures("restore_db_per_function")
class TestPatchProjectLabel:
def test_admin_can_delete_label(self, projects):
project = deepcopy(list(projects)[1])
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.