Sub topic 15
Failure Modes and Debugging
Assume you know Python and NumPy, understand image coordinates and bounding boxes, and have run a pretrained keypoint model. This chapter focuses on diagnosing bad predictions rather than improving the network architecture.
A debugging model
A pose prediction can fail at several stages:
Start by saving the input image, person boxes, keypoints, confidence values, and final application output. Inspect these separately. A wrong action label may come from a correct pose and a faulty angle calculation.
Occlusion and missing joints
Occlusion occurs when another object hides a body part. A model may place the hidden wrist near the visible elbow, predict a low-confidence location, or copy a plausible location from the other side of the body.
Use confidence as a warning signal, not as proof that a point is correct. Check whether the point lies inside the detected person box and whether its position is anatomically plausible. For a hidden joint, retaining the previous location for a short period can be better than treating a low-confidence prediction as a new movement.
Crowding and identity errors
In a crowded image, a top-down model can assign a crop to the wrong person if detections overlap. A bottom-up model can detect the joints but group a left wrist with a neighboring person's shoulder. These errors often appear as sudden, large jumps in one or more joints.
Compare each person's pose with the previous frame. A practical identity check uses box overlap, pose distance, or a tracker. Draw a different color for each person and include the person identifier in debugging output.
Left-right swaps
Left and right labels are defined from the person's perspective, not the viewer's. In a front-facing image, the person's left hand often appears on the right side of the image. Swaps become common when a person turns sideways, crosses their arms, or one side is hidden.
Test with an image where the person raises only one known hand. Confirm the model's label convention before writing rules such as “left elbow angle.” Never infer labels only from the x-coordinate.
Coordinate and decoding bugs
A heatmap coordinate must be mapped back to the correct image coordinate system. Common mistakes include using width as the y scale, forgetting crop offsets, mixing normalized coordinates with pixels, and using the wrong output stride.
For every prediction, verify these invariants:
- x is between 0 and image width.
- y is between 0 and image height.
- A known point moves consistently when the image is resized.
- A point decoded from a crop is translated by the crop's top-left offset.
A simple overlay is usually more useful than a numerical log. Draw the skeleton and keypoint names on the original image.
Temporal instability
Frame-by-frame predictions can jitter even when the person is still. An exponential moving average reduces this noise:
import numpy as np
def smooth_points(previous, current, alpha=0.7):
"""Return a smoothed (K, 2) array. alpha weights the current frame."""
previous = np.asarray(previous, dtype=float)
current = np.asarray(current, dtype=float)
if previous.shape != current.shape:
raise ValueError("point arrays must have the same shape")
return alpha * current + (1.0 - alpha) * previousA larger alpha follows motion quickly but smooths less. A smaller value is steadier but adds delay. Smooth only reliable points, or keep a visibility mask so missing joints do not pull the track toward an arbitrary coordinate.
A repeatable checklist
- Display the original image and detected boxes.
- Overlay keypoints before post-processing.
- Print keypoint names, coordinates, and confidences.
- Test one person before testing a crowd.
- Test clear, occluded, rotated, and low-light images.
- Compare predictions before and after resizing or cropping.
- Check the final rule separately from the model output.
Exercise
A wrist jumps across the image for one frame, while its confidence is low and the person's box is stable. What should you inspect first?
Show answer
Inspect the overlay, confidence threshold, and temporal tracking. The likely causes are an occluded or misdetected wrist and an identity or decoding error, not necessarily a change in pose.