{"record":{"id":"6d9f31686708c873","repo":"roboflow/supervision","slug":"confusionmatrix-can-only-be-calculated-for-detecti","errorCode":null,"errorMessage":"ConfusionMatrix can only be calculated for Detections with class_id","messagePattern":"ConfusionMatrix can only be calculated for Detections with class_id","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/detection.py","lineNumber":134,"sourceCode":"        (1, 6)\n        >>> obb_coords = np.array([[0, 0, 10, 0, 10, 10, 0, 10]], dtype=np.float32)\n        >>> det_obb = sv.Detections(\n        ...     xyxy=np.array([[0, 0, 10, 10]], dtype=np.float32),\n        ...     class_id=np.array([0]),\n        ...     data={ORIENTED_BOX_COORDINATES: obb_coords},\n        ... )\n        >>> tensor_obb = detections_to_tensor(\n        ...     det_obb, metric_target=MetricTarget.ORIENTED_BOUNDING_BOXES\n        ... )\n        >>> tensor_obb.shape\n        (1, 9)\n\n        ```\n    \"\"\"\n    _assert_supported_target(metric_target)\n\n    if detections.class_id is None:\n        raise ValueError(\n            \"ConfusionMatrix can only be calculated for Detections with class_id\"\n        )\n\n    box_data: npt.NDArray[np.float32]\n    if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES:\n        obb = detections.data.get(ORIENTED_BOX_COORDINATES)\n        if obb is None:\n            if len(detections) > 0:\n                raise ValueError(\n                    \"ORIENTED_BOUNDING_BOXES requested, but \"\n                    f\"{ORIENTED_BOX_COORDINATES} is missing from detections.data\"\n                )\n            box_data = np.empty((0, 8), dtype=np.float32)\n        else:\n            obb_arr = np.asarray(obb, dtype=np.float32)\n            # Normalize (N, 4, 2) → (N, 8) as produced by from_ultralytics.\n            if obb_arr.ndim == 3 and obb_arr.shape[1:] == (4, 2):\n                obb_arr = obb_arr.reshape(-1, 8)","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/detection.py#L116-L152","documentation":"Error \"ConfusionMatrix can only be calculated for Detections with class_id\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/metrics/detection.py:134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}