Sub topic 11
Single-stage pose models
This chapter covers models that predict people and their keypoints in one forward pass. It assumes you know how top-down and bottom-up pipelines work from the previous two chapters, and that you understand anchor-based or anchor-free object detection, non-maximum suppression (NMS), and the COCO 17-keypoint layout.
Why a third family exists
A top-down pipeline runs a detector, then runs a pose network once per crop. Its cost grows with the number of people, and the two stages are trained separately. A bottom-up pipeline runs once per image but needs a grouping step, which is often slow and heuristic.
A single-stage model removes both problems. It extends an object detector so that each detection also carries its keypoints. One network pass gives you boxes, confidences and all 17 keypoints for every person, and the only post-processing is NMS.
The idea has two main lineages:
- Detector extensions. Examples are YOLO-Pose, YOLOv8-pose and RTMO. A detection head gets extra output channels for keypoints.
- Point-based methods. Examples are CenterNet-style models and PETR. The model predicts a person center or a set of queries, then regresses the keypoint offsets from it.
This chapter focuses on the first lineage because it is the one you are most likely to deploy.
How the head works
In a YOLO-style pose model, the backbone and neck produce feature maps at several strides, typically 8, 16 and 32. Each location on each map is a candidate person. The head predicts, for that location:
- A box: center, width and height.
- A person score.
- 17 keypoints, each with x, y and a confidence or visibility value.
For YOLOv8-pose that is 4 + 1 + 17 × 3 = 56 numbers per candidate. At a 640 × 640 input there are 8400 candidates, so the raw output has shape (56, 8400).
Keypoints are offsets, not heatmaps
Single-stage models usually do not predict heatmaps. They regress keypoint positions directly, as offsets from the candidate's anchor point, scaled by the stride. This brings back the regression problem from the coordinate regression chapter, where the network must map features to precise positions without a spatial map to guide it.
Two things make it workable here:
- The keypoint is predicted relative to a nearby anchor, so the offset is small and the target is easier to learn.
- The loss is tuned for keypoints. YOLO-Pose uses an OKS-based loss, which is 1 minus the OKS between prediction and ground truth. This trains on the metric you evaluate with. Because OKS divides by object scale and per-keypoint sigmas, large and small people contribute fairly.
A separate binary cross-entropy loss trains the per-keypoint visibility or confidence, using the COCO visibility flags from the annotations chapter.
Decoding raw output yourself
Libraries hide this step, but you should know what they do. The sketch below assumes keypoint coordinates are already in input pixels, which is the case for exported YOLOv8-pose models. Check your model's export format, because some heads output raw offsets that must be decoded against the anchor grid.
import numpy as np
def split_predictions(raw, score_thr=0.25):
"""raw: (56, N). Rows: cx, cy, w, h, person score, then 17 x (x, y, conf)."""
preds = raw.T
preds = preds[preds[:, 4] >= score_thr]
center, size = preds[:, :2], preds[:, 2:4]
boxes = np.concatenate([center - size / 2, center + size / 2], axis=1)
kpts = preds[:, 5:].reshape(-1, 17, 3)
return boxes, preds[:, 4], kpts
def nms(boxes, scores, iou_thr=0.7):
order = scores.argsort()[::-1]
keep = []
while order.size:
i = order[0]
keep.append(int(i))
rest = order[1:]
lt = np.maximum(boxes[i, :2], boxes[rest, :2])
rb = np.minimum(boxes[i, 2:], boxes[rest, 2:])
inter = np.clip(rb - lt, 0, None).prod(axis=1)
area_i = (boxes[i, 2:] - boxes[i, :2]).prod()
area_r = (boxes[rest, 2:] - boxes[rest, :2]).prod(axis=1)
iou = inter / (area_i + area_r - inter + 1e-9)
order = rest[iou <= iou_thr]
return keep
if __name__ == "__main__":
rng = np.random.default_rng(0)
raw = np.zeros((56, 3), dtype=np.float32)
raw[:5, 0] = [100, 100, 50, 120, 0.90] # person A
raw[:5, 1] = [102, 101, 50, 120, 0.80] # duplicate of A
raw[:5, 2] = [300, 150, 60, 140, 0.70] # person B
raw[5:, :] = rng.uniform(0, 1, (51, 3))
boxes, scores, kpts = split_predictions(raw)
keep = nms(boxes, scores)
print(len(keep), kpts[keep].shape) # 2 (2, 17, 3)Because NMS works on boxes, it can suppress a true person whose box overlaps a stronger neighbor. This is the main crowding failure of the family. Some pose models use pose-aware NMS, which compares OKS between candidates instead of box IoU.
Running a pretrained model
The Ultralytics package wraps all of the steps above, including NMS, and returns per-person keypoints.
from ultralytics import YOLO
model = YOLO("yolov8n-pose.pt")
results = model("person.jpg")
kp = results[0].keypoints
if kp is not None and len(kp.xy) > 0:
xy = kp.xy[0].cpu().numpy() # (17, 2) pixel coordinates of the first person
conf = kp.conf[0].cpu().numpy() # (17,) per-keypoint confidence
print(xy.shape, conf.shape)kp.xy has shape (num_people, 17, 2). Points the model considers absent often come back as (0, 0) with low confidence, so filter on conf before using a point. Do not treat (0, 0) as a real location.
Trade-offs against the other families
| Property | Top-down | Bottom-up | Single-stage |
|---|---|---|---|
| Passes through a network | 1 detector + N crops | 1 | 1 |
| Cost with crowd size | Grows linearly | Nearly flat, plus grouping | Nearly flat |
| Grouping step | None, the crop defines the person | Needed, often heuristic | None, the candidate defines the person |
| Keypoint precision | Highest, heatmaps at crop resolution | Medium | Lower for small keypoints |
| Failure under crowding | Detector misses or merges boxes | Wrong joint assignment | NMS removes true people |
| Typical use | Accuracy-first, offline | Dense scenes | Real-time, edge devices |
Single-stage models give up some precision on fine joints such as wrists and ankles. Top-down models crop and resize each person, so every person gets full network resolution, while a single-stage model gives a small person in a large frame only a few feature-map cells. If you need high accuracy and have a time budget, top-down is still the better choice. If you need 30 frames per second on modest hardware, single-stage usually wins.
Failure modes specific to this family
- Duplicate poses. A NMS threshold that is too high leaves two poses for one person. A threshold that is too low removes people standing close together. Tune it on your own data.
- Small people. Few features cover them, so keypoints scatter. Raise the input size, or tile the image.
- Box and keypoints disagree. The box can be correct while limbs are off. The keypoint confidence is a separate output, so use it, and do not rely on the person score alone.
- Left-right swaps. These behave as in other families. Horizontal flip augmentation must also swap the left and right keypoint indices, or the model learns the swap as a label.
- Scale mismatch. Models trained with mosaic augmentation at one scale can degrade on very different image sizes. Evaluate at the resolution you will deploy.
Choosing a model
- Start with a single-stage model if latency or deployment cost is the constraint, and measure keypoint AP on a sample of your own footage.
- If wrists or ankles are too noisy, try a larger input size before changing the family.
- If crowds cause missed people, try lowering the NMS IoU threshold or switching to pose-aware NMS.
- If accuracy is still short, move to a top-down pipeline and accept the per-person cost.
Exercise
A single-stage pose model returns 8400 candidate vectors of 56 numbers each for a 640 x 640 image. (a) What do the 56 numbers contain? (b) You run it on a photo of two people hugging, and it returns only one pose. Name the most likely cause and one fix.
Show answer
(a) 4 box values (center x, center y, width, height), 1 person score, and 17 keypoints with x, y and confidence each, which is 4 + 1 + 51 = 56. (b) Box-based NMS probably suppressed the weaker person because the two boxes overlap heavily. Fixes include lowering the NMS IoU threshold's suppression strength (raising the IoU threshold so fewer boxes are removed), using pose-aware NMS based on OKS, or switching to a top-down pipeline whose detector handles overlap with a separate pose pass per crop.
Exercise
Why is an OKS-based loss a better fit for single-stage keypoint regression than a plain L1 loss on pixel coordinates?
Show answer
OKS normalizes the error by the person's scale and by a per-keypoint sigma, so small and large people contribute comparably and hard joints such as hips are penalized less sharply than easy ones such as eyes. The loss also matches the evaluation metric, so training optimizes what the keypoint AP measures. A plain pixel L1 loss lets large people dominate the gradient.