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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
result
property
Get current tracking results.
tlwh
property
Get current position in bounding box format (top left x, top left y, width, height).
xywh
property
Get current position in bounding box format (center x, center 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).
__init__(xywh, score, cls)
Initialize new STrack instance.
Source code in ultralytics/trackers/byte_tracker.py
__repr__()
Return a string representation of the BYTETracker object with start and end frames and track ID.
activate(kalman_filter, frame_id)
Start a new tracklet.
Source code in ultralytics/trackers/byte_tracker.py
convert_coords(tlwh)
Convert a bounding box's top-left-width-height format to its x-y-aspect-height equivalent.
multi_gmc(stracks, H=np.eye(2, 3))
staticmethod
Update state tracks positions and covariances using a homography matrix.
Source code in ultralytics/trackers/byte_tracker.py
multi_predict(stracks)
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(new_track, frame_id, new_id=False)
Reactivates a previously lost track with a new detection.
Source code in ultralytics/trackers/byte_tracker.py
tlwh_to_xyah(tlwh)
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(new_track, frame_id)
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
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
|
__init__(args, frame_rate=30)
Initialize a YOLOv8 object to track objects with given arguments and frame rate.
Source code in ultralytics/trackers/byte_tracker.py
get_dists(tracks, detections)
Calculates the distance between tracks and detections using IoU and fuses scores.
Source code in ultralytics/trackers/byte_tracker.py
get_kalmanfilter()
init_track(dets, scores, cls, img=None)
Initialize object tracking with detections and scores using STrack algorithm.
Source code in ultralytics/trackers/byte_tracker.py
joint_stracks(tlista, tlistb)
staticmethod
Combine two lists of stracks into a single one.
Source code in ultralytics/trackers/byte_tracker.py
multi_predict(tracks)
remove_duplicate_stracks(stracksa, stracksb)
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(tlista, tlistb)
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(results, img=None)
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 |
|