-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c39e38f
fixed uploading annotation for overlapped segments
d4820d4
fixed dump of tracks for multisegment task
d9d0699
Update CHANGELOG.md
azhavoro 4f4f3ca
Merge branch 'develop' into az/fix_uploading_annotation
azhavoro 705bd7d
fixed comments
3eec428
Merge branch 'develop' into az/fix_uploading_annotation
azhavoro bd228e1
fixed comments
976a820
Update cvat/apps/engine/data_manager.py
azhavoro bf1e0a3
drop start shapes with outside==True for splitted track
f4ed055
code cleanup
bae93c0
fixed typo
ae65237
fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,13 +77,73 @@ def serialize(self): | |
if serializer.is_valid(raise_exception=True): | ||
return serializer.data | ||
|
||
@staticmethod | ||
def _is_shape_inside(shape, start, stop): | ||
return start <= int(shape['frame']) <= stop | ||
|
||
@staticmethod | ||
def _is_track_inside(track, start, stop): | ||
# a <= b | ||
def has_overlap(a, b): | ||
return 0 <= min(b, stop) - max(a, start) | ||
|
||
prev_shape = None | ||
for shape in track['shapes']: | ||
if prev_shape and not prev_shape['outside'] and \ | ||
has_overlap(prev_shape['frame'], shape['frame']): | ||
return True | ||
prev_shape = shape | ||
|
||
if not prev_shape['outside'] and prev_shape['frame'] <= stop: | ||
return True | ||
|
||
return False | ||
|
||
@staticmethod | ||
def _slice_track(track_, start, stop): | ||
def filter_track_shapes(shapes): | ||
shapes = [s for s in shapes if AnnotationIR._is_shape_inside(s, start, stop)] | ||
drop_count = 0 | ||
for s in shapes: | ||
if s['outside']: | ||
drop_count += 1 | ||
else: | ||
break | ||
# Need to leave the last shape if all shapes are outside | ||
if drop_count == len(shapes): | ||
drop_count -= 1 | ||
|
||
return shapes[drop_count:] | ||
|
||
track = copy.deepcopy(track_) | ||
segment_shapes = filter_track_shapes(track['shapes']) | ||
|
||
if len(segment_shapes) < len(track['shapes']): | ||
interpolated_shapes = TrackManager.get_interpolated_shapes(track, start, stop) | ||
scoped_shapes = filter_track_shapes(interpolated_shapes) | ||
|
||
if scoped_shapes: | ||
if not scoped_shapes[0]['keyframe']: | ||
segment_shapes.insert(0, scoped_shapes[0]) | ||
if not scoped_shapes[-1]['keyframe']: | ||
segment_shapes.append(scoped_shapes[-1]) | ||
|
||
# Should delete 'interpolation_shapes' and 'keyframe' keys because | ||
# Track and TrackedShape models don't expect these fields | ||
del track['interpolated_shapes'] | ||
for shape in segment_shapes: | ||
del shape['keyframe'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should we delete the property for all segment_shapes? Could you please add a comment? |
||
|
||
track['shapes'] = segment_shapes | ||
track['frame'] = track['shapes'][0]['frame'] | ||
return track | ||
|
||
#makes a data copy from specified frame interval | ||
def slice(self, start, stop): | ||
is_frame_inside = lambda x: (start <= int(x['frame']) <= 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.tags = [copy.deepcopy(t) for t in self.tags if self._is_shape_inside(t, start, stop)] | ||
splitted_data.shapes = [copy.deepcopy(s) for s in self.shapes if self._is_shape_inside(s, start, stop)] | ||
splitted_data.tracks = [self._slice_track(t, start, stop) for t in self.tracks if self._is_track_inside(t, start, stop)] | ||
|
||
return splitted_data | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tricky case here. Should we return True here for shapes with outside == True?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added filter to remove starting shapes with outside==True after processing