roboflow/supervision · error · ValueError
Cannot merge CompactMask objects with different image shapes
Error message
Cannot merge CompactMask objects with different image shapes.
What it means
Error "Cannot merge CompactMask objects with different image shapes." thrown in roboflow/supervision.
Source
Thrown at src/supervision/detection/core.py:3346
all_xyxy[:, 0].min(),
all_xyxy[:, 1].min(),
all_xyxy[:, 2].max(),
all_xyxy[:, 3].max(),
]
],
dtype=np.float32,
)
data = winner.data
# Mask union via logical OR. Preserve CompactMask outputs without re-cropping
# to the merged box, because source masks may legitimately extend outside it.
masks = [d.mask for d in detections if d.mask is not None]
if masks:
if all(isinstance(m, CompactMask) for m in masks):
compact_masks = cast(list[CompactMask], masks)
image_shape = compact_masks[0].image_shape
if any(m.image_shape != image_shape for m in compact_masks):
raise ValueError(
"Cannot merge CompactMask objects with different image shapes."
)
union_mask = np.zeros(image_shape, dtype=bool)
for compact_mask in compact_masks:
union_mask |= compact_mask.to_dense()[0]
union_xyxy = mask_to_xyxy(union_mask[np.newaxis]).astype(np.float32)
mask = CompactMask.from_dense(
masks=union_mask[np.newaxis],
xyxy=union_xyxy,
image_shape=image_shape,
)
else:
dense_masks = [
m.to_dense() if isinstance(m, CompactMask) else m for m in masks
]
mask = np.logical_or.reduce(np.concatenate(dense_masks, axis=0))[np.newaxis]
else:
mask = NoneView on GitHub (pinned to 7f254d9784)
Solutions
- Merge only CompactMask objects created for the same image shape.
- Normalize all masks to a single image_shape (resize/pad) before merging.
When it happens
Trigger: Thrown at src/supervision/detection/core.py:3346 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/3ffe192a4497f0c4.
Report an issue: GitHub.