{"record":{"id":"ace5bb015f05582c","repo":"roboflow/supervision","slug":"keypoint-confidence-second-dimension-must-be-m","errorCode":null,"errorMessage":"keypoint_confidence second dimension must be {m}, but got shape {actual_shape}","messagePattern":"keypoint_confidence second dimension must be (.+?), but got shape (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/validators/__init__.py","lineNumber":145,"sourceCode":"\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\n\n@deprecated(  # type: ignore[untyped-decorator]\n    target=_validate_keypoint_confidence,\n    deprecated_in=\"0.27.0\",\n    remove_in=\"0.31.0\",","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/validators/__init__.py#L127-L163","documentation":"Raised by supervision.validators._validate_keypoint_confidence when confidence's second dimension differs from m, the number of keypoints per object implied by xy. Checked only when n > 0. Mixing keypoint schemas (17-point COCO vs 16-point MPII, etc.) is the usual cause.","triggerScenarios":"Constructing KeyPoints with xy of shape (2, 17, 2) but confidence of shape (2, 16); using a pose model's score vector from a different skeleton than the coordinates.","commonSituations":"Swapping pose models without regenerating the confidence arrays; hardcoded keypoint counts; slicing keypoints (e.g. dropping a nose point) without slicing confidence columns.","solutions":["Derive m from xy and rebuild confidence with m columns: m = xy.shape[1].","Slice columns in sync: kp = KeyPoints(xy=xy[:, idx], confidence=conf[:, idx]).","Use None for confidence and rely on xy[..., 2] when shapes are uncertain."],"exampleFix":"# before\nkp = KeyPoints(xy=xy, confidence=conf)  # xy:17 points, conf:16 scores\n\n# after\nkp = KeyPoints(xy=xy, confidence=conf[:, : xy.shape[1]])  # or rebuild with 17","handlingStrategy":"validation","validationCode":"m = xy.shape[1]\nconfidence = np.asarray(confidence, dtype=np.float32)[:, :m]\nkp = KeyPoints(xy=xy, confidence=confidence)","typeGuard":"def kp_conf_cols_match(confidence: np.ndarray, xy: np.ndarray) -> bool:\n    return confidence.ndim == 2 and confidence.shape[1] == xy.shape[1]","tryCatchPattern":null,"preventionTips":["Use one skeleton schema consistently across xy and confidence.","Slice keypoint columns and confidence columns with the same index.","Derive m from xy.shape[1], never hardcode it."],"tags":["keypoints","confidence","validation","shape"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}