Skip to content

Commit

Permalink
Fix tracks splitting for tracks that have sub-tracks (#6968)
Browse files Browse the repository at this point in the history
When uploading annotations for the whole task that has few jobs our
server splits tracks. Each track we divide into a few tracks in that way
that each track corresponds to only one job and all shapes of the track
do not extend beyond the frame range corresponding to that job.

It mainly works, but we have a problem with skeleton tracks. Due to this
problem we if upload skeleton tracks for the whole task all our tracks
will be duplicated for each job but not split, it means that we will
have tracks that extend beyond the frame range of jobs and it leads to
bad side effects, in this case, our exported annotations from such task
could be incorrect or we won't be able to export annotations at all.

And the reason for this problem is this small bug, which this PR fixes.
Our code really slices sub-tracks for the skeleton track, but after this
slicing server doesn't save the result.
  • Loading branch information
Kirill Sizov authored Oct 11, 2023
1 parent cf4329a commit b450b44
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20231010_113810_sizow.k.d_fix_tracks_splitting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Splitting skeleton tracks on jobs
(<https://github.com/opencv/cvat/pull/6968>)
9 changes: 6 additions & 3 deletions cvat/apps/dataset_manager/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ def filter_track_shapes(shapes):
track = deepcopy(track_)
segment_shapes = filter_track_shapes(deepcopy(track['shapes']))

track["elements"] = [
cls._slice_track(element, start, stop, dimension)
for element in track.get('elements', [])
]

if len(segment_shapes) < len(track['shapes']):
for element in track.get('elements', []):
element = cls._slice_track(element, start, stop, dimension)
interpolated_shapes = TrackManager.get_interpolated_shapes(
track, start, stop, dimension)
scoped_shapes = filter_track_shapes(interpolated_shapes)
Expand Down Expand Up @@ -909,7 +912,7 @@ def propagate(shape, end_frame, *, included_frames=None):
break # The track finishes here

if prev_shape:
assert curr_frame > prev_shape["frame"] # Catch invalid tracks
assert curr_frame > prev_shape["frame"], f"{curr_frame} > {prev_shape['frame']}. Track id: {track['id']}" # Catch invalid tracks

# Propagate attributes
for attr in prev_shape["attributes"]:
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/dataset_manager/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _add_missing_shape(self, track, first_shape):
missing_shape = deepcopy(first_shape)
missing_shape["frame"] = track["frame"]
missing_shape["outside"] = True
missing_shape.pop("id")
missing_shape.pop("id", None)
track["shapes"].append(missing_shape)

def _correct_frame_of_tracked_shapes(self, track):
Expand Down
58 changes: 58 additions & 0 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from shared.utils.config import (
BASE_URL,
USER_PASS,
delete_method,
get_method,
make_api_client,
patch_method,
Expand Down Expand Up @@ -534,6 +535,63 @@ def test_remove_first_keyframe(self):
response = patch_method("admin1", endpoint, annotations, action="update")
assert response.status_code == HTTPStatus.OK

def test_can_split_skeleton_tracks_on_jobs(self, jobs):
# https://github.com/opencv/cvat/pull/6968
task_id = 21

task_jobs = [job for job in jobs if job["task_id"] == task_id]

frame_ranges = {}
for job in task_jobs:
frame_ranges[job["id"]] = set(range(job["start_frame"], job["stop_frame"] + 1))

# skeleton track that covers few jobs
annotations = {
"tracks": [
{
"frame": 0,
"label_id": 58,
"shapes": [{"type": "skeleton", "frame": 0, "points": []}],
"elements": [
{
"label_id": 59,
"frame": 0,
"shapes": [
{"type": "points", "frame": 0, "points": [1.0, 2.0]},
{"type": "points", "frame": 2, "points": [1.0, 2.0]},
{"type": "points", "frame": 7, "points": [1.0, 2.0]},
],
},
],
}
]
}

# clear task annotations
response = delete_method("admin1", f"tasks/{task_id}/annotations")
assert response.status_code == 204, f"Cannot delete task's annotations: {response.content}"

# create skeleton track that covers few jobs
response = patch_method(
"admin1", f"tasks/{task_id}/annotations", annotations, action="create"
)
assert response.status_code == 200, f"Cannot update task's annotations: {response.content}"

# check that server splitted skeleton track's elements on jobs correctly
for job_id, job_frame_range in frame_ranges.items():
response = get_method("admin1", f"jobs/{job_id}/annotations")
assert response.status_code == 200, f"Cannot get job's annotations: {response.content}"

job_annotations = response.json()
assert len(job_annotations["tracks"]) == 1, "Expected to see only one track"

track = job_annotations["tracks"][0]
assert track.get("elements", []), "Expected to see track with elements"

for element in track["elements"]:
element_frames = set(shape["frame"] for shape in element["shapes"])
assert element_frames <= job_frame_range, "Track shapes get out of job frame range"


@pytest.mark.usefixtures("restore_db_per_class")
class TestGetTaskDataset:
Expand Down

0 comments on commit b450b44

Please sign in to comment.