Sub topic 15
Diagnosing Poor Detections
This chapter assumes you understand Python, bounding boxes, IoU, neural-network training, and the basic YOLO inference workflow. The goal is to find whether poor predictions come from the data, the model, post-processing, or the deployment environment.
Start with the failure pattern
Do not begin by changing random hyperparameters. Collect examples of:
- False positives: the model detects an object that is not present.
- False negatives: an object is present but not detected.
- Localization errors: the class is correct, but the box is too large, too small, or shifted.
- Duplicate detections: several boxes describe the same object.
- Class confusion: the model detects an object but chooses the wrong class.
Compare these errors with image size, object size, lighting, camera angle, and class. A failure that affects only small objects needs a different fix from a failure that affects one label class.
Use metrics to narrow the cause
Precision measures how many reported detections are correct:
precision = true positives / (true positives + false positives)
Recall measures how many real objects the model finds:
recall = true positives / (true positives + false negatives)
A low precision suggests excessive false positives. A low recall suggests missed objects or an overly strict confidence threshold. Mean average precision, or mAP, combines ranking quality and localization quality, but it can hide problems in a rare class. Always inspect per-class metrics and a confusion matrix.
| Symptom | Likely causes | Useful check |
|---|---|---|
| Many missed objects | Small objects, poor labels, high confidence threshold | Lower `conf`; inspect image resolution and labels |
| Many false positives | Background confusion, incomplete labels, low threshold | Review false-positive images and negative examples |
| Boxes are shifted | Incorrect coordinates, loose labels, insufficient training | Draw labels and predictions together |
| One class is weak | Few examples or class ambiguity | Count labels per class and inspect its AP |
| Duplicate boxes remain | NMS IoU threshold is too high | Lower the NMS IoU threshold |
Check the data before the model
A detector cannot learn from incorrect supervision. Verify that every image has a matching label file and that each label uses:
class_id x_center y_center width height
YOLO coordinates are normalized to the range 0 to 1. A box that uses pixel coordinates, reversed corners, or the wrong class index can make training appear to work while producing poor predictions.
Also check for:
- Missing objects in label files.
- Boxes that extend outside the image.
- Inconsistent class names between training and validation.
- Validation images that differ sharply from training images.
- Too few examples of important classes.
- Augmentations that create unrealistic images.
Plot several labeled training images. This catches coordinate and class errors faster than reading training logs.
Tune inference after validation
The confidence threshold controls which candidate detections are reported. Lowering it usually increases recall and decreases precision. The NMS IoU threshold controls how much overlap is allowed between retained boxes. A high NMS threshold keeps more overlapping boxes; a low threshold removes them more aggressively.
detections = [
{"score": 0.91, "is_correct": True},
{"score": 0.63, "is_correct": False},
{"score": 0.48, "is_correct": True},
{"score": 0.22, "is_correct": True},
]
for threshold in (0.2, 0.4, 0.6, 0.8):
selected = [d for d in detections if d["score"] >= threshold]
correct = sum(d["is_correct"] for d in selected)
precision = correct / len(selected) if selected else 0.0
print(threshold, len(selected), round(precision, 2))Tune thresholds on a validation set, then verify them on a separate test set. Do not tune on production images alone.
Exercise
Exercise
Predictions have high precision but low recall. Name two changes to investigate first.
Show answer
Lower the confidence threshold and inspect whether small objects, missing labels, low image resolution, or an unrepresentative training set cause the missed detections.