{"record":{"id":"494aca95a31e48d9","repo":"roboflow/supervision","slug":"keypoint-confidence-first-dimension-must-be-n-b","errorCode":null,"errorMessage":"keypoint_confidence first dimension must be {n}, but got shape {actual_shape}","messagePattern":"keypoint_confidence first dimension must be (.+?), but got shape (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/validators/__init__.py","lineNumber":140,"sourceCode":"    deprecated_in=\"0.29.0\",\n    remove_in=\"0.32.0\",\n)\ndef validate_confidence(confidence: Any, n: int) -> None:\n    void(confidence, n)\n\n\ndef _validate_keypoint_confidence(confidence: Any, n: int, m: int) -> None:\n    \"\"\"Validate per-keypoint confidence: 2D ``np.ndarray`` with shape ``(n, m)``.\"\"\"\n    actual_shape = str(getattr(confidence, \"shape\", None))\n\n    if confidence is not None:\n        if not isinstance(confidence, np.ndarray) or confidence.ndim != 2:\n            raise ValueError(\n                f\"keypoint_confidence must be a 2D np.ndarray with shape (n, m), but \"\n                f\"got shape {actual_shape}\"\n            )\n        if confidence.shape[0] != n:\n            raise ValueError(\n                f\"keypoint_confidence first dimension must be {n}, \"\n                f\"but got shape {actual_shape}\"\n            )\n        if n > 0 and confidence.shape[1] != m:\n            raise ValueError(\n                f\"keypoint_confidence second dimension must be {m}, but \"\n                f\"got shape {actual_shape}\"\n            )\n\n\n@deprecated(  # type: ignore[untyped-decorator]\n    target=_validate_keypoint_confidence,\n    deprecated_in=\"0.29.0\",\n    remove_in=\"0.32.0\",\n)\ndef validate_key_point_confidence(confidence: Any, n: int, m: int) -> None:\n    void(confidence, n, m)\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/validators/__init__.py#L122-L158","documentation":"Raised by supervision.validators._validate_keypoint_confidence when confidence is 2D but its first dimension differs from n, the number of key-point objects in xy. Each object needs its own row of m per-keypoint scores.","triggerScenarios":"Constructing KeyPoints with xy of shape (4, 17, 2) but confidence of shape (1, 17) or (3, 17).","commonSituations":"Detecting multiple people but reusing a single skeleton's confidence; filtering detected objects without filtering confidence rows; model returning per-frame rather than per-object scores.","solutions":["Index confidence with the same object mask used on xy: conf = conf[keep_idx].","Tile a shared row only if truly identical: np.tile(conf, (n, 1)).","Verify conf.shape == (xy.shape[0], xy.shape[1]) with an assert before construction."],"exampleFix":"# before\nkp = KeyPoints(xy=xy, confidence=conf)  # xy:(4,17,2), conf:(1,17)\n\n# after\nkp = KeyPoints(xy=xy, confidence=conf[keep_idx])  # keep_idx also applied to xy","handlingStrategy":"validation","validationCode":"confidence = np.asarray(confidence, dtype=np.float32)\nassert confidence.shape[0] == xy.shape[0], \"one confidence row per object\"\nkp = KeyPoints(xy=xy, confidence=confidence)","typeGuard":"def kp_conf_rows_match(confidence: np.ndarray, xy: np.ndarray) -> bool:\n    return confidence.ndim == 2 and confidence.shape[0] == xy.shape[0]","tryCatchPattern":null,"preventionTips":["Index confidence with the same object mask as xy.","Assert shape (n, m) matches xy before construction.","Never reuse one object's confidence for a multi-object batch."],"tags":["keypoints","confidence","validation","shape"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}