Sub topic 4
Direct Coordinate Regression and Its Limits
This chapter assumes basic Python and NumPy, familiarity with convolutional neural networks, and a basic understanding of bounding boxes and training loss.
The basic idea
Direct coordinate regression makes a network predict the location of every keypoint directly. For a cropped person image, the output might contain 34 numbers for 17 COCO keypoints:
(x_1, y_1, x_2, y_2, \ldots, x_{17}, y_{17})The coordinates are often normalized to the range 0 to 1. A value of 0.5 for x means the point is halfway across the crop. At inference time, multiply normalized coordinates by the crop width and height to recover pixel positions.
A confidence value is not automatically provided by coordinate regression. A model can output coordinates, but estimating whether each coordinate is reliable requires an additional output, such as a visibility score or uncertainty value.
A typical model and loss
A common design uses a convolutional backbone followed by a global pooling layer and a fully connected layer. The final layer has 2K outputs for K keypoints.
The training target is the labelled coordinate vector. Mean squared error (MSE) penalizes the squared distance between predicted and labelled coordinates:
L = \frac{1}{2K}\sum_i(\hat{p_i}-p_i)^2Here, \(pi\) is a target coordinate and \(\hat{pi}\) is the prediction.
import numpy as np
def coordinate_mse(predicted, target):
"""Return mean squared error for arrays shaped (K, 2)."""
predicted = np.asarray(predicted, dtype=np.float32)
target = np.asarray(target, dtype=np.float32)
if predicted.shape != target.shape or predicted.ndim != 2:
raise ValueError("predicted and target must both have shape (K, 2)")
return float(np.mean((predicted - target) ** 2))
target = np.array([[0.25, 0.40], [0.70, 0.55]])
prediction = np.array([[0.30, 0.35], [0.65, 0.60]])
print(coordinate_mse(prediction, target))L1 loss or a smooth L1 loss can reduce the effect of unusually large errors. A visibility mask can also exclude keypoints that are not labelled or are too difficult to identify.
Strengths and limits
Coordinate regression is compact and simple. It produces a fixed-size output and can be fast for one person in a well-aligned crop. It is useful when another model already supplies a person bounding box.
However, the final coordinate does not show where the model searched. Two visually different poses can produce similar features after global pooling. The network must compress spatial evidence into a small vector, which can make precise localization difficult.
| Property | Direct coordinate regression | Heatmap prediction |
|---|---|---|
| Output | A coordinate pair per keypoint | A spatial map per keypoint |
| Localization evidence | Hidden in the vector | Visible across the map |
| Output size | Small | Larger |
| Typical use | Cropped, single-person input | Precise spatial localization |
Direct regression also assumes that the input contains one known person. Applying it to a full image with several people would require a separate output for an unknown number of people. It does not naturally solve detection, person assignment, or left-right identity.
Exercise
Why is direct coordinate regression usually paired with a person detector for multi-person images?
Show answer
It predicts a fixed set of keypoints for one input instance, so a detector must first find and separate each person.