fix(detection): keep from_inference aligned on partial masks#2362
Merged
Borda merged 3 commits intoJun 30, 2026
Conversation
process_roboflow_result appended a mask only for predictions carrying one (RLE or polygon), while xyxy/confidence/class_id were appended for every prediction. A result mixing masked and box-only predictions (e.g. a segmentation batch where one polygon is empty) produced a mask array shorter than the boxes, so Detections.from_inference raised a shape-mismatch error. Append None for box-only predictions and build the mask array only when every prediction has a mask, otherwise drop masks to preserve alignment, mirroring the tracker_id handling. Fully-masked and mask-free results are unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2362 +/- ##
=======================================
Coverage 83% 83%
=======================================
Files 69 69
Lines 9616 9622 +6
=======================================
+ Hits 7941 7947 +6
Misses 1675 1675 🚀 New features to boost your workflow:
|
from_inference aligned on partial masks
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a robustness issue in the Roboflow/Inference connector path by ensuring mask handling stays aligned with xyxy when a batch mixes masked and box-only predictions. It updates process_roboflow_result to avoid producing misaligned mask arrays that previously caused Detections.from_inference to raise on mixed batches.
Changes:
- Ensure
process_roboflow_resultappendsNonefor box-only predictions and drops masks (with a warning) when only a subset of predictions includes mask data. - Update the existing unit test that previously documented the misalignment as a known limitation to reflect the new aligned behavior.
- Add an end-to-end
Detections.from_inferenceregression test covering a mixed masked/box-only batch.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/supervision/detection/utils/internal.py |
Keeps mask collection aligned by inserting None for box-only detections and dropping masks on partial-mask batches to prevent shape errors. |
tests/detection/utils/test_internal.py |
Updates the expected output for a mixed RLE + box-only batch to confirm masks are dropped (not misaligned). |
tests/detection/test_core.py |
Adds an end-to-end regression test asserting mixed mask presence does not crash and results in mask is None. |
…cker_id - Update `masks` Returns clause to document partial-drop case and corrupt-RLE blast radius (D1+C1) - Remove stale "known limitation" note from from_inference docstring; describe actual behavior (D2) - Extract _all_present_or_none() helper; eliminate duplicated partial-drop-warn pattern (S1) --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Borda
approved these changes
Jun 30, 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
process_roboflow_resultappends a mask only for predictions that carry one (RLE or polygon), but appendsxyxy,confidenceandclass_idfor every prediction. A result that mixes masked and box-only predictions therefore ends up with a mask array shorter than the boxes, andDetections.from_inferenceraises:This shows up with segmentation results where one polygon is empty/degenerate and falls back to a box, so part of the batch has masks and part does not.
This is the same shape of issue as #2353 (partial
tracker_id), in the same function; the mask path was the remaining case.Fix
Append
Nonefor box-only predictions to keep the list aligned, and build the mask array only when every prediction has a mask, otherwise drop masks (with a warning) to preserve alignment withxyxy. Fully-masked and mask-free results are unchanged. Missing entries are detected by identity (mask is None) sinceNone in maskswould compare numpy arrays element-wise and raise.Tests
Added an end-to-end
from_inferencetest for a mixed masked/box-only batch, and updated the existingprocess_roboflow_resultcase that previously documented the misalignment as a known limitation.