1from abc
import abstractmethod
9 momentums (dict[str:float], optional): Momentums to update the buffers.
10 The `str` indicates the name of the buffer while the `float`
11 indicates the momentum. Default to None.
12 num_frames_retain (int, optional). If a track is disappeared more than
13 `num_frames_retain` frames, it will be deleted in the memo.
14 init_cfg (dict or list[dict], optional): Initialization config dict.
18 def __init__(self, momentums=None, num_frames_retain=30):
20 if momentums
is not None:
21 assert isinstance(momentums, dict),
'momentums must be a dict'
29 """Reset the buffer of the tracker."""
35 """Whether the buffer is empty or not."""
36 return False if self.
tracks else True
40 """All ids in the tracker."""
41 return list(self.
tracks.keys())
45 """bool: whether the framework has a reid model"""
46 return hasattr(self,
'reid')
and self.reid
is not None
49 """Update the tracker.
52 kwargs (dict[str: Tensor | int]): The `str` indicates the
53 name of the input variable. `ids` and `frame_ids` are
54 obligatory in the keys.
57 memo_items = [k
for k, v
in kwargs.items()
if v
is not None]
58 rm_items = [k
for k
in kwargs.keys()
if k
not in memo_items]
61 if not hasattr(self,
'memo_items'):
66 assert 'ids' in memo_items
67 num_objs = len(kwargs[
'ids'])
68 id_indice = memo_items.index(
'ids')
69 assert 'frame_ids' in memo_items
70 frame_id = int(kwargs[
'frame_ids'])
71 if isinstance(kwargs[
'frame_ids'], int):
72 kwargs[
'frame_ids'] = torch.tensor([kwargs[
'frame_ids']] * num_objs)
74 for k, v
in kwargs.items():
75 if len(v) != num_objs:
78 for obj
in zip(*kwargs.values()):
79 id = int(obj[id_indice])
88 """Pop out invalid tracks."""
90 for k, v
in self.
tracks.items():
93 for invalid_id
in invalid_ids:
94 self.
tracks.pop(invalid_id)
102 self.
tracks[id][k] = (1 - m) * self.
tracks[id][k] + m * v
104 self.
tracks[id][k].append(v)
107 """Initialize a track."""
118 """Tracking forward function."""
update_track(self, id, obj)
track(self, *args, **kwargs)
__init__(self, momentums=None, num_frames_retain=30)
pop_invalid_tracks(self, frame_id)
init_track(self, id, obj)