Skip to content

Commit 285af58

Browse files
authored
chore: Redundant types from docstrings (#206)
* drop redundant types * update docstrings
1 parent 456a44b commit 285af58

File tree

5 files changed

+98
-119
lines changed

5 files changed

+98
-119
lines changed

trackers/core/bytetrack/kalman_box_tracker.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ class ByteTrackKalmanBoxTracker:
1414
its position.
1515
1616
Attributes:
17-
tracker_id (int): Unique identifier for the tracker.
18-
number_of_successful_updates (int): Number of times the object has been
17+
tracker_id: Unique identifier for the tracker.
18+
number_of_successful_updates: Number of times the object has been
1919
updated successfully.
20-
time_since_update (int): Number of frames since the last update.
21-
state (np.ndarray): State vector of the bounding box.
22-
F (np.ndarray): State transition matrix.
23-
H (np.ndarray): Measurement matrix.
24-
Q (np.ndarray): Process noise covariance matrix.
25-
R (np.ndarray): Measurement noise covariance matrix.
26-
P (np.ndarray): Error covariance matrix.
27-
count_id (int): Class variable to assign unique IDs to each tracker.
20+
time_since_update: Number of frames since the last update.
21+
state: State vector of the bounding box.
22+
F: State transition matrix.
23+
H: Measurement matrix.
24+
Q: Process noise covariance matrix.
25+
R: Measurement noise covariance matrix.
26+
P: Error covariance matrix.
27+
count_id: Class variable to assign unique IDs to each tracker.
2828
2929
Args:
30-
bbox (np.ndarray): Initial bounding box in the form [x1, y1, x2, y2].
30+
bbox: Initial bounding box in the form [x1, y1, x2, y2].
3131
"""
3232

3333
count_id = 0
@@ -38,7 +38,7 @@ def get_next_tracker_id(cls) -> int:
3838
Class method that returns the next available tracker ID.
3939
4040
Returns:
41-
int: The next available tracker ID.
41+
The next available tracker ID.
4242
"""
4343
next_id = cls.count_id
4444
cls.count_id += 1
@@ -109,7 +109,7 @@ def update(self, bbox: np.ndarray) -> None:
109109
Updates the state with a new detected bounding box.
110110
111111
Args:
112-
bbox (np.ndarray): Detected bounding box in the form [x1, y1, x2, y2].
112+
bbox: Detected bounding box in the form [x1, y1, x2, y2].
113113
"""
114114
self.time_since_update = 0
115115
self.number_of_successful_updates += 1
@@ -134,7 +134,7 @@ def get_state_bbox(self) -> np.ndarray:
134134
Returns the current bounding box estimate from the state vector.
135135
136136
Returns:
137-
np.ndarray: The bounding box [x1, y1, x2, y2].
137+
The bounding box [x1, y1, x2, y2].
138138
"""
139139
return np.array(
140140
[

trackers/core/bytetrack/tracker.py

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,28 @@
2020

2121

2222
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.
3126
3227
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+
"""
5745

5846
def __init__(
5947
self,
@@ -104,20 +92,19 @@ def update(
10492
self,
10593
detections: sv.Detections,
10694
) -> 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.
11298
11399
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.
115103
116104
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.
121108
"""
122109

123110
if len(self.tracks) == 0 and len(detections) == 0:
@@ -333,9 +320,8 @@ def _similarity_step(
333320
return matched_indices, unmatched_tracks, unmatched_detections
334321

335322
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.
339325
"""
340326
self.tracks = []
341327
ByteTrackKalmanBoxTracker.count_id = 0

trackers/core/sort/kalman_box_tracker.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ class SORTKalmanBoxTracker:
1515
its position.
1616
1717
Attributes:
18-
tracker_id (int): Unique identifier for the tracker.
19-
number_of_successful_updates (int): Number of times the object has been
18+
tracker_id: Unique identifier for the tracker.
19+
number_of_successful_updates: Number of times the object has been
2020
updated successfully.
21-
time_since_update (int): Number of frames since the last update.
22-
state (np.ndarray): State vector of the bounding box.
23-
F (np.ndarray): State transition matrix.
24-
H (np.ndarray): Measurement matrix.
25-
Q (np.ndarray): Process noise covariance matrix.
26-
R (np.ndarray): Measurement noise covariance matrix.
27-
P (np.ndarray): Error covariance matrix.
28-
count_id (int): Class variable to assign unique IDs to each tracker.
21+
time_since_update: Number of frames since the last update.
22+
state: State vector of the bounding box.
23+
F: State transition matrix.
24+
H: Measurement matrix.
25+
Q: Process noise covariance matrix.
26+
R: Measurement noise covariance matrix.
27+
P: Error covariance matrix.
28+
count_id: Class variable to assign unique IDs to each tracker.
2929
3030
Args:
31-
bbox (np.ndarray): Initial bounding box in the form [x1, y1, x2, y2].
31+
bbox: Initial bounding box in the form [x1, y1, x2, y2].
3232
"""
3333

3434
count_id: int = 0
@@ -111,7 +111,7 @@ def update(self, bbox: NDArray[np.float64]) -> None:
111111
Updates the state with a new detected bounding box.
112112
113113
Args:
114-
bbox (np.ndarray): Detected bounding box in the form [x1, y1, x2, y2].
114+
bbox: Detected bounding box in the form [x1, y1, x2, y2].
115115
"""
116116
self.time_since_update = 0
117117
self.number_of_successful_updates += 1
@@ -140,6 +140,6 @@ def get_state_bbox(self) -> NDArray[np.float32]:
140140
Returns the current bounding box estimate from the state vector.
141141
142142
Returns:
143-
np.ndarray: The bounding box [x1, y1, x2, y2]
143+
The bounding box [x1, y1, x2, y2].
144144
"""
145145
return self.state[:4, 0].flatten().astype(np.float32)

trackers/core/sort/tracker.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,25 @@
1818

1919

2020
class SORTTracker(BaseTracker):
21-
"""Implements SORT (Simple Online and Realtime Tracking).
22-
23-
SORT is a pragmatic approach to multiple object tracking with a focus on
24-
simplicity and speed. It uses a Kalman filter for motion prediction and the
25-
Hungarian algorithm or simple IOU matching for data association.
21+
"""Track objects using SORT algorithm with Kalman filter and IoU matching.
22+
Provides simple and fast online tracking using only bounding box geometry
23+
without appearance features.
2624
2725
Args:
28-
lost_track_buffer: Number of frames to buffer when a track is lost.
29-
Increasing lost_track_buffer enhances occlusion handling, significantly
30-
improving tracking through occlusions, but may increase the possibility
31-
of ID switching for objects with similar appearance.
32-
frame_rate: Frame rate of the video (frames per second).
33-
Used to calculate the maximum time a track can be lost.
34-
track_activation_threshold: Detection confidence threshold
35-
for track activation. Only detections with confidence above this
36-
threshold will create new tracks. Increasing this threshold
37-
reduces false positives but may miss real objects with low confidence.
38-
minimum_consecutive_frames: Number of consecutive frames that an object
39-
must be tracked before it is considered a 'valid' track. Increasing
40-
`minimum_consecutive_frames` prevents the creation of accidental tracks
41-
from false detection or double detection, but risks missing shorter
42-
tracks. Before the tracker is considered valid, it will be assigned
43-
`-1` as its `tracker_id`.
44-
minimum_iou_threshold: IOU threshold for associating detections to
45-
existing tracks.
26+
lost_track_buffer: `int` specifying number of frames to buffer when a
27+
track is lost. Increasing this value enhances occlusion handling but
28+
may increase ID switching for similar objects.
29+
frame_rate: `float` specifying video frame rate in frames per second.
30+
Used to scale the lost track buffer for consistent tracking across
31+
different frame rates.
32+
track_activation_threshold: `float` specifying minimum detection
33+
confidence to create new tracks. Higher values reduce false
34+
positives but may miss low-confidence objects.
35+
minimum_consecutive_frames: `int` specifying number of consecutive
36+
frames before a track is considered valid. Before reaching this
37+
threshold, tracks are assigned `tracker_id` of `-1`.
38+
minimum_iou_threshold: `float` specifying IoU threshold for associating
39+
detections to existing tracks. Higher values require more overlap.
4640
"""
4741

4842
def __init__(
@@ -120,19 +114,18 @@ def _spawn_new_trackers(
120114
self.trackers.append(new_tracker)
121115

122116
def update(self, detections: sv.Detections) -> sv.Detections:
123-
"""Updates the tracker state with new detections.
124-
125-
Performs Kalman filter prediction, associates detections with existing
126-
trackers based on IOU, updates matched trackers, and initializes new
127-
trackers for unmatched high-confidence detections.
117+
"""Update tracker state with new detections and return tracked objects.
118+
Performs Kalman filter prediction, IoU-based association, and initializes
119+
new tracks for unmatched high-confidence detections.
128120
129121
Args:
130-
detections: The latest set of object detections from a frame.
122+
detections: `sv.Detections` containing bounding boxes with shape
123+
`(N, 4)` in `(x_min, y_min, x_max, y_max)` format and optional
124+
confidence scores.
131125
132126
Returns:
133-
A copy of the input detections, augmented with assigned `tracker_id` for
134-
each successfully tracked object. Detections not associated with a
135-
track will not have a `tracker_id`.
127+
`sv.Detections` with `tracker_id` assigned for each detection.
128+
Unmatched or immature tracks have `tracker_id` of `-1`.
136129
"""
137130

138131
if len(self.trackers) == 0 and len(detections) == 0:
@@ -180,9 +173,8 @@ def update(self, detections: sv.Detections) -> sv.Detections:
180173
return updated_detections
181174

182175
def reset(self) -> None:
183-
"""Resets the tracker's internal state.
184-
185-
Clears all active tracks and resets the track ID counter.
176+
"""Reset tracker state by clearing all tracks and resetting ID counter.
177+
Call this method when switching to a new video or scene.
186178
"""
187179
self.trackers = []
188180
SORTKalmanBoxTracker.count_id = 0

trackers/utils/sort_utils.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def get_alive_trackers(
2929
it was just updated).
3030
3131
Args:
32-
trackers (Sequence[KalmanBoxTrackerType]): List of KalmanBoxTracker objects.
33-
minimum_consecutive_frames (int): Number of consecutive frames that an object
32+
trackers: List of KalmanBoxTracker objects.
33+
minimum_consecutive_frames: Number of consecutive frames that an object
3434
must be tracked before it is considered a 'valid' track.
35-
maximum_frames_without_update (int): Maximum number of frames without update
35+
maximum_frames_without_update: Maximum number of frames without update
3636
before a track is considered dead.
3737
3838
Returns:
39-
List[KalmanBoxTrackerType]: List of alive trackers.
39+
List of alive trackers.
4040
"""
4141
alive_trackers = []
4242
for tracker in trackers:
@@ -56,11 +56,12 @@ def get_iou_matrix(
5656
Build IOU cost matrix between detections and predicted bounding boxes
5757
5858
Args:
59-
detection_boxes (np.ndarray): Detected bounding boxes in the
59+
trackers: List of KalmanBoxTracker objects.
60+
detection_boxes: Detected bounding boxes in the
6061
form [x1, y1, x2, y2].
6162
6263
Returns:
63-
np.ndarray: IOU cost matrix.
64+
IOU cost matrix.
6465
"""
6566
predicted_boxes = np.array([t.get_state_bbox() for t in trackers])
6667
if len(predicted_boxes) == 0 and len(trackers) > 0:
@@ -88,17 +89,17 @@ def update_detections_with_track_ids(
8889
it is assigned an ID to the detection that just updated it.
8990
9091
Args:
91-
trackers (Sequence[SORTKalmanBoxTracker]): List of SORTKalmanBoxTracker objects.
92-
detections (sv.Detections): The latest set of object detections.
93-
detection_boxes (np.ndarray): Detected bounding boxes in the
92+
trackers: List of SORTKalmanBoxTracker objects.
93+
detections: The latest set of object detections.
94+
detection_boxes: Detected bounding boxes in the
9495
form [x1, y1, x2, y2].
95-
minimum_iou_threshold (float): IOU threshold for associating detections to
96+
minimum_iou_threshold: IOU threshold for associating detections to
9697
existing tracks.
97-
minimum_consecutive_frames (int): Number of consecutive frames that an object
98+
minimum_consecutive_frames: Number of consecutive frames that an object
9899
must be tracked before it is considered a 'valid' track.
99100
100101
Returns:
101-
sv.Detections: A copy of the detections with `tracker_id` set
102+
A copy of the detections with `tracker_id` set
102103
for each detection that is tracked.
103104
"""
104105
# Re-run association in the same way (could also store direct mapping)

0 commit comments

Comments
 (0)