roboflow/supervision · error · ValueError
All or none of the 'mask' fields must be None
Error message
All or none of the 'mask' fields must be None
What it means
Error "All or none of the 'mask' fields must be None" thrown in roboflow/supervision.
Source
Thrown at src/supervision/detection/core.py:2444
for detections in detections_list:
_validate_detections_fields(
xyxy=detections.xyxy,
mask=detections.mask,
confidence=detections.confidence,
class_id=detections.class_id,
tracker_id=detections.tracker_id,
data=detections.data,
)
xyxy = np.vstack([d.xyxy for d in detections_list])
def stack_mask_or_none() -> npt.NDArray[np.generic] | CompactMask | None:
masks = [d.mask for d in detections_list]
if all(m is None for m in masks):
return None
if any(m is None for m in masks):
raise ValueError("All or none of the 'mask' fields must be None")
if all(isinstance(m, CompactMask) for m in masks):
return CompactMask.merge(cast(list[CompactMask], masks))
if all(not isinstance(m, CompactMask) for m in masks):
# All-dense: preserve backward-compatible dense stacking.
return cast(
npt.NDArray[np.generic], np.vstack([np.asarray(m) for m in masks])
)
# Mixed dense and CompactMask: convert dense masks to CompactMask to
# avoid materialising a full (N, H, W) stack.
compact_image_shapes = {
m.image_shape for m in masks if isinstance(m, CompactMask)
}
if len(compact_image_shapes) != 1:
raise ValueError(
"Cannot merge CompactMask objects with different image shapes: "
f"{sorted(compact_image_shapes)}"
)
image_shape: tuple[int, int] = next(iter(compact_image_shapes))View on GitHub (pinned to 7f254d9784)
Solutions
- Ensure every Detections object being merged either has a mask or none of them do; do not mix masked and unmasked Detections.
- If only some detections have masks, either compute masks for all of them or drop the mask field from all before merging.
When it happens
Trigger: Thrown at src/supervision/detection/core.py:2444 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/9fe603c381d912c2.
Report an issue: GitHub.