@@ -210,7 +210,6 @@ def update_with_detections(self, detections: Detections) -> Detections:
210
210
```python
211
211
import supervision as sv
212
212
from ultralytics import YOLO
213
- import numpy as np
214
213
215
214
model = YOLO(<MODEL_PATH>)
216
215
tracker = sv.ByteTrack()
@@ -261,6 +260,21 @@ def callback(frame: np.ndarray, index: int) -> np.ndarray:
261
260
262
261
return detections
263
262
263
+ def reset (self ):
264
+ """
265
+ Resets the internal state of the ByteTrack tracker.
266
+
267
+ This method clears the tracking data, including tracked, lost,
268
+ and removed tracks, as well as resetting the frame counter. It's
269
+ particularly useful when processing multiple videos sequentially,
270
+ ensuring the tracker starts with a clean state for each new video.
271
+ """
272
+ self .frame_id = 0
273
+ self .tracked_tracks : List [STrack ] = []
274
+ self .lost_tracks : List [STrack ] = []
275
+ self .removed_tracks : List [STrack ] = []
276
+ BaseTrack .reset_counter ()
277
+
264
278
def update_with_tensors (self , tensors : np .ndarray ) -> List [STrack ]:
265
279
"""
266
280
Updates the tracker with the provided tensors and returns the updated tracks.
@@ -306,6 +320,7 @@ def update_with_tensors(self, tensors: np.ndarray) -> List[STrack]:
306
320
""" Add newly detected tracklets to tracked_stracks"""
307
321
unconfirmed = []
308
322
tracked_stracks = [] # type: list[STrack]
323
+
309
324
for track in self .tracked_tracks :
310
325
if not track .is_activated :
311
326
unconfirmed .append (track )
0 commit comments