Sub topic 12
Evaluating Pose: OKS and Keypoint AP
Assume you know NumPy, bounding-box area, supervised-learning loss, and object-detection evaluation. This chapter uses COCO-style 2D pose annotations, where each person has 17 labelled keypoints and a visibility flag.
Why pixel error is not enough
A prediction is close when its keypoints are near the labelled keypoints. However, the same pixel error has different meanings for small and large people. A five-pixel error is more serious for a distant person than for a person filling the image.
Object Keypoint Similarity (OKS) solves this by normalising distance by the ground-truth person area. It also gives each keypoint a tolerance called a sigma. For example, an ankle is harder to label precisely than a nose, so it can use a larger sigma.
For keypoint \(i\), the similarity is:
exp(-d_i² / (2 × area × (2 × sigma_i)²))
The final OKS is the mean similarity over visible or labelled keypoints.
| Input | Purpose |
|---|---|
| Keypoint distance | Measures prediction error |
| Person area | Makes the error scale-aware |
| Per-keypoint sigma | Models annotation difficulty |
| Visibility flag | Selects keypoints included in the score |
import numpy as np
SIGMAS = np.array([
.26, .25, .25, .35, .35, .79, .79, .72, .72,
.62, .62, 1.07, 1.07, .87, .87, .89, .89
]) / 10.0
def oks(gt, pred, visibility, area):
"""Compute COCO-style OKS for one person."""
d2 = ((gt - pred) ** 2).sum(axis=1)
variance = (2 * SIGMAS) ** 2
exponent = d2 / (2 * variance * (area + np.spacing(1)))
labelled = visibility > 0
if not labelled.any():
return 0.0
return float(np.exp(-exponent)[labelled].mean())
gt = np.zeros((17, 2))
pred = np.zeros((17, 2))
visibility = np.ones(17)
print(oks(gt, pred, visibility, area=10_000))A perfect prediction has OKS 1.0. Larger errors produce values closer to 0. The area must be the ground-truth object area, not the image area.
From OKS to keypoint AP
Keypoint average precision (AP) uses OKS in the same general way that object-detection AP uses intersection over union. Each predicted person has:
- 17 keypoint coordinates
- A confidence score used for ranking
- An OKS match against each ground-truth person
At an OKS threshold, such as 0.50, a prediction matches an unassigned ground-truth person when its OKS reaches that threshold. Predictions are processed from highest to lowest confidence. Unmatched predictions are false positives, and unmatched ground-truth people are false negatives.
COCO reports AP over thresholds from 0.50 through 0.95, usually in steps of 0.05. The stricter thresholds reward precise joint placement.
Reading errors
A low AP at 0.50 but reasonable AP at lower thresholds suggests poor localization. A large drop from AP50 to AP75 indicates that predictions find the person but place joints inaccurately. Inspect the person area, visibility flags, keypoint order, and confidence ranking before changing the model.
Exercise
Why can a five-pixel error reduce OKS more for a small person than for a large person?
Show answer
OKS divides the error by the ground-truth person area, so the same error occupies a larger fraction of the small person's scale.