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 points missing when exporting tracked skeleton #5914

Merged
merged 26 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
93b3097
Fix export with skeletons
yasakova-anastasia Mar 23, 2023
f70b086
Remove deletion of skeleton points in shapes
yasakova-anastasia Mar 24, 2023
2d09cab
Resolve conflicts
yasakova-anastasia Mar 24, 2023
0d95eca
Fix export of a job from a task with multiple jobs
yasakova-anastasia Mar 24, 2023
35b72e6
Fix linters
yasakova-anastasia Mar 24, 2023
c694a94
Fix pylint
yasakova-anastasia Mar 24, 2023
53115cb
Small fix
yasakova-anastasia Mar 24, 2023
5b51b32
Fix endframe
yasakova-anastasia Mar 27, 2023
3085d21
Merge branch 'develop' into ay/fix-several-jobs-export
yasakova-anastasia Mar 27, 2023
f04f2c2
Merge branch 'develop' into ay/fix-several-jobs-export
yasakova-anastasia Mar 27, 2023
637fcbe
Update Chabgelog
yasakova-anastasia Mar 27, 2023
10df28d
Fixes
yasakova-anastasia Mar 27, 2023
5eb5fff
Merge branch 'develop' into ay/fix-export
yasakova-anastasia Mar 27, 2023
689f01d
Merge branch 'develop' into ay/fix-several-jobs-export
yasakova-anastasia Mar 27, 2023
4228741
Update tests
yasakova-anastasia Mar 27, 2023
288e8d0
Fixes
yasakova-anastasia Mar 27, 2023
b62c010
Remove useless change
yasakova-anastasia Mar 27, 2023
8c4bd3c
Merge remote-tracking branch 'remotes/origin/ay/fix-several-jobs-expo…
yasakova-anastasia Mar 28, 2023
bd2e686
Fix tests
yasakova-anastasia Mar 28, 2023
fcf4c19
Fix black
yasakova-anastasia Mar 28, 2023
348c253
Small fix
yasakova-anastasia Mar 28, 2023
9834a32
Resolve conflicts
yasakova-anastasia Mar 29, 2023
8101490
Update tests/python/rest_api/test_jobs.py
yasakova-anastasia Mar 29, 2023
f83d2f0
Update Changelog
yasakova-anastasia Mar 30, 2023
af2814e
Merge remote-tracking branch 'origin/ay/fix-export' into ay/fix-export
yasakova-anastasia Mar 30, 2023
1cea246
Apply comments
yasakova-anastasia Mar 30, 2023
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 @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Nuclio function invocations when deployed via the Helm chart
(<https://github.com/opencv/cvat/issues/5626>)
- Export of a job from a task with multiple jobs (<https://github.com/opencv/cvat/pull/5928>)
- Points missing when exporting tracked skeleton (<https://github.com/opencv/cvat/issues/5497>)
- Escaping in the `filter` parameter in generated URLs
(<https://github.com/opencv/cvat/issues/5566>)

Expand Down
26 changes: 15 additions & 11 deletions cvat/apps/dataset_manager/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _calc_polygons_similarity(p0, p1):
else:
return 0 # if there's invalid polygon, assume similarity is 0

has_same_type = obj0["type"] == obj1["type"]
has_same_type = obj0["type"] == obj1["type"]
has_same_label = obj0.get("label_id") == obj1.get("label_id")
if has_same_type and has_same_label:
if obj0["type"] == ShapeType.RECTANGLE:
Expand Down Expand Up @@ -366,7 +366,7 @@ def _calc_polygons_similarity(p0, p1):

p_top0 = geometry.box(*top_view_0)
p_top1 = geometry.box(*top_view_1)
top_similarity =_calc_polygons_similarity(p_top0, p_top1)
top_similarity = _calc_polygons_similarity(p_top0, p_top1)

side_view_0 = [
x_c0 - x_len0 / 2,
Expand All @@ -383,7 +383,7 @@ def _calc_polygons_similarity(p0, p1):
]
p_side0 = geometry.box(*side_view_0)
p_side1 = geometry.box(*side_view_1)
side_similarity =_calc_polygons_similarity(p_side0, p_side1)
side_similarity = _calc_polygons_similarity(p_side0, p_side1)

return top_similarity * side_similarity
elif obj0["type"] == ShapeType.POLYGON:
Expand Down Expand Up @@ -412,7 +412,13 @@ def to_shapes(self, end_frame, end_skeleton_frame=None):
shapes = []
for idx, track in enumerate(self.objects):
track_shapes = {}
for shape in TrackManager.get_interpolated_shapes(track, 0, end_frame, self._dimension):
for shape in TrackManager.get_interpolated_shapes(
track,
0,
end_frame,
self._dimension,
include_outside_frames=end_skeleton_frame is not None,
):
shape["label_id"] = track["label_id"]
shape["group"] = track["group"]
shape["track_id"] = idx
Expand All @@ -434,10 +440,6 @@ def to_shapes(self, end_frame, end_skeleton_frame=None):
for shape in element_shapes:
track_shapes[shape["frame"]]["elements"].append(shape)

for frame, shape in list(track_shapes.items()):
if all([el["outside"] for el in shape["elements"]]):
track_shapes.pop(frame)

shapes.extend(list(track_shapes.values()))
return shapes

Expand Down Expand Up @@ -502,7 +504,9 @@ def _modify_unmached_object(self, obj, end_frame):
self._modify_unmached_object(element, end_frame)

@staticmethod
def get_interpolated_shapes(track, start_frame, end_frame, dimension):
def get_interpolated_shapes(
track, start_frame, end_frame, dimension, *, include_outside_frames=False
):
def copy_shape(source, frame, points=None, rotation=None):
copied = deepcopy(source)
copied["keyframe"] = False
Expand Down Expand Up @@ -831,7 +835,7 @@ def interpolate(shape0, shape1):
for attr in prev_shape["attributes"]:
if attr["spec_id"] not in map(lambda el: el["spec_id"], shape["attributes"]):
shape["attributes"].append(deepcopy(attr))
if not prev_shape["outside"]:
if not prev_shape["outside"] or include_outside_frames:
shapes.extend(interpolate(prev_shape, shape))

shape["keyframe"] = True
Expand All @@ -850,7 +854,7 @@ def interpolate(shape0, shape1):
def _unite_objects(obj0, obj1):
track = obj0 if obj0["frame"] < obj1["frame"] else obj1
assert obj0["label_id"] == obj1["label_id"]
shapes = {shape["frame"]:shape for shape in obj0["shapes"]}
shapes = {shape["frame"]: shape for shape in obj0["shapes"]}
for shape in obj1["shapes"]:
frame = shape["frame"]
if frame in shapes:
Expand Down
10 changes: 8 additions & 2 deletions tests/python/rest_api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ def test_member_update_job_assignee(

def _check_coco_job_annotations(content, values_to_be_checked):
exported_annotations = json.loads(content)
assert values_to_be_checked["shapes_length"] == len(exported_annotations["annotations"])
if "shapes_length" in values_to_be_checked:
assert values_to_be_checked["shapes_length"] == len(exported_annotations["annotations"])
assert values_to_be_checked["job_size"] == len(exported_annotations["images"])
assert values_to_be_checked["task_size"] > len(exported_annotations["images"])

Expand All @@ -546,7 +547,7 @@ def _check_cvat_for_images_job_annotations(content, values_to_be_checked):
# check number of images, their sorting, number of annotations
images = document.findall("image")
assert len(images) == values_to_be_checked["job_size"]
if values_to_be_checked.get("shapes_length") is not None:
if "shapes_length" in values_to_be_checked:
assert len(list(document.iter("box"))) == values_to_be_checked["shapes_length"]
current_id = values_to_be_checked["start_frame"]
for image_elem in images:
Expand Down Expand Up @@ -664,6 +665,11 @@ def test_exported_job_dataset_structure(
[
("CVAT for images 1.1", "annotations.xml", _check_cvat_for_images_job_annotations),
("CVAT for video 1.1", "annotations.xml", _check_cvat_for_video_job_annotations),
(
"COCO Keypoints 1.0",
"annotations/person_keypoints_default.json",
_check_coco_job_annotations,
),
],
)
def test_export_job_among_several_jobs_in_task(
Expand Down
4 changes: 3 additions & 1 deletion tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ def test_can_export_task_dataset(self, admin_user, tasks_with_shapes):
assert response.data

@pytest.mark.parametrize("tid", [21])
@pytest.mark.parametrize("format_name", ["CVAT for images 1.1", "CVAT for video 1.1"])
@pytest.mark.parametrize(
"format_name", ["CVAT for images 1.1", "CVAT for video 1.1", "COCO Keypoints 1.0"]
)
def test_can_export_task_with_several_jobs(self, admin_user, tid, format_name):
response = self._test_export_task(admin_user, tid, format=format_name)
assert response.data
Expand Down