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

Allow to upload tracks from COCO formats #6969

Merged
merged 6 commits into from
Oct 12, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Uploading skeleton tracks in COCO Keypoints format
(<https://github.com/opencv/cvat/pull/6969>)
15 changes: 13 additions & 2 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,7 @@ def _convert_shape(self,
label=self.map_label(element.label, shape.label),
attributes=element_attr))

dm_attr["keyframe"] = any([element.attributes.get("keyframe") for element in elements])
anno = dm.Skeleton(elements, label=dm_label,
attributes=dm_attr, group=dm_group, z_order=shape.z_order)
else:
Expand Down Expand Up @@ -1899,6 +1900,15 @@ def import_dm_annotations(dm_dataset: dm.Dataset, instance_data: Union[ProjectDa
dm.AnnotationType.mask: ShapeType.MASK
}

track_formats = [
'cvat',
'datumaro',
'sly_pointcloud',
'coco',
'coco_instances',
'coco_person_keypoints'
]

label_cat = dm_dataset.categories()[dm.AnnotationType.label]

root_hint = find_dataset_root(dm_dataset, instance_data)
Expand Down Expand Up @@ -1983,7 +1993,7 @@ def reduce_fn(acc, v):
if ann.attributes.get('source', '').lower() in {'auto', 'semi-auto', 'manual', 'file'} else 'manual'

shape_type = shapes[ann.type]
if track_id is None or 'keyframe' not in ann.attributes or dm_dataset.format not in ['cvat', 'datumaro', 'sly_pointcloud']:
if track_id is None or 'keyframe' not in ann.attributes or dm_dataset.format not in track_formats:
elements = []
if ann.type == dm.AnnotationType.skeleton:
for element in ann.elements:
Expand Down Expand Up @@ -2050,7 +2060,7 @@ def reduce_fn(acc, v):

if ann.type == dm.AnnotationType.skeleton:
for element in ann.elements:
element_keyframe = dm.util.cast(element.attributes.get('keyframe', None), bool) is True
element_keyframe = dm.util.cast(element.attributes.get('keyframe', None), bool, True)
element_occluded = element.visibility[0] == dm.Points.Visibility.hidden
element_outside = element.visibility[0] == dm.Points.Visibility.absent
if not element_keyframe and not element_outside:
Expand All @@ -2069,6 +2079,7 @@ def reduce_fn(acc, v):
]
element_source = element.attributes.pop('source').lower() \
if element.attributes.get('source', '').lower() in {'auto', 'semi-auto', 'manual', 'file'} else 'manual'

tracks[track_id]['elements'][element.label].shapes.append(instance_data.TrackedShape(
type=shapes[element.type],
frame=frame_number,
Expand Down
40 changes: 40 additions & 0 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2526,3 +2526,43 @@ def test_import_annotations(self, task_kind, annotation_kind, expect_success):
task.import_annotations(self.format_name, dataset_file)

assert b"Could not match item id" in capture.value.body

def test_can_export_and_import_skeleton_tracks_in_coco_format(self):
task = self.client.tasks.retrieve(14)
dataset_file = self.tmp_dir / "some_file.zip"
format_name = "COCO Keypoints 1.0"

original_annotations = task.get_annotations()

task.export_dataset(format_name, dataset_file, include_images=False)
task.remove_annotations()
task.import_annotations(format_name, dataset_file)

imported_annotations = task.get_annotations()

# Number of shapes and tracks hasn't changed
assert len(original_annotations.shapes) == len(imported_annotations.shapes)
assert len(original_annotations.tracks) == len(imported_annotations.tracks)

# Frames of shapes, tracks and track elements hasn't changed
assert set([s.frame for s in original_annotations.shapes]) == set(
[s.frame for s in imported_annotations.shapes]
)
assert set([t.frame for t in original_annotations.tracks]) == set(
[t.frame for t in imported_annotations.tracks]
)
assert set(
[
tes.frame
for t in original_annotations.tracks
for te in t.elements
for tes in te.shapes
]
) == set(
[
tes.frame
for t in imported_annotations.tracks
for te in t.elements
for tes in te.shapes
]
)