Skip to content

Commit

Permalink
removing deleted_frames argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Eldies committed Dec 18, 2024
1 parent 4535f5d commit eb3ce13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
35 changes: 12 additions & 23 deletions cvat/apps/dataset_manager/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import math
from collections.abc import Container, Sequence
from typing import Collection, Optional
from typing import Optional
import numpy as np
from itertools import chain
from scipy.optimize import linear_sum_assignment
Expand Down Expand Up @@ -199,27 +199,22 @@ def clear_frames(self, frames: Container[int]):
# Tracks are not expected in the cases this function is supposed to be used
raise AssertionError("Partial annotation cleanup is not supported for tracks")

def to_shapes(
self,
def to_shapes(self,
end_frame: int,
*,
included_frames: Optional[Sequence[int]] = None,
include_outside: bool = False,
use_server_track_ids: bool = False,
deleted_frames: Optional[Collection[int]] = None,
use_server_track_ids: bool = False
) -> list:
shapes = self.data.shapes
tracks = TrackManager(self.data.tracks, dimension=self.dimension)

if included_frames is not None:
shapes = [s for s in shapes if s["frame"] in included_frames]

return shapes + tracks.to_shapes(
end_frame,
included_frames=included_frames,
include_outside=include_outside,
use_server_track_ids=use_server_track_ids,
deleted_frames=deleted_frames,
return shapes + tracks.to_shapes(end_frame,
included_frames=included_frames, include_outside=include_outside,
use_server_track_ids=use_server_track_ids
)

def to_tracks(self):
Expand Down Expand Up @@ -467,19 +462,15 @@ def _modify_unmatched_object(self, obj, end_frame):


class TrackManager(ObjectManager):
def to_shapes(
self,
end_frame: int,
*,
def to_shapes(self, end_frame: int, *,
included_frames: Optional[Sequence[int]] = None,
include_outside: bool = False,
use_server_track_ids: bool = False,
deleted_frames: Optional[Collection[int]] = None,
use_server_track_ids: bool = False
) -> list:
shapes = []
for idx, track in enumerate(self.objects):
if deleted_frames is not None:
track = dict(track, shapes=list(filter(lambda sh: sh['frame'] not in deleted_frames, track['shapes'])))
if included_frames is not None:
track = dict(track, shapes=list(filter(lambda sh: sh['frame'] in included_frames, track['shapes'])))
track_id = track["id"] if use_server_track_ids else idx
track_shapes = {}

Expand Down Expand Up @@ -509,12 +500,10 @@ def to_shapes(
element_included_frames = set(track_shapes.keys())
if included_frames is not None:
element_included_frames = element_included_frames.intersection(included_frames)
element_shapes = track_elements.to_shapes(
end_frame,
element_shapes = track_elements.to_shapes(end_frame,
included_frames=element_included_frames,
include_outside=True, # elements are controlled by the parent shape
use_server_track_ids=use_server_track_ids,
deleted_frames=deleted_frames,
use_server_track_ids=use_server_track_ids
)

for shape in element_shapes:
Expand Down
10 changes: 4 additions & 6 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def rel_frame_id(self, absolute_id):
return d

def _init_frame_info(self):
self._deleted_frames = { k for k in self._db_data.deleted_frames }
self._deleted_frames = { k: True for k in self._db_data.deleted_frames }

self._excluded_frames = set()

Expand Down Expand Up @@ -499,8 +499,7 @@ def get_frame(idx):
# Skip outside, deleted and excluded frames
included_frames=included_frames,
include_outside=False,
use_server_track_ids=self._use_server_track_ids,
deleted_frames=self.deleted_frames,
use_server_track_ids=self._use_server_track_ids
),
key=lambda shape: shape.get("z_order", 0)
):
Expand Down Expand Up @@ -696,7 +695,7 @@ def frame_info(self):
return self._frame_info

@property
def deleted_frames(self) -> set[int]:
def deleted_frames(self):
return self._deleted_frames

@property
Expand Down Expand Up @@ -1299,8 +1298,7 @@ def get_frame(task_id: int, idx: int) -> ProjectData.Frame:
task.data.size,
included_frames=task_included_frames,
include_outside=False,
use_server_track_ids=self._use_server_track_ids,
deleted_frames=task_data.deleted_frames,
use_server_track_ids=self._use_server_track_ids
),
key=lambda shape: shape.get("z_order", 0)
):
Expand Down

0 comments on commit eb3ce13

Please sign in to comment.