Skip to content

fix(tracker): harden ByteTrack edge cases#2413

Merged
Borda merged 3 commits into
developfrom
medium/Dataset-3
Jul 7, 2026
Merged

fix(tracker): harden ByteTrack edge cases#2413
Borda merged 3 commits into
developfrom
medium/Dataset-3

Conversation

@Borda

@Borda Borda commented Jul 7, 2026

Copy link
Copy Markdown
Member

This pull request introduces several important fixes and improvements to the sv.ByteTrack tracker and related utilities, focusing on correctness, stability, and non-mutating behavior. The changes address issues with tracker ID assignment, activation thresholds, input validation, and cost matrix handling, and are accompanied by comprehensive new tests to prevent regressions.

Tracker stability and correctness:

  • sv.ByteTrack no longer mutates input Detections when assigning tracker IDs, ensuring that the original detection objects remain unchanged after tracking.
  • Detections at the activation-threshold boundary (score equal to threshold) are now eligible for matching, improving track continuity.
  • Impossible new-track thresholds above score 1.0 are now avoided, so tracks with maximum-confidence detections can still be started.
  • Zero-area and non-finite tensor boxes are filtered out before Kalman updates, preventing invalid track creation. [1] [2]
  • First-frame tensor updates do not emit unconfirmed -1 IDs, and short-lived tracks do not consume external IDs unless confirmed. [1] [2]

Assignment and cost matrix handling:

  • The linear_assignment function in matching.py now operates on a copy of the cost matrix, ensuring the input matrix is not mutated during assignment.

Testing and regression coverage:

  • Added multiple regression tests in test_byte_tracker.py to verify that tracker IDs are assigned correctly, input objects are not mutated, zero-area boxes are ignored, and cost matrices remain unchanged during assignment. [1] [2]

These changes collectively improve the reliability, safety, and predictability of the ByteTrack tracking implementation.


part of #2408

- Keep ByteTrack confidence-threshold boundary detections eligible and avoid impossible activation thresholds above score 1.0.

- Stop mutating caller-owned detections and assignment cost matrices while preserving matched tracker output.

- Filter invalid tensor boxes before Kalman updates and respect minimum consecutive frames on first-frame tensor updates.

---

Co-authored-by: Codex <codex@openai.com>
@Borda Borda requested a review from SkalskiP as a code owner July 7, 2026 11:44
@Borda Borda requested a review from Copilot July 7, 2026 11:44
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87%. Comparing base (814a226) to head (935c332).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2413   +/-   ##
=======================================
  Coverage       87%     87%           
=======================================
  Files           70      70           
  Lines        10218   10227    +9     
=======================================
+ Hits          8843    8853   +10     
+ Misses        1375    1374    -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

This PR hardens sv.ByteTrack by addressing multiple edge cases around activation/ID assignment, threshold boundaries, invalid tensor inputs, and non-mutating behavior, with regression tests and a changelog entry to lock in the expected behavior.

Changes:

  • Prevents unintended caller-visible mutations (e.g., avoids mutating caller-owned cost matrices and avoids writing tracker_id into the input Detections object).
  • Improves tracking correctness around thresholds and activation/confirmation behavior (inclusive activation threshold, avoids det_thresh > 1.0, fixes short-lived/unconfirmed track ID consumption).
  • Filters invalid tensor inputs (non-finite / zero-area boxes) before Kalman updates, and adds regression tests + changelog note.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/supervision/tracker/byte_tracker/core.py Adds tensor validity filtering, inclusive activation threshold, clamps impossible det_thresh, and avoids mutating input Detections when assigning tracker IDs.
src/supervision/tracker/byte_tracker/single_object_track.py Adjusts activation/confirmation bookkeeping so tracks only consume external IDs when confirmed and don’t emit unconfirmed IDs on first-frame tensor updates.
src/supervision/tracker/byte_tracker/matching.py Makes linear_assignment operate on a copied cost matrix to avoid mutating the caller’s input.
tests/tracker/test_byte_tracker.py Adds regression tests for non-mutation, threshold-boundary matching, invalid tensor filtering, cost-matrix non-mutation, and ID assignment behavior.
docs/changelog.md Documents the user-visible ByteTrack fixes in the Unreleased “Fixed” section.

Comment thread src/supervision/tracker/byte_tracker/core.py
Borda and others added 2 commits July 7, 2026 18:46
- Avoids per-call np.arange allocation by cloning detections with slice(None) while preserving non-mutation behavior.
- Adds regressions for delayed activation on the second consecutive tensor frame and broader invalid-tensor rejection cases.

---

Co-authored-by: Codex <codex@openai.com>
@Borda Borda merged commit dde4227 into develop Jul 7, 2026
26 of 27 checks passed
@Borda Borda deleted the medium/Dataset-3 branch July 7, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants