roboflow/supervision · error · ValueError

keypoint_confidence second dimension must be {m}, but got sh

Error message

keypoint_confidence second dimension must be {m}, but got shape {actual_shape}

What it means

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.

Source

Thrown at src/supervision/validators/__init__.py:145


def _validate_keypoint_confidence(confidence: Any, n: int, m: int) -> None:
    """Validate per-keypoint confidence: 2D ``np.ndarray`` with shape ``(n, m)``."""
    actual_shape = str(getattr(confidence, "shape", None))

    if confidence is not None:
        if not isinstance(confidence, np.ndarray) or confidence.ndim != 2:
            raise ValueError(
                f"keypoint_confidence must be a 2D np.ndarray with shape (n, m), but "
                f"got shape {actual_shape}"
            )
        if confidence.shape[0] != n:
            raise ValueError(
                f"keypoint_confidence first dimension must be {n}, "
                f"but got shape {actual_shape}"
            )
        if n > 0 and confidence.shape[1] != m:
            raise ValueError(
                f"keypoint_confidence second dimension must be {m}, but "
                f"got shape {actual_shape}"
            )


@deprecated(  # type: ignore[untyped-decorator]
    target=_validate_keypoint_confidence,
    deprecated_in="0.29.0",
    remove_in="0.32.0",
)
def validate_key_point_confidence(confidence: Any, n: int, m: int) -> None:
    void(confidence, n, m)


@deprecated(  # type: ignore[untyped-decorator]
    target=_validate_keypoint_confidence,
    deprecated_in="0.27.0",
    remove_in="0.31.0",

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Derive m from xy and rebuild confidence with m columns: m = xy.shape[1].
  2. Slice columns in sync: kp = KeyPoints(xy=xy[:, idx], confidence=conf[:, idx]).
  3. Use None for confidence and rely on xy[..., 2] when shapes are uncertain.

Example fix

# before
kp = KeyPoints(xy=xy, confidence=conf)  # xy:17 points, conf:16 scores

# after
kp = KeyPoints(xy=xy, confidence=conf[:, : xy.shape[1]])  # or rebuild with 17
Defensive patterns

Strategy: validation

Validate before calling

m = xy.shape[1]
confidence = np.asarray(confidence, dtype=np.float32)[:, :m]
kp = KeyPoints(xy=xy, confidence=confidence)

Type guard

def kp_conf_cols_match(confidence: np.ndarray, xy: np.ndarray) -> bool:
    return confidence.ndim == 2 and confidence.shape[1] == xy.shape[1]

Prevention

When it happens

Trigger: 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.

Common situations: Swapping pose models without regenerating the confidence arrays; hardcoded keypoint counts; slicing keypoints (e.g. dropping a nose point) without slicing confidence columns.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/ace5bb015f05582c. Report an issue: GitHub.