roboflow/supervision · error · ValueError
F1Score with `MetricTarget.MASKS` requires detections to inc
Error message
F1Score with `MetricTarget.MASKS` requires detections to include masks.
What it means
Error "F1Score with `MetricTarget.MASKS` requires detections to include masks." thrown in roboflow/supervision.
Source
Thrown at src/supervision/metrics/f1_score.py:535
return result_f1_score
def _detections_content(
self, detections: Detections
) -> npt.NDArray[Any] | CompactMask:
"""Return boxes, masks or oriented bounding boxes from detections.
For the mask target this may return a
:class:`~supervision.detection.compact_mask.CompactMask` rather than a
dense boolean array when the detections carry compact masks.
"""
if self._metric_target == MetricTarget.BOXES:
return cast(npt.NDArray[Any], detections.xyxy)
if self._metric_target == MetricTarget.MASKS:
if detections.mask is not None:
# detections.mask is NDArray[bool] | CompactMask; return as-is.
return detections.mask
if len(detections) > 0:
raise ValueError(
"F1Score with `MetricTarget.MASKS` requires detections to "
"include masks."
)
return self._make_empty_content()
if self._metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
obb = detections.data.get(ORIENTED_BOX_COORDINATES)
if obb is not None and len(obb) > 0:
result_obb: npt.NDArray[np.float32] = np.array(obb, dtype=np.float32)
return result_obb
return self._make_empty_content()
raise ValueError(f"Invalid metric target: {self._metric_target}")
def _make_empty_content(self) -> npt.NDArray[Any]:
if self._metric_target == MetricTarget.BOXES:
empty_boxes: npt.NDArray[np.float32] = np.empty((0, 4), dtype=np.float32)
return empty_boxes
if self._metric_target == MetricTarget.MASKS:
empty_masks: npt.NDArray[np.bool_] = np.empty((0, 0, 0), dtype=bool)View on GitHub (pinned to 7f254d9784)
Solutions
- Include masks in the Detections when using MetricTarget.MASKS with F1Score.
- If masks are unavailable, use MetricTarget.BOXES instead.
When it happens
Trigger: Thrown at src/supervision/metrics/f1_score.py:535 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/4a9a01359e084562.
Report an issue: GitHub.