Skip to content

perf(kf): construct small diagonal covariances directly - #578

Open
JESUSROYETH wants to merge 1 commit into
roboflow:developfrom
JESUSROYETH:perf/direct-diagonal-covariance
Open

perf(kf): construct small diagonal covariances directly#578
JESUSROYETH wants to merge 1 commit into
roboflow:developfrom
JESUSROYETH:perf/direct-diagonal-covariance

Conversation

@JESUSROYETH

Copy link
Copy Markdown
Contributor

The scale-aware noise paths in BoTSORTTracklet and McByteTracklet rebuild small diagonal Q/R matrices on predict/update, and P when a track starts. The diagonal values are already known, but each of the twelve sites goes through the general-purpose np.diag dispatch anyway.

So this adds the same small helper to both sibling modules: allocate the zero matrix, then assign its flat diagonal stride directly. It keeps the existing values and the float64 output, it just skips the generic path.

Validation

I first compared the baseline against itself, then against this patch, over 6,000 boxes. That covers BoT-SORT and McByte tracklets, XCYCWH/XYXY/XCYCSR representations, restored float32 and float64 states, initial Q/R/P, predict and update. The complete bit-level digest is identical.

I also ran the three tracker families over 36,928 real MOT17 public detections, plus BoT-SORT over 45,442 real DanceTrack ground-truth boxes from five sequences picked to cover a range of sequence sizes. Output boxes were paired by Hungarian IoU, not by index. Matched boxes, tracker IDs and the complete per-frame state digests are exact.

The focused tracker suite passes with 150 tests. pytest -m 'not integration' passes with 1,564 tests, all 4 evaluator integrations pass, and pre-commit run --all-files is clean.

Performance

CPU-only, Python 3.12.3 / NumPy 1.26.4. Inputs are loaded before timing, run order alternates, and garbage collection runs before each sample.

Isolated construction, 50,000 calls per sample:

matrix np.diag median [range] direct median [range] delta paired wins
4×4 0.762 µs [0.752, 0.772] 0.515 µs [0.509, 0.521] -32.33% 15/15
7×7 0.835 µs [0.818, 0.853] 0.571 µs [0.563, 0.594] -31.53% 15/15
8×8 0.857 µs [0.848, 0.890] 0.602 µs [0.593, 0.620] -29.67% 15/15

Whole tracker, 10 paired runs:

stream / tracker develop median [range] this patch median [range] delta paired wins
MOT17 / BoT-SORT 516.62 µs/frame [509.58, 523.09] 502.53 µs/frame [497.52, 509.46] -2.73% 10/10
MOT17 / CBIoU 527.84 µs/frame [506.98, 532.39] 516.65 µs/frame [497.57, 518.49] -2.12% 10/10
MOT17 / McByte 593.26 µs/frame [581.69, 596.65] 580.57 µs/frame [569.95, 585.94] -2.14% 10/10
DanceTrack / BoT-SORT 434.60 µs/frame [428.52, 442.10] 425.34 µs/frame [420.33, 436.75] -2.13% 9/10

The duplicated noise code came through BoT-SORT #386 and McByte #388. #567 made Q and R refresh only where each is actually consumed, then #572 removed the larger bounding-box decode overhead. That left these small matrix builders as a measurable part of what's left.

Open feature PRs #511 and #436 also touch BoT-SORT's tracklet, so this patch doesn't apply cleanly to their current heads. Neither one changes McByte's sibling or proposes this diagonal construction, but if either lands first the BoT-SORT half will need conflict resolution.

@JESUSROYETH
JESUSROYETH requested a review from SkalskiP as a code owner August 22, 2026 10:30
@Borda
Borda requested a balanced review from Copilot August 23, 2026 12:13
@Borda Borda added the enhancement New feature or request label Aug 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes scale-aware Kalman covariance construction while preserving float64 values and tracker behavior.

Changes:

  • Adds direct diagonal-matrix construction.
  • Applies it to Q, R, and initial P in BoT-SORT and McByte.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/trackers/core/botsort/tracklet.py Optimizes BoT-SORT covariance construction.
src/trackers/core/mcbyte/tracklet.py Applies the same optimization to McByte.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants