|
20 | 20 |
|
21 | 21 |
|
22 | 22 | class ByteTrackTracker(BaseTracker): |
23 | | - """Implements ByteTrack. |
24 | | -
|
25 | | - ByteTrack is a simple, effective, and generic multi-object tracking method |
26 | | - that improves upon tracking-by-detection by associating *every* detection box |
27 | | - instead of discarding low-score ones. This makes it more robust to occlusions. |
28 | | - It uses a two-stage association process and builds on established techniques |
29 | | - like the Kalman Filter for motion prediction and the Hungarian algorithm for |
30 | | - data association. |
| 23 | + """Track objects using ByteTrack algorithm with two-stage association. |
| 24 | + Associates both high and low confidence detections to reduce fragmentation |
| 25 | + and improve tracking through occlusions. |
31 | 26 |
|
32 | 27 | Args: |
33 | | - lost_track_buffer: Number of frames to buffer when a track is lost. |
34 | | - Increasing lost_track_buffer enhances occlusion handling, significantly |
35 | | - improving tracking through occlusions, but may increase the possibility |
36 | | - of ID switching for objects that disappear. |
37 | | - frame_rate: Frame rate of the video (frames per second). |
38 | | - Used to calculate the maximum time a track can be lost. |
39 | | - track_activation_threshold: Detection confidence threshold |
40 | | - for track activation. Only detections with confidence above this |
41 | | - threshold will create new tracks. Increasing this threshold may |
42 | | - reduce false positives but may miss real objects with low confidence. |
43 | | - minimum_consecutive_frames: Number of consecutive frames that an object |
44 | | - must be tracked before it is considered a 'valid'/'active/ track. Increasing |
45 | | - `minimum_consecutive_frames` prevents the creation of accidental tracks |
46 | | - from false detection or double detection, but risks missing shorter |
47 | | - tracks. Before the tracker is considered valid, it will be assigned |
48 | | - `-1` as its `tracker_id`. |
49 | | - minimum_iou_threshold: IoU threshold for associating detections to existing tracks. |
50 | | - Prevents the association of lower IoU than the threshold between boxes and tracks. |
51 | | - A higher value will only associate boxes that have more overlapping area. |
52 | | - high_conf_det_threshold: threshold for assigning detections to high probability class. |
53 | | - A higher value will classify only higher confidence/probability detections as 'high probability' |
54 | | - per the ByteTrack algorithm, which are used in the first similarity step of |
55 | | - the algorithm. |
56 | | - """ # noqa: E501 |
| 28 | + lost_track_buffer: `int` specifying number of frames to buffer when a |
| 29 | + track is lost. Increasing this value enhances occlusion handling but |
| 30 | + may increase ID switching for disappearing objects. |
| 31 | + frame_rate: `float` specifying video frame rate in frames per second. |
| 32 | + Used to scale the lost track buffer for consistent tracking across |
| 33 | + different frame rates. |
| 34 | + track_activation_threshold: `float` specifying minimum detection |
| 35 | + confidence to create new tracks. Higher values reduce false |
| 36 | + positives but may miss low-confidence objects. |
| 37 | + minimum_consecutive_frames: `int` specifying number of consecutive |
| 38 | + frames before a track is considered valid. Before reaching this |
| 39 | + threshold, tracks are assigned `tracker_id` of `-1`. |
| 40 | + minimum_iou_threshold: `float` specifying IoU threshold for associating |
| 41 | + detections to existing tracks. Higher values require more overlap. |
| 42 | + high_conf_det_threshold: `float` specifying threshold for separating |
| 43 | + high and low confidence detections in the two-stage association. |
| 44 | + """ |
57 | 45 |
|
58 | 46 | def __init__( |
59 | 47 | self, |
@@ -104,20 +92,19 @@ def update( |
104 | 92 | self, |
105 | 93 | detections: sv.Detections, |
106 | 94 | ) -> sv.Detections: |
107 | | - """Updates the tracker state with new detections. |
108 | | -
|
109 | | - Performs Kalman Filter prediction, associates detections with existing |
110 | | - tracks based on IoU, updates matched tracks, and initializes new |
111 | | - tracks for unmatched high-confidence detections. |
| 95 | + """Update tracker state with new detections and return tracked objects. |
| 96 | + Performs Kalman filter prediction, two-stage association (high then low |
| 97 | + confidence), and initializes new tracks for unmatched detections. |
112 | 98 |
|
113 | 99 | Args: |
114 | | - detections: The latest set of object detections from a frame. |
| 100 | + detections: `sv.Detections` containing bounding boxes with shape |
| 101 | + `(N, 4)` in `(x_min, y_min, x_max, y_max)` format and optional |
| 102 | + confidence scores. |
115 | 103 |
|
116 | 104 | Returns: |
117 | | - A copy of the input detections, augmented with assigned `tracker_id` for |
118 | | - each successfully tracked object. Detections not associated with a |
119 | | - track will not have a `tracker_id`. The order of the detections is not |
120 | | - guaranteed to be the same as the input detections. |
| 105 | + `sv.Detections` with `tracker_id` assigned for each detection. |
| 106 | + Unmatched detections have `tracker_id` of `-1`. Detection order |
| 107 | + may differ from input. |
121 | 108 | """ |
122 | 109 |
|
123 | 110 | if len(self.tracks) == 0 and len(detections) == 0: |
@@ -333,9 +320,8 @@ def _similarity_step( |
333 | 320 | return matched_indices, unmatched_tracks, unmatched_detections |
334 | 321 |
|
335 | 322 | def reset(self) -> None: |
336 | | - """Resets the tracker's internal state. |
337 | | -
|
338 | | - Clears all active tracks and resets the track ID counter. |
| 323 | + """Reset tracker state by clearing all tracks and resetting ID counter. |
| 324 | + Call this method when switching to a new video or scene. |
339 | 325 | """ |
340 | 326 | self.tracks = [] |
341 | 327 | ByteTrackKalmanBoxTracker.count_id = 0 |
0 commit comments