{"record":{"id":"8c523b958db15da8","repo":"roboflow/supervision","slug":"visible-second-dimension-must-be-m-but-got-shap","errorCode":null,"errorMessage":"visible second dimension must be {m}, but got shape {actual_shape}","messagePattern":"visible second dimension must be (.+?), but got shape (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/validators/__init__.py","lineNumber":254,"sourceCode":"def _validate_visible(visible: Any, n: int, m: int) -> None:\n    \"\"\"Validate per-keypoint visibility mask.\n\n    Expects a 2D bool ``np.ndarray`` with shape ``(n, m)``.\n    \"\"\"\n    if visible is None:\n        return\n    actual_shape = str(getattr(visible, \"shape\", None))\n    if not isinstance(visible, np.ndarray) or visible.ndim != 2:\n        raise ValueError(\n            \"visible must be a 2D np.ndarray with shape (n, m), but \"\n            f\"got shape {actual_shape}\"\n        )\n    if visible.shape[0] != n:\n        raise ValueError(\n            f\"visible first dimension must be {n}, but got shape {actual_shape}\"\n        )\n    if n > 0 and visible.shape[1] != m:\n        raise ValueError(\n            f\"visible second dimension must be {m}, but got shape {actual_shape}\"\n        )\n\n\ndef _validate_detections_fields(\n    xyxy: Any,\n    mask: Any,\n    class_id: Any,\n    confidence: Any,\n    tracker_id: Any,\n    data: dict[str, Any],\n) -> None:\n    _validate_xyxy(xyxy)\n    n = len(xyxy)\n    _validate_mask(mask, n)\n    _validate_class_id(class_id, n)\n    _validate_confidence(confidence, n)\n    _validate_tracker_id(tracker_id, n)","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/validators/__init__.py#L236-L272","documentation":"Raised by supervision.validators._validate_visible when visible's second dimension does not equal m, the number of keypoints per object expected from xy. The check runs only when n > 0, because with zero objects m cannot be cross-validated.","triggerScenarios":"Constructing KeyPoints with xy of shape (1, 17, 2) but a visible mask of shape (1, 13) — e.g. a COCO-17 model with a 13-point visibility vector.","commonSituations":"Mixing keypoint schemas (COCO 17 vs. MPII 16 vs. custom 13); hardcoding m from a different pose model; keeping a stale visibility mask after switching skeletons.","solutions":["Derive m from xy: m = xy.shape[1], and build visible with exactly m columns.","Trim/pad the mask to match: visible = visible[:, :xy.shape[1]].","Use None for visible when unsure, and let KeyPoints infer visibility."],"exampleFix":"# before\nkp = KeyPoints(xy=xy, visible=vis_13)  # xy has 17 points\n\n# after\nkp = KeyPoints(xy=xy, visible=vis_13[:, :xy.shape[1]])  # or rebuild with 17 cols","handlingStrategy":"validation","validationCode":"m = xy.shape[1]\nvisible = np.asarray(visible, dtype=bool)[:, :m]\nkp = KeyPoints(xy=xy, visible=visible)","typeGuard":"def visible_cols_match(visible: np.ndarray, xy: np.ndarray) -> bool:\n    return visible.ndim == 2 and visible.shape[1] == xy.shape[1]","tryCatchPattern":null,"preventionTips":["Pin one keypoint schema per pipeline; document m.","Slice keypoint columns and visibility columns together.","Derive m from xy.shape[1] instead of hardcoding."],"tags":["keypoints","validation","shape","mask"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}