Skip to content

fix(detection): keep from_inference aligned on partial masks#2362

Open
kounelisagis wants to merge 1 commit into
roboflow:developfrom
kounelisagis:fix/from-inference-partial-masks
Open

fix(detection): keep from_inference aligned on partial masks#2362
kounelisagis wants to merge 1 commit into
roboflow:developfrom
kounelisagis:fix/from-inference-partial-masks

Conversation

@kounelisagis

Copy link
Copy Markdown
Contributor

Bug

process_roboflow_result appends a mask only for predictions that carry one (RLE or polygon), but appends xyxy, confidence and class_id for every prediction. A result that mixes masked and box-only predictions therefore ends up with a mask array shorter than the boxes, and Detections.from_inference raises:

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

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 None for 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 with xyxy. Fully-masked and mask-free results are unchanged. Missing entries are detected by identity (mask is None) since None in masks would compare numpy arrays element-wise and raise.

Tests

Added an end-to-end from_inference test for a mixed masked/box-only batch, and updated the existing process_roboflow_result case that previously documented the misalignment as a known limitation.

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

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82%. Comparing base (09b2199) to head (d637e91).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2362   +/-   ##
=======================================
  Coverage       82%     82%           
=======================================
  Files           68      68           
  Lines         9560    9564    +4     
=======================================
+ Hits          7881    7885    +4     
  Misses        1679    1679           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant