fix(tracker): harden ByteTrack edge cases#2413
Merged
Merged
Conversation
- 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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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:
|
Contributor
There was a problem hiding this comment.
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_idinto the inputDetectionsobject). - 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. |
- 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>
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.
This pull request introduces several important fixes and improvements to the
sv.ByteTracktracker 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.ByteTrackno longer mutates inputDetectionswhen assigning tracker IDs, ensuring that the original detection objects remain unchanged after tracking.1.0are now avoided, so tracks with maximum-confidence detections can still be started.-1IDs, and short-lived tracks do not consume external IDs unless confirmed. [1] [2]Assignment and cost matrix handling:
linear_assignmentfunction inmatching.pynow operates on a copy of the cost matrix, ensuring the input matrix is not mutated during assignment.Testing and regression coverage:
test_byte_tracker.pyto 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