roboflow/supervision · error · ValueError
ConfusionMatrix can only be calculated for Detections with c
Error message
ConfusionMatrix can only be calculated for Detections with class_id
What it means
Error "ConfusionMatrix can only be calculated for Detections with class_id" thrown in roboflow/supervision.
Source
Thrown at src/supervision/metrics/detection.py:134
(1, 6)
>>> obb_coords = np.array([[0, 0, 10, 0, 10, 10, 0, 10]], dtype=np.float32)
>>> det_obb = sv.Detections(
... xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),
... class_id=np.array([0]),
... data={ORIENTED_BOX_COORDINATES: obb_coords},
... )
>>> tensor_obb = detections_to_tensor(
... det_obb, metric_target=MetricTarget.ORIENTED_BOUNDING_BOXES
... )
>>> tensor_obb.shape
(1, 9)
```
"""
_assert_supported_target(metric_target)
if detections.class_id is None:
raise ValueError(
"ConfusionMatrix can only be calculated for Detections with class_id"
)
box_data: npt.NDArray[np.float32]
if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:
obb = detections.data.get(ORIENTED_BOX_COORDINATES)
if obb is None:
if len(detections) > 0:
raise ValueError(
"ORIENTED_BOUNDING_BOXES requested, but "
f"{ORIENTED_BOX_COORDINATES} is missing from detections.data"
)
box_data = np.empty((0, 8), dtype=np.float32)
else:
obb_arr = np.asarray(obb, dtype=np.float32)
# Normalize (N, 4, 2) → (N, 8) as produced by from_ultralytics.
if obb_arr.ndim == 3 and obb_arr.shape[1:] == (4, 2):
obb_arr = obb_arr.reshape(-1, 8)View on GitHub (pinned to 7f254d9784)
Solutions
- Set class_id on the Detections before computing the confusion matrix.
- Derive class_id from your model output and pass it to the Detections constructor.
When it happens
Trigger: Thrown at src/supervision/metrics/detection.py:134 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/6d9f31686708c873.
Report an issue: GitHub.