Reference for ultralytics/trackers/bot_sort.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/trackers/bot_sort.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.trackers.bot_sort.BOTrack
Bases: STrack
An extended version of the STrack class for YOLOv8, adding object tracking features.
Attributes:
Name | Type | Description |
---|---|---|
shared_kalman |
KalmanFilterXYWH
|
A shared Kalman filter for all instances of BOTrack. |
smooth_feat |
ndarray
|
Smoothed feature vector. |
curr_feat |
ndarray
|
Current feature vector. |
features |
deque
|
A deque to store feature vectors with a maximum length defined by |
alpha |
float
|
Smoothing factor for the exponential moving average of features. |
mean |
ndarray
|
The mean state of the Kalman filter. |
covariance |
ndarray
|
The covariance matrix of the Kalman filter. |
Methods:
Name | Description |
---|---|
update_features |
Update features vector and smooth it using exponential moving average. |
predict |
Predicts the mean and covariance using Kalman filter. |
re_activate |
Reactivates a track with updated features and optionally new ID. |
update |
Update the YOLOv8 instance with new track and frame ID. |
tlwh |
Property that gets the current position in tlwh format |
multi_predict |
Predicts the mean and covariance of multiple object tracks using shared Kalman filter. |
convert_coords |
Converts tlwh bounding box coordinates to xywh format. |
tlwh_to_xywh |
Convert bounding box to xywh format |
Usage
bo_track = BOTrack(tlwh, score, cls, feat) bo_track.predict() bo_track.update(new_track, frame_id)
Source code in ultralytics/trackers/bot_sort.py
tlwh
property
Get current position in bounding box format (top left x, top left y, width, height)
.
convert_coords
multi_predict
staticmethod
Predicts the mean and covariance of multiple object tracks using shared Kalman filter.
Source code in ultralytics/trackers/bot_sort.py
predict
Predicts the mean and covariance using Kalman filter.
Source code in ultralytics/trackers/bot_sort.py
re_activate
Reactivates a track with updated features and optionally assigns a new ID.
Source code in ultralytics/trackers/bot_sort.py
tlwh_to_xywh
staticmethod
Convert bounding box to format (center x, center y, width, height)
.
update
Update the YOLOv8 instance with new track and frame ID.
update_features
Update features vector and smooth it using exponential moving average.
Source code in ultralytics/trackers/bot_sort.py
ultralytics.trackers.bot_sort.BOTSORT
Bases: BYTETracker
An extended version of the BYTETracker class for YOLOv8, designed for object tracking with ReID and GMC algorithm.
Attributes:
Name | Type | Description |
---|---|---|
proximity_thresh |
float
|
Threshold for spatial proximity (IoU) between tracks and detections. |
appearance_thresh |
float
|
Threshold for appearance similarity (ReID embeddings) between tracks and detections. |
encoder |
object
|
Object to handle ReID embeddings, set to None if ReID is not enabled. |
gmc |
GMC
|
An instance of the GMC algorithm for data association. |
args |
object
|
Parsed command-line arguments containing tracking parameters. |
Methods:
Name | Description |
---|---|
get_kalmanfilter |
Returns an instance of KalmanFilterXYWH for object tracking. |
init_track |
Initialize track with detections, scores, and classes. |
get_dists |
Get distances between tracks and detections using IoU and (optionally) ReID. |
multi_predict |
Predict and track multiple objects with YOLOv8 model. |
Usage
bot_sort = BOTSORT(args, frame_rate) bot_sort.init_track(dets, scores, cls, img) bot_sort.multi_predict(tracks)
Note
The class is designed to work with the YOLOv8 object detection model and supports ReID only if enabled via args.
Source code in ultralytics/trackers/bot_sort.py
get_dists
Get distances between tracks and detections using IoU and (optionally) ReID embeddings.
Source code in ultralytics/trackers/bot_sort.py
get_kalmanfilter
init_track
Initialize track with detections, scores, and classes.