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

Fixed uploading track annotations for multi-segment tasks #1396

Merged
merged 12 commits into from
Apr 30, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- VOC format exports Upper case labels correctly in lower case (https://github.com/opencv/cvat/pull/1379)
- Fixed polygon exporting bug in COCO dataset (https://github.com/opencv/cvat/issues/1387)
- Task creation from remote files (https://github.com/opencv/cvat/pull/1392)
- Uploading Track annotations for multi-segment tasks (https://github.com/opencv/cvat/pull/1396)
azhavoro marked this conversation as resolved.
Show resolved Hide resolved

### Security
-
Expand Down
28 changes: 27 additions & 1 deletion cvat/apps/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,33 @@ def slice(self, start, stop):
splitted_data = AnnotationIR()
splitted_data.tags = copy.deepcopy(list(filter(is_frame_inside, self.tags)))
splitted_data.shapes = copy.deepcopy(list(filter(is_frame_inside, self.shapes)))
splitted_data.tracks = copy.deepcopy(list(filter(lambda y: len(list(filter(is_frame_inside, y['shapes']))), self.tracks)))
splitted_data.tracks = []

for track_ in self.tracks:
if not list(filter(is_frame_inside, track_['shapes'])):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't look how the function is used by for the slice function the condition looks wrong. Let's say we have a track with two shapes only. First shape is on 0 frame and second shape is on 100 frame (0 - start, and 100 - outside). Let's say the slice function is called with start=10 and stop=20. Looks like the track will be filtered out.

continue

track = copy.deepcopy(track_)
track['frame'] = max(start, track['frame'])

segment_shapes = [s for s in track['shapes'] if is_frame_inside(s)]

if len(segment_shapes) < len(track['shapes']):
azhavoro marked this conversation as resolved.
Show resolved Hide resolved
interpolated_shapes = TrackManager.get_interpolated_shapes(track, 0, stop)
azhavoro marked this conversation as resolved.
Show resolved Hide resolved
if track['shapes'][0]['frame'] < start and \
segment_shapes[0]['frame'] > start:
start_shape = next(s for s in interpolated_shapes if s['frame'] == start)
segment_shapes.insert(0, start_shape)
if track['shapes'][-1]['frame'] > stop and \
segment_shapes[-1]['frame'] < stop:
stop_shape = next(s for s in interpolated_shapes if s['frame'] == stop)
segment_shapes.append(stop_shape)
del track['interpolated_shapes']
for shape in segment_shapes:
del shape['keyframe']

track['shapes'] = segment_shapes
splitted_data.tracks.append(track)

return splitted_data

Expand Down
1 change: 0 additions & 1 deletion cvat/apps/engine/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from enum import Enum
from collections import OrderedDict
from django.utils import timezone
from PIL import Image

from django.conf import settings
from django.db import transaction
Expand Down
3 changes: 3 additions & 0 deletions cvat/apps/engine/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def merge(self, objects, start_frame, overlap):
if j != -1:
self._modify_unmached_object(old_objects[j],
start_frame + overlap)
# Need to reset cached interpolated shapes
# because shapes was changed
old_objects[j]['interpolated_shapes'] = []
azhavoro marked this conversation as resolved.
Show resolved Hide resolved
else:
# We don't have old objects on the frame. Let's add all new ones.
self.objects.extend(int_objects_by_frame[frame])
Expand Down