ocsort
sleap_nn.tracking.mot.ocsort
¶
OC-SORT (Cao et al., 2023) and Deep OC-SORT (Maggiolino et al., 2023).
Observation-centric SORT: re-updates a re-found track's Kalman state along a virtual trajectory over the gap (ORU), adds a velocity-direction consistency term to the association (OCM) and recovers tracks from their last observation (OCR). Deep OC-SORT adds a score-adaptive appearance EMA and an appearance term weighted by how discriminative it is per row/column (adaptive weighting). Original implementations from the published algorithms.
OC-SORT, per frame (after every live track is predicted to this step):
- Detections are split by score:
D_hi(s > track_high_threshold) and, only whenuse_byte,D_lo(track_low_threshold < s <= track_high_threshold). Everything else is ignored. OnlyD_hidetections start tracks. - Stage 1 -- one pool of every live track (tentative, confirmed and lost
alike, as in SORT) against
D_hi. A pair is admissible on GEOMETRY ALONE: similarity of the track's prediction>= min_match_similarity. If the admissible pairs form a one-to-one pattern they are taken as is; otherwise the assignment maximizessimilarity + OCMover the matrix and drops the inadmissible pairs (:func:~sleap_nn.tracking.mot.association. linear_assignment_masked). OCM (observation-centric momentum) rewards detections lying in the direction the track was moving: the angle between the track's direction (from its observationdelta_tsteps back to its last observation) and the direction from that earlier observation to the detection, weighted byinertiaand the detection score. - BYTE (
use_byteonly) -- the remaining tracks' predictions againstD_lo, admissible at>= min_match_similarity. - OCR (observation-centric recovery) -- the remaining
D_hiagainst the remaining tracks' LAST OBSERVATIONS (not their predictions), admissible at>= min_match_similarity: recovers tracks whose prediction drifted while the animal stopped or turned. - Lifecycle (base class): a track's state is frozen at its first miss and,
when it is re-matched, re-updated along a virtual trajectory linearly
interpolated between its last observation and the new one (ORU) before the
real update. SORT-family counters (
hitsstart at 0, confirmation onhit_streak >= min_hits, tentative tracks coast) and removal after more thantrack_bufferunmatched steps.
Deep OC-SORT is OC-SORT (D_hi only, no BYTE stage) on a [cx, cy, w, h]
Kalman filter whose size velocities are zeroed while a track is frozen, with:
- a score-adaptive appearance EMA (base class memory,
adaptive_ema: a detection at the score floortrack_high_thresholddoes not move the EMA), updated under the appearance quality gate; - a STANDARDIZED appearance term in the stage-1 objective,
similarity + OCM + W * E'withE' = clip(2 (cos - mu_neg) / (mu_pos - mu_neg) - 1, -1, 1)(cos: cosine of the detection vector to the track's EMA;mu_pos/mu_neg: the video's calibrated median true / competitor EMA cosines), so the term means the same thing whatever the embedding model's cosine scale. When appearance is enabled for association but the video has no usablemu_pos/mu_negspread -- an explicitappearance_thresholdon a video that is uncalibrated (noprepare()) or too short / with too few animals to calibrate --E'is replaced by the raw EMA cosine, the reference's term (logged once;resolved["appearance"]["association_term"]records which term ran). The term is 0 (neutral) where either side has no vector, where the pair has no geometric overlap, and everywhere when appearance is disabled.Wis the adaptive weight (w_assoc_embplus half the row and column top-1/top-2 margins ofE', each capped ataw_param) or the constantw_assoc_embwithaw_off. Appearance orders COMPETING candidates but never vetoes an uncontested one: on a pair that is the only admissible candidate of both its row and its column a negativeW * E'is clamped to 0 (otherwise the masked assignment trades it for an inadmissible, zero-evidence cell whenever an unrelated ambiguity elsewhere in the frame stops the one-to-one shortcut); - an optional appearance rescue (
rescue): a pair belowmin_match_similaritybut at or aboverescue_min_similarityis also admissible when appearance is DECISIVE: its EMA cosine clears the appearance gate and is the top of its row and column among the geometrically plausible pairs by at least the calibrated marginm_assoc. The one-to-one shortcut is evaluated on this extended admissibility.
The OCR stage is geometric only, as in the reference. tracking_score is
always the geometric similarity of the matched pair (prediction or last
observation), never the composite objective.
Classes:
| Name | Description |
|---|---|
DeepOCSORTTracker |
Deep OC-SORT tracker (see :mod: |
OCSORTTracker |
OC-SORT tracker (see :mod: |
DeepOCSORTTracker
¶
Bases: OCSORTTracker
Deep OC-SORT tracker (see :mod:sleap_nn.tracking.mot.ocsort).
Methods:
| Name | Description |
|---|---|
__init__ |
Create a tracker for one video. |
prepare |
Per-video pre-pass (see :meth: |
Source code in sleap_nn/tracking/mot/ocsort.py
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 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
__init__(params, carrier='pose', n_nodes=None)
¶
Create a tracker for one video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
MOTParams
|
Resolved parameters (see :meth: |
required |
carrier
|
str
|
|
'pose'
|
n_nodes
|
Optional[int]
|
Skeleton size for pose detections ( |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
On an unknown carrier, or parameters resolved for another tracker. |
Source code in sleap_nn/tracking/mot/ocsort.py
prepare(frames)
¶
Per-video pre-pass (see :meth:BaseMOTTracker.prepare).
Without any usable appearance vector (the shared rule:
:func:~sleap_nn.tracking.mot.detections.has_usable_embedding; a NaN or
all-zero vector is missing) Deep OC-SORT is OC-SORT on a [cx, cy, w,
h] filter: with appearance_threshold="auto" this is logged and the
video is tracked on geometry alone; an explicit (float)
appearance_threshold asks for appearance that does not exist and
raises. An explicit threshold on a video whose calibration cannot
standardize the cosines (too few trials) logs that the raw EMA cosine
is used instead of E'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
Sequence[Tuple[int, Sequence[Any]]]
|
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
An explicit |
Source code in sleap_nn/tracking/mot/ocsort.py
OCSORTTracker
¶
Bases: BaseMOTTracker
OC-SORT tracker (see :mod:sleap_nn.tracking.mot.ocsort).
Source code in sleap_nn/tracking/mot/ocsort.py
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 210 211 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 | |