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 an issue with Imagenet dataset import #4861

Merged
merged 17 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -133,6 +133,7 @@ Skeleton (<https://github.com/cvat-ai/cvat/pull/1>), (<https://github.com/opencv
- Fix build dependencies for Siammask (<https://github.com/openvinotoolkit/cvat/pull/4486>)
- Bug: Exif orientation information handled incorrectly (<https://github.com/openvinotoolkit/cvat/pull/4529>)
- Fixed build of retinanet function image (<https://github.com/cvat-ai/cvat/pull/54>)
- Bug: Import dataset of Imagenet format fail (<https://github.com/opencv/cvat/issues/4850>)

## \[2.0.0] - 2022-03-04
### Added
Expand Down
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, '')
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
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 = min(dataset_files['media'], key=lambda x: len(Path(x).parts), default=None)
if shortes_path is not None:
dataset_files['data_root'] = str(Path(shortes_path).parent.absolute()) + osp.sep
if len(dataset_files['media']):
dataset_files['data_root'] = data_root
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved

project_annotation.add_task(task_fields, dataset_files, project_data)
17 changes: 17 additions & 0 deletions tests/python/rest_api/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@ def test_admin_can_get_project_backup_and_create_project_by_backup(self, admin_u
)
assert response.status == HTTPStatus.ACCEPTED

def test_can_import_export_dataset_with_imagenet_format(self):
# https://github.com/opencv/cvat/issues/4850
username = "admin1"
format_name = "ImageNet 1.0"
project_id = 4

response = self._test_export_project(username, project_id, format_name)

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

import_data = {
"dataset_file": tmp_file,
}

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

yasakova-anastasia marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.usefixtures("changedb")
class TestPatchProjectLabel:
Expand Down
38 changes: 36 additions & 2 deletions tests/python/shared/assets/annotations.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,24 @@
"z_order": 0
}
],
"tags": [],
"tags": [
{
"attributes": [],
"frame": 2,
"group": 0,
"id": 1,
"label_id": 17,
"source": "manual"
},
{
"attributes": [],
"frame": 3,
"group": 0,
"id": 2,
"label_id": 16,
"source": "manual"
}
],
"tracks": [],
"version": 0
},
Expand Down Expand Up @@ -1003,7 +1020,24 @@
"z_order": 0
}
],
"tags": [],
"tags": [
{
"attributes": [],
"frame": 2,
"group": 0,
"id": 1,
"label_id": 17,
"source": "manual"
},
{
"attributes": [],
"frame": 3,
"group": 0,
"id": 2,
"label_id": 16,
"source": "manual"
}
],
"tracks": [],
"version": 0
},
Expand Down
Binary file modified tests/python/shared/assets/cvat_db/cvat_data.tar.bz2
Binary file not shown.
55 changes: 51 additions & 4 deletions tests/python/shared/assets/cvat_db/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$260000$DevmxlmLwciP1P6sZs2Qag$U9DFtjTWx96Sk95qY6UXVcvpdQEP2LcoFBftk5D2RKY=",
"last_login": "2022-09-29T08:00:09.733Z",
"last_login": "2022-10-17T17:09:16.903Z",
"is_superuser": true,
"username": "admin1",
"first_name": "Admin",
Expand Down Expand Up @@ -487,6 +487,14 @@
"expire_date": "2022-03-02T06:24:53.914Z"
}
},
{
"model": "sessions.session",
"pk": "d3rhbsiax4etv2gtdkl6j883hvlz21rc",
"fields": {
"session_data": ".eJxVjMsOwiAQRf-FtSEMDAIu3fcbyPBQqgaS0q6M_y5NutDtOefeN_O0rcVvPS9-TuzCgJ1-WaD4zHUX6UH13nhsdV3mwPeEH7bzqaX8uh7t30GhXsYaQYNDpYMULqECS9IY0uIGxmYUQdoYMCpIeRgYiXVaDXoWgkImZJ8vqTk2zg:1okTc4:kq0YGX6_uyDwCa3VLl1bcp38oBfM6XfHIk0oE4XzpPw",
"expire_date": "2022-10-31T17:09:16.915Z"
}
},
{
"model": "sessions.session",
"pk": "dpaw6pntyqwr5l6qjv6zq3yoajp301be",
Expand Down Expand Up @@ -2242,7 +2250,7 @@
"assignee": null,
"bug_tracker": "",
"created_date": "2022-06-08T08:32:45.521Z",
"updated_date": "2022-09-28T12:26:54.279Z",
"updated_date": "2022-10-17T17:09:36.526Z",
"status": "annotation",
"organization": 2,
"source_storage": null,
Expand Down Expand Up @@ -2532,7 +2540,7 @@
"assignee": null,
"bug_tracker": "",
"created_date": "2022-06-08T08:33:06.505Z",
"updated_date": "2022-06-08T08:33:20.808Z",
"updated_date": "2022-10-17T17:09:36.570Z",
"overlap": 0,
"segment_size": 5,
"status": "annotation",
Expand Down Expand Up @@ -3574,7 +3582,7 @@
"fields": {
"segment": 17,
"assignee": null,
"updated_date": "2022-06-22T09:18:45.296Z",
"updated_date": "2022-10-17T17:09:36.571Z",
"status": "annotation",
"stage": "annotation",
"state": "in progress"
Expand Down Expand Up @@ -4726,6 +4734,45 @@
"job": 18
}
},
{
"model": "engine.jobcommit",
"pk": 73,
"fields": {
"scope": "create",
"owner": [
"admin1"
],
"timestamp": "2022-10-17T17:09:36.573Z",
"data": {
"stage": "annotation",
"state": "in progress",
"assignee": null
},
"job": 17
}
},
{
"model": "engine.labeledimage",
"pk": 1,
"fields": {
"job": 17,
"label": 17,
"frame": 2,
"group": 0,
"source": "manual"
}
},
{
"model": "engine.labeledimage",
"pk": 2,
"fields": {
"job": 17,
"label": 16,
"frame": 3,
"group": 0,
"source": "manual"
}
},
{
"model": "engine.labeledshape",
"pk": 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/python/shared/assets/jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
"status": "annotation",
"stop_frame": 4,
"task_id": 13,
"updated_date": "2022-06-22T09:18:45.296000Z",
"updated_date": "2022-10-17T17:09:36.571000Z",
"url": "http://localhost:8080/api/jobs/17"
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/shared/assets/projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
"tasks": [
13
],
"updated_date": "2022-09-28T12:26:54.279000Z",
"updated_date": "2022-10-17T17:09:36.526000Z",
"url": "http://localhost:8080/api/projects/4"
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/shared/assets/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
"status": "annotation",
"subset": "",
"target_storage": null,
"updated_date": "2022-06-08T08:33:20.808000Z",
"updated_date": "2022-10-17T17:09:36.570000Z",
"url": "http://localhost:8080/api/tasks/13"
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/shared/assets/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
"is_active": true,
"is_staff": true,
"is_superuser": true,
"last_login": "2022-09-29T08:00:09.733000Z",
"last_login": "2022-10-17T17:09:16.903140Z",
"last_name": "First",
"url": "http://localhost:8080/api/users/1",
"username": "admin1"
Expand Down