Sub topic 10
Bottom-up estimation and keypoint grouping
This chapter assumes you know how heatmaps are decoded into coordinates, how the top-down pipeline works, and basic NumPy. Top-down estimation detects each person first and then runs a pose model on each crop. Bottom-up estimation reverses the order: it finds every keypoint in the image first and then decides which keypoints belong to the same person. The second step is called grouping, and most of the design effort in bottom-up methods goes into it.
The core idea
A bottom-up network runs once on the whole image. It produces two kinds of output:
- Keypoint heatmaps. One map per joint type (17 for COCO), covering every person at once. A map for "left wrist" has one peak per visible left wrist.
- Association signals. Extra outputs that say which detected joints go together.
Peak detection on the heatmaps gives a set of candidates for each joint type. Candidates are unlabelled by person. If the image shows five people, the left-wrist map yields up to five candidates, and the grouping step assigns each one to a person.
Why choose bottom-up
The main benefit is that inference cost barely depends on how many people appear. The network runs once, and grouping is cheap compared with the network. A top-down method runs the pose model once per detected person, so a crowded scene costs much more.
| Property | Top-down | Bottom-up |
|---|---|---|
| Network passes per image | 1 detector + N pose passes | 1 |
| Cost in crowds | Grows with N | Almost flat |
| Dependence on person detector | Total | None |
| Small or distant people | Good (each is cropped and resized) | Weaker (fixed input scale) |
| Typical accuracy on COCO | Higher | Lower, though the gap has narrowed |
| Main error source | Detector misses and bad crops | Wrong grouping |
Scale is the main weakness. A top-down crop normalises every person to the same size. A bottom-up model must handle a person 40 pixels tall and one 600 pixels tall in the same image. Methods address this with multi-scale inference or high-resolution backbones such as HigherHRNet, which adds a higher-resolution output branch for small people.
How the pipeline fits together
Two ways to encode association
Part Affinity Fields
OpenPose uses Part Affinity Fields (PAFs). A PAF is a pair of maps (an x map and a y map) for each limb, such as left shoulder to left elbow. At pixels lying on that limb, the vector stored in the map points along the limb from the first joint to the second. Elsewhere it is zero.
To test whether candidate A (a shoulder) and candidate B (an elbow) belong together, you sample points along the segment from A to B. At each point you take the dot product of the PAF vector with the unit direction from A to B. The mean of those values is the line integral score. It is near 1 when the field agrees with the segment, and near 0 when the segment crosses empty space or runs against the field.
Associative embeddings
Newell et al. take a different route. For each joint type, the network also predicts a tag, a scalar or short vector for every pixel. Training pushes tags of joints from the same person close together and tags from different people apart. At inference, you read the tag at each detected peak and cluster by tag value. Two wrists with similar tags go to the same person.
Embeddings need no limb-specific geometry, so they scale to any skeleton. They can struggle when two people overlap heavily, because their tags may drift close together. PAFs encode geometry directly, but they depend on the limb being roughly straight and visible between its endpoints.
Grouping with PAFs in code
The functions below implement the line integral score and a greedy matcher for one limb type. The demo builds a synthetic field with two horizontal forearms and checks that the correct elbow-wrist pairs are chosen over the crossing pairs.
import numpy as np
def paf_score(paf_x, paf_y, p1, p2, n_samples=10):
"""Mean agreement between the PAF and the segment p1 -> p2. Points are (x, y)."""
p1 = np.asarray(p1, dtype=float)
p2 = np.asarray(p2, dtype=float)
d = p2 - p1
norm = np.linalg.norm(d)
if norm < 1e-6:
return 0.0
u = d / norm
ts = np.linspace(0.0, 1.0, n_samples)
pts = p1[None, :] + ts[:, None] * d[None, :]
xs = np.clip(np.rint(pts[:, 0]).astype(int), 0, paf_x.shape[1] - 1)
ys = np.clip(np.rint(pts[:, 1]).astype(int), 0, paf_x.shape[0] - 1)
return float((paf_x[ys, xs] * u[0] + paf_y[ys, xs] * u[1]).mean())
def match_limb(cands_a, cands_b, paf_x, paf_y, threshold=0.5):
"""Greedy one-to-one matching of candidates, best score first."""
pairs = []
for i, a in enumerate(cands_a):
for j, b in enumerate(cands_b):
pairs.append((paf_score(paf_x, paf_y, a, b), i, j))
pairs.sort(reverse=True)
used_a, used_b, links = set(), set(), []
for score, i, j in pairs:
if score < threshold:
break
if i in used_a or j in used_b:
continue
used_a.add(i)
used_b.add(j)
links.append((i, j, round(score, 2)))
return links
def draw_limb(paf_x, paf_y, p1, p2, width=2):
"""Write the unit vector p1 -> p2 into a band of pixels around the segment."""
p1 = np.asarray(p1, dtype=float)
p2 = np.asarray(p2, dtype=float)
u = (p2 - p1) / np.linalg.norm(p2 - p1)
for t in np.linspace(0.0, 1.0, 200):
x, y = np.rint(p1 + t * (p2 - p1)).astype(int)
paf_x[y - width:y + width + 1, x - width:x + width + 1] = u[0]
paf_y[y - width:y + width + 1, x - width:x + width + 1] = u[1]
paf_x = np.zeros((64, 64))
paf_y = np.zeros((64, 64))
elbows = [(10, 10), (10, 40)]
wrists = [(30, 10), (30, 40)]
for e, w in zip(elbows, wrists):
draw_limb(paf_x, paf_y, e, w)
print(match_limb(elbows, wrists, paf_x, paf_y))The output is [(0, 0, 1.0), (1, 1, 1.0)]. The crossing pairs score about 0.1, because only their endpoints touch the field, so they fall below the threshold.
A full system repeats this for every limb in a skeleton tree. It then links the matches into people. Two limbs that share a joint candidate, such as shoulder-elbow and elbow-wrist, merge into one skeleton.
Failure modes specific to grouping
- Merged people. Two people standing close together can end up with a limb joined across them, producing one skeleton with two left arms. Limits such as "one candidate per person per joint type" prevent the worst cases.
- Split people. A missing candidate in the middle of a chain breaks the skeleton in two. Many systems add redundant limbs (for example shoulder to wrist directly) to bridge gaps.
- Greedy errors. Matching best-first is fast but not globally optimal. Hungarian matching is optimal for one limb type, though the gain over greedy is often small in practice.
- Long limbs. Sampling a few points along a long limb can miss a short stretch where the field is weak or wrong. Increasing
n_samplescosts little. - False peaks. A texture that looks like a wrist adds a candidate with no real person. Its low association scores usually leave it ungrouped, so check for orphan candidates when debugging.
Choosing between the two
Use bottom-up when you expect crowded scenes, need a predictable latency, or cannot rely on a person detector. Use top-down when you want the highest accuracy and your scenes have a modest, bounded number of people. For many production uses, a single-stage model gives most of the speed of bottom-up with fewer post-processing rules.
Exercise
In the demo above, suppose you lower the threshold in match_limb from 0.5 to 0.05. The crossing pairs score about 0.1. What happens to the output, and why does it stay one-to-one?
Show answer
The sorted list begins with the two correct pairs, both with score 1.0. They are accepted first, so elbow 0 and wrist 0 are marked used, and likewise elbow 1 and wrist 1. The crossing pairs (score about 0.1) now pass the lower threshold, but each one involves a candidate already in useda or usedb, so the loop skips it. The output is unchanged. The used sets enforce the one-to-one rule. A low threshold becomes harmful only when a candidate is left unmatched. In that case a weak, wrong link can then be accepted for it.
Exercise
A bottom-up model works well on a street scene with many pedestrians but often attaches a small child's wrist to the adult standing next to them. Name two likely causes and one mitigation for each.
Show answer
Cause 1: scale. The child is small, so the heatmap peaks and association signals are low resolution and noisy. Mitigation: multi-scale inference or a higher-resolution output such as HigherHRNet. Cause 2: proximity and overlap. The child's wrist lies near the adult's arm, so a PAF line integral or tag distance can score the wrong pair highly. Mitigation: add redundant limbs and enforce one candidate per person per joint type, or use embeddings with a larger separation margin during training.