perf(kf): construct small diagonal covariances directly - #578
Open
JESUSROYETH wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The scale-aware noise paths in
BoTSORTTrackletandMcByteTrackletrebuild 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-purposenp.diagdispatch 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, andpre-commit run --all-filesis 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:
np.diagmedian [range]Whole tracker, 10 paired runs:
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.