{"record":{"id":"b5d9893dd3702cf2","repo":"roboflow/supervision","slug":"targets-must-have-shape-n-expected-target-cols-b5d989","errorCode":null,"errorMessage":"Targets must have shape (N, {expected_target_cols}). Got {targets.shape} instead.","messagePattern":"Targets must have shape \\(N, (.+?)\\)\\. Got (.+?) instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/detection.py","lineNumber":914,"sourceCode":"\n        Returns:\n            Confusion matrix based on a single image.\n        \"\"\"\n        _assert_supported_target(metric_target)\n\n        expected_pred_cols = (\n            10 if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES else 6\n        )\n        expected_target_cols = (\n            9 if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES else 5\n        )\n        if predictions.ndim != 2 or predictions.shape[1] != expected_pred_cols:\n            raise ValueError(\n                f\"Predictions must have shape (M, {expected_pred_cols}). \"\n                f\"Got {predictions.shape} instead.\"\n            )\n        if targets.ndim != 2 or targets.shape[1] != expected_target_cols:\n            raise ValueError(\n                f\"Targets must have shape (N, {expected_target_cols}). \"\n                f\"Got {targets.shape} instead.\"\n            )\n\n        result_matrix: npt.NDArray[np.int32] = np.zeros(\n            (num_classes + 1, num_classes + 1), dtype=np.int32\n        )\n\n        # Filter predictions by confidence threshold\n        coords_dim = 8 if metric_target == MetricTarget.ORIENTED_BOUNDING_BOXES else 4\n        class_id_idx = coords_dim\n        conf_idx = coords_dim + 1\n\n        confidence = predictions[:, conf_idx]\n        detection_batch_filtered = predictions[confidence >= conf_threshold]\n\n        if len(detection_batch_filtered) == 0:\n            true_classes = _validated_class_ids(","sourceCodeStart":896,"sourceCodeEnd":932,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/detection.py#L896-L932","documentation":"Error \"Targets must have shape (N, {expected_target_cols}). Got {targets.shape} instead.\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/metrics/detection.py:914 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reshape the targets array to (N, expected_target_cols) before calling.","Check for accidental transposition or extra dimensions in the targets array."],"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-15T17:31:12.345Z"}