Sub topic 2
Decoding heatmaps into coordinates and confidence
This chapter assumes you know NumPy arrays, convolutional networks, and bounding boxes. A heatmap is a 2D grid of scores, one grid per keypoint, where high values mark likely keypoint locations.
Decoding heatmaps
A heatmap model outputs one map per keypoint, with shape (K, H, W). The peak of map k gives the location of keypoint k, and the peak value gives its confidence. Decoding takes the arg-max of each map, then scales the grid position by the stride between the heatmap and the input image.
import numpy as np
def decode_heatmaps(heatmaps, stride):
k, h, w = heatmaps.shape
flat = heatmaps.reshape(k, -1)
idx = flat.argmax(axis=1)
scores = flat.max(axis=1)
ys, xs = np.divmod(idx, w)
coords = np.stack([xs, ys], axis=1).astype(np.float32) * stride
return coords, scores
if __name__ == "__main__":
maps = np.zeros((17, 64, 48), dtype=np.float32)
maps[0, 10, 20] = 0.9
coords, scores = decode_heatmaps(maps, stride=4)
print(coords[0], scores[0]) # [80. 40.] 0.9Backbones and high-resolution architectures
A backbone is the convolutional network that extracts features from the image. Classification backbones shrink the image by 32 times, which leaves a coarse heatmap. Pose backbones such as HRNet keep several resolution branches and exchange information between them, so the output heatmap stays fine enough to localize joints.
Training with Gaussian targets
Each labelled keypoint becomes a target map: a 2D Gaussian centred on the point, with a standard deviation of a few pixels. The loss is usually mean squared error between predicted and target maps. Invisible keypoints get no target. Augmentation such as rotation or scaling must transform the coordinates too. A horizontal flip must also swap left and right keypoint indices.
Top-down estimation
A top-down pipeline runs a person detector first. It crops each box, resizes the crop to the model input, estimates keypoints, and maps the coordinates back to the full image. Accuracy depends on the detector, and compute grows with the number of people.
Bottom-up estimation
A bottom-up pipeline detects every keypoint of every person in one pass. It then groups the keypoints into people using learned association fields or distances. Compute does not grow with the crowd, but grouping errors rise when people overlap.
Exercise
A heatmap has shape (17, 64, 48), the stride is 4, and the peak for keypoint 0 is at row 10, column 20. What are the image coordinates (x, y)?
Show answer
x = 20 × 4 = 80 and y = 10 × 4 = 40, so (80, 40).