Skip to content

fix(detection): do not crash from_inference on partial tracker_id#2353

Merged
Borda merged 4 commits into
roboflow:developfrom
kounelisagis:fix/from-inference-partial-tracker-id
Jun 26, 2026
Merged

fix(detection): do not crash from_inference on partial tracker_id#2353
Borda merged 4 commits into
roboflow:developfrom
kounelisagis:fix/from-inference-partial-tracker-id

Conversation

@kounelisagis

@kounelisagis kounelisagis commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Bug

Detections.from_inference raises when a Roboflow/Inference result has some predictions with a tracker_id and some without:

ValueError: tracker_id must be a 1D np.ndarray with shape (3,), but got shape (2,)

In process_roboflow_result, every branch appends xyxy, confidence, class_id and class for each prediction, but tracker_id was appended only when the key was present. A mixed batch then leaves tracker_ids shorter than the boxes, and Detections validation rejects it.

To be clear about scope: ByteTrack (both supervision's own and the inference block) attaches a tracker_id to 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_id for every prediction (None when absent) and build the array only when all detections carry one, otherwise keep it None. Fully tracked results still get the array, fully untracked results still get None, so existing behavior is unchanged; only the previously crashing mixed case changes (it now drops tracker_id rather than misaligning).

Tests

Added a process_roboflow_result case for a mixed batch and an end to end from_inference test that asserts it no longer raises and keeps all detections.

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.
@kounelisagis kounelisagis requested a review from SkalskiP as a code owner June 24, 2026 11:25
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82%. Comparing base (25d98c8) to head (1c20e36).

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda requested a review from Copilot June 26, 2026 09:14
@Borda Borda added the bug Something isn't working label Jun 26, 2026
@Borda Borda changed the title fix(detection): do not crash from_inference on partial tracker_id fix(detection): do not crash from_inference on partial tracker_id Jun 26, 2026
Comment thread src/supervision/detection/utils/internal.py

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 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_result to collect tracker_id per prediction and only materialize a tracker_id array when all detections have one.
  • Add unit coverage for mixed tracker_id batches at both the parsing level and Detections.from_inference end-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.

Comment thread src/supervision/detection/utils/internal.py
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.
@kounelisagis kounelisagis requested a review from Borda June 26, 2026 10:17
- 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 Borda merged commit 27ba0aa into roboflow:develop Jun 26, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants