Sub topic 3
Single-Stage Pose Models
This chapter assumes you know basic Python and NumPy, understand convolutional networks, and know what a bounding box and a training loss are.
Single-stage pose models
A single-stage pose model finds every person and their keypoints in one forward pass. A top-down model first detects people, then runs a pose estimator on each crop. Single-stage models often run faster on crowded frames because their cost does not grow with the number of people.
Evaluating pose: OKS and keypoint AP
Object Keypoint Similarity (OKS) scores one predicted person against its ground truth. Each keypoint gets a Gaussian similarity based on its distance error, scaled by object area and a per-keypoint sigma. Keypoint AP averages precision over OKS thresholds from 0.50 to 0.95.
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):
d2 = ((gt - pred) ** 2).sum(axis=1)
var = (2 * SIGMAS) ** 2
e = d2 / (2 * var * (area + np.spacing(1)))
mask = visibility > 0
return float(np.exp(-e)[mask].mean()) if mask.any() else 0.0Running a pretrained pose model
from ultralytics import YOLO
model = YOLO("yolov8n-pose.pt")
result = model("person.jpg")[0]
if result.keypoints is not None and len(result.keypoints.xy) > 0:
xy = result.keypoints.xy[0].cpu().numpy() # (17, 2) pixel coordinates
conf = result.keypoints.conf[0].cpu().numpy() # (17,) confidence per keypoint
print(xy.shape, conf.shape)Using the output: joint angles and smoothing
In the COCO layout, the left shoulder is index 5, the left elbow is 7, and the left wrist is 9. The elbow angle is the angle at index 7 formed by indices 5, 7 and 9. Per-frame keypoints jitter, so smooth them across frames with a moving average:
import numpy as np
def smooth(track, window=5):
"""Moving average over frames. track: (T, 2) array for one keypoint. window must be odd."""
kernel = np.ones(window) / window
padded = np.pad(track, ((window // 2, window // 2), (0, 0)), mode="edge")
return np.stack([np.convolve(padded[:, i], kernel, mode="valid") for i in range(2)], axis=1)Failure modes and debugging
| Symptom | Likely cause | Check |
|---|---|---|
| Keypoints missing or wild | Occlusion | Inspect per-keypoint confidence |
| Skeletons jump between people | Crowding | Add a tracker or raise the detection threshold |
| Left and right limbs swapped | Symmetric body ambiguity | Plot the skeleton on the frame and verify indices |
Extension: lifting 2D poses to 3D
A 3D lifting model takes 2D keypoints and predicts a depth for each joint. Its errors include every 2D error, so improve the 2D output before you lift.
Exercise
Why does OKS divide by object area?
Show answer
Larger people span more pixels, so an equal pixel error matters less. Dividing by area makes the score independent of scale.