Reference for ultralytics/trackers/byte_tracker.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/trackers/byte_tracker.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.trackers.byte_tracker.STrack
Bases: BaseTrack
Single object tracking representation that uses Kalman filtering for state estimation.
This class is responsible for storing all the information regarding individual tracklets and performs state updates and predictions based on Kalman filter.
Attributes:
Name | Type | Description |
---|---|---|
shared_kalman |
KalmanFilterXYAH
|
Shared Kalman filter that is used across all STrack instances for prediction. |
_tlwh |
ndarray
|
Private attribute to store top-left corner coordinates and width and height of bounding box. |
kalman_filter |
KalmanFilterXYAH
|
Instance of Kalman filter used for this particular object track. |
mean |
ndarray
|
Mean state estimate vector. |
covariance |
ndarray
|
Covariance of state estimate. |
is_activated |
bool
|
Boolean flag indicating if the track has been activated. |
score |
float
|
Confidence score of the track. |
tracklet_len |
int
|
Length of the tracklet. |
cls |
any
|
Class label for the object. |
idx |
int
|
Index or identifier for the object. |
frame_id |
int
|
Current frame ID. |
start_frame |
int
|
Frame where the object was first detected. |
Methods:
Name | Description |
---|---|
predict |
Predict the next state of the object using Kalman filter. |
multi_predict |
Predict the next states for multiple tracks. |
multi_gmc |
Update multiple track states using a homography matrix. |
activate |
Activate a new tracklet. |
re_activate |
Reactivate a previously lost tracklet. |
update |
Update the state of a matched track. |
convert_coords |
Convert bounding box to x-y-aspect-height format. |
tlwh_to_xyah |
Convert tlwh bounding box to xyah format. |
Source code in ultralytics/trackers/byte_tracker.py
tlwh
property
Get current position in bounding box format (top left x, top left y, width, height).
xywha
property
Get current position in bounding box format (center x, center y, width, height, angle).
xyxy
property
Convert bounding box to format (min x, min y, max x, max y), i.e., (top left, bottom right).
__repr__
Return a string representation of the BYTETracker object with start and end frames and track ID.
activate
Start a new tracklet.
Source code in ultralytics/trackers/byte_tracker.py
convert_coords
Convert a bounding box's top-left-width-height format to its x-y-aspect-height equivalent.
multi_gmc
staticmethod
Update state tracks positions and covariances using a homography matrix.
Source code in ultralytics/trackers/byte_tracker.py
multi_predict
staticmethod
Perform multi-object predictive tracking using Kalman filter for given stracks.
Source code in ultralytics/trackers/byte_tracker.py
predict
Predicts mean and covariance using Kalman filter.
Source code in ultralytics/trackers/byte_tracker.py
re_activate
Reactivates a previously lost track with a new detection.
Source code in ultralytics/trackers/byte_tracker.py
tlwh_to_xyah
staticmethod
Convert bounding box to format (center x, center y, aspect ratio, height), where the aspect ratio is width / height.
Source code in ultralytics/trackers/byte_tracker.py
update
Update the state of a matched track.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_track |
STrack
|
The new track containing updated information. |
required |
frame_id |
int
|
The ID of the current frame. |
required |
Source code in ultralytics/trackers/byte_tracker.py
ultralytics.trackers.byte_tracker.BYTETracker
BYTETracker: A tracking algorithm built on top of YOLOv8 for object detection and tracking.
The class is responsible for initializing, updating, and managing the tracks for detected objects in a video sequence. It maintains the state of tracked, lost, and removed tracks over frames, utilizes Kalman filtering for predicting the new object locations, and performs data association.
Attributes:
Name | Type | Description |
---|---|---|
tracked_stracks |
list[STrack]
|
List of successfully activated tracks. |
lost_stracks |
list[STrack]
|
List of lost tracks. |
removed_stracks |
list[STrack]
|
List of removed tracks. |
frame_id |
int
|
The current frame ID. |
args |
namespace
|
Command-line arguments. |
max_time_lost |
int
|
The maximum frames for a track to be considered as 'lost'. |
kalman_filter |
object
|
Kalman Filter object. |
Methods:
Name | Description |
---|---|
update |
Updates object tracker with new detections. |
get_kalmanfilter |
Returns a Kalman filter object for tracking bounding boxes. |
init_track |
Initialize object tracking with detections. |
get_dists |
Calculates the distance between tracks and detections. |
multi_predict |
Predicts the location of tracks. |
reset_id |
Resets the ID counter of STrack. |
joint_stracks |
Combines two lists of stracks. |
sub_stracks |
Filters out the stracks present in the second list from the first list. |
remove_duplicate_stracks |
Removes duplicate stracks based on IoU. |
Source code in ultralytics/trackers/byte_tracker.py
get_dists
Calculates the distance between tracks and detections using IoU and fuses scores.
Source code in ultralytics/trackers/byte_tracker.py
get_kalmanfilter
init_track
Initialize object tracking with detections and scores using STrack algorithm.
Source code in ultralytics/trackers/byte_tracker.py
joint_stracks
staticmethod
Combine two lists of stracks into a single one.
Source code in ultralytics/trackers/byte_tracker.py
multi_predict
remove_duplicate_stracks
staticmethod
Remove duplicate stracks with non-maximum IoU distance.
Source code in ultralytics/trackers/byte_tracker.py
reset
Reset tracker.
Source code in ultralytics/trackers/byte_tracker.py
reset_id
staticmethod
sub_stracks
staticmethod
DEPRECATED CODE in https://github.com/ultralytics/ultralytics/pull/1890/ stracks = {t.track_id: t for t in tlista} for t in tlistb: tid = t.track_id if stracks.get(tid, 0): del stracks[tid] return list(stracks.values())
Source code in ultralytics/trackers/byte_tracker.py
update
Updates object tracker with new detections and returns tracked object bounding boxes.
Source code in ultralytics/trackers/byte_tracker.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|