fix(detection): do not crash from_inference on partial tracker_id#2353
Merged
Borda merged 4 commits intoJun 26, 2026
Merged
Conversation
process_roboflow_result appended tracker_id only for predictions that carried one, while xyxy/confidence/class_id were appended for every prediction. A result where some predictions are tracked and others are not produced a tracker_id array shorter than the boxes, so Detections.from_inference raised "tracker_id must be a 1D np.ndarray with shape (N,)". Collect tracker_id for every prediction (None when absent) and build the array only when all detections carry one, otherwise leave it None. Fully-tracked and untracked results are unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2353 +/- ##
=======================================
Coverage 82% 82%
=======================================
Files 68 68
Lines 9318 9317 -1
=======================================
Hits 7634 7634
+ Misses 1684 1683 -1 🚀 New features to boost your workflow:
|
from_inference on partial tracker_id
Borda
reviewed
Jun 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves robustness of the Roboflow/Inference connector path by preventing Detections.from_inference from raising when tracker_id is only present on a subset of predictions, aligning behavior with “best-effort parsing” expectations for partially-tracked batches.
Changes:
- Update
process_roboflow_resultto collecttracker_idper prediction and only materialize atracker_idarray when all detections have one. - Add unit coverage for mixed
tracker_idbatches at both the parsing level andDetections.from_inferenceend-to-end.
Quality assessment (n/5):
- Code quality: 3/5
- Testing: 4/5
- Documentation: 4/5
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/supervision/detection/utils/internal.py | Adjusts tracker-id collection/creation logic to avoid misaligned arrays and crashes on partial tracking metadata. |
| tests/detection/utils/test_internal.py | Adds a process_roboflow_result regression case for mixed tracker_id presence. |
| tests/detection/test_core.py | Adds an end-to-end regression test ensuring from_inference doesn’t raise and preserves detections for partial tracker_id batches. |
It can hold None for predictions without a tracker_id before the array is built (only when no None is present), so the annotation now matches.
- Add logger.warning when mixed batch detected (some but not all predictions carry tracker_id); consistent with RLE graceful-degradation path that already logs - Update process_roboflow_result Returns clause to document mixed-batch semantics: tracker_ids is None when absent OR when only a subset present - Add tracker_id semantics and masks misalignment limitation note to Detections.from_inference Returns section - Strengthen test_from_inference_partial_tracker_id_does_not_crash with class_id, confidence, xyxy.shape, and class_name assertions - Add all_absent_tracker_id_no_raise parametrize case verifying None not in tracker_ids guard for non-empty all-absent batches - Convert mixed tracker_id case to pytest.param(..., id="mixed_tracker_id_batch_drops_to_none") per CONTRIBUTING.md - Add changelog entry for PR roboflow#2353 crash fix --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
approved these changes
Jun 26, 2026
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.
Bug
Detections.from_inferenceraises when a Roboflow/Inference result has some predictions with atracker_idand some without:In
process_roboflow_result, every branch appendsxyxy,confidence,class_idandclassfor each prediction, buttracker_idwas appended only when the key was present. A mixed batch then leavestracker_idsshorter than the boxes, andDetectionsvalidation rejects it.To be clear about scope: ByteTrack (both supervision's own and the inference block) attaches a
tracker_idto every detection, so a standard tracking pipeline won't hit this. It comes up when predictions are assembled or merged by hand, or come from a source that only tracks some of them. So this is more of a robustness fix: the connector degrades gracefully instead of raising a confusing shape error on that input.Fix
Collect
tracker_idfor every prediction (Nonewhen absent) and build the array only when all detections carry one, otherwise keep itNone. Fully tracked results still get the array, fully untracked results still getNone, so existing behavior is unchanged; only the previously crashing mixed case changes (it now dropstracker_idrather than misaligning).Tests
Added a
process_roboflow_resultcase for a mixed batch and an end to endfrom_inferencetest that asserts it no longer raises and keeps all detections.