Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions supervision/tracker/byte_tracker/basetrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def next_id() -> int:
BaseTrack._count += 1
return BaseTrack._count

@staticmethod
def reset_counter():
BaseTrack._count = 0
BaseTrack.track_id = 0
BaseTrack.start_frame = 0
BaseTrack.frame_id = 0
BaseTrack.time_since_update = 0

def activate(self, *args):
raise NotImplementedError

Expand Down
17 changes: 16 additions & 1 deletion supervision/tracker/byte_tracker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def update_with_detections(self, detections: Detections) -> Detections:
```python
import supervision as sv
from ultralytics import YOLO
import numpy as np

model = YOLO(<MODEL_PATH>)
tracker = sv.ByteTrack()
Expand Down Expand Up @@ -261,6 +260,21 @@ def callback(frame: np.ndarray, index: int) -> np.ndarray:

return detections

def reset(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we document this method? For the method to be displayed in docs it needs to be public and have docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @SkalskiP Thank you for the suggestions. I have already implemented the changes. Please let me know if there is anything else that needs to be updated. 🥷 🚀

"""
Resets the internal state of the ByteTrack tracker.

This method clears the tracking data, including tracked, lost,
and removed tracks, as well as resetting the frame counter. It's
particularly useful when processing multiple videos sequentially,
ensuring the tracker starts with a clean state for each new video.
"""
self.frame_id = 0
self.tracked_tracks: List[STrack] = []
self.lost_tracks: List[STrack] = []
self.removed_tracks: List[STrack] = []
BaseTrack.reset_counter()

def update_with_tensors(self, tensors: np.ndarray) -> List[STrack]:
"""
Updates the tracker with the provided tensors and returns the updated tracks.
Expand Down Expand Up @@ -306,6 +320,7 @@ def update_with_tensors(self, tensors: np.ndarray) -> List[STrack]:
""" Add newly detected tracklets to tracked_stracks"""
unconfirmed = []
tracked_stracks = [] # type: list[STrack]

for track in self.tracked_tracks:
if not track.is_activated:
unconfirmed.append(track)
Expand Down