Sub topic 5
Reading a Detector's Output: Boxes, Scores and Classes
Assume you know Python, image arrays, bounding-box formats, and the basic idea of a neural network. This chapter focuses on how to interpret what a YOLO-style detector returns after one forward pass.
What one prediction contains
An object detector returns several candidate detections. Each candidate describes:
- A box, which locates an object in the image.
- A class, such as
person,car, ordog. - One or more scores, which express how strongly the model supports that prediction.
A box is often represented as (x1, y1, x2, y2), where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner. Pixel coordinates usually start at (0, 0) in the image's top-left corner.
A detector's internal prediction may instead use (x_center, y_center, width, height). The model or framework decodes this into corner coordinates before returning the result.
| Output | Meaning | Typical example |
|---|---|---|
| Box | Object location | `[52, 80, 210, 360]` pixels |
| Class ID | Position in the class-name list | `0` |
| Class name | Human-readable category | `person` |
| Confidence | Score for the final detection | `0.91` |
Objectness and class scores
Many YOLO designs produce an objectness score. It estimates whether a candidate box contains any object at all. The model also produces a class score, which estimates the class conditional on an object being present.
A simplified final score is:
confidence(class) = objectness × class_score(class)For example, objectness 0.8 and a car score of 0.9 produce a class confidence of 0.72.
The exact output layout depends on the YOLO version and implementation. Some newer frameworks expose only a final confidence value in their high-level result object. Do not assume that the returned conf value is a separate raw objectness score.
Decoding a candidate
The following example converts a center-format prediction into a corner-format box and selects its highest-scoring class.
def decode_candidate(x_center, y_center, width, height,
objectness, class_scores, class_names):
x1 = x_center - width / 2
y1 = y_center - height / 2
x2 = x_center + width / 2
y2 = y_center + height / 2
class_id = max(range(len(class_scores)),
key=lambda i: class_scores[i])
confidence = objectness * class_scores[class_id]
return {
"box": [x1, y1, x2, y2],
"class_id": class_id,
"class_name": class_names[class_id],
"confidence": confidence,
}
names = ["person", "car", "dog"]
prediction = decode_candidate(
100, 120, 80, 160,
0.90, [0.05, 0.80, 0.10], names
)
print(prediction)This produces a box from (60, 40) to (140, 200). The predicted class is car, with confidence 0.72.
The output pipeline
A practical inference pipeline usually performs these steps:
Low-confidence filtering removes candidates that are unlikely to be useful. Non-maximum suppression then removes duplicate boxes around the same object.
Common interpretation errors
- Treating normalized coordinates as pixels. Coordinates in the range
0to1must be scaled by image width and height. - Reading the class ID as a label. Look it up in the model's names.
- Comparing raw scores from different models. Score calibration can differ between models.
- Assuming confidence alone measures localization quality. A high score does not guarantee a well-positioned box.
Exercise
A prediction has objectness 0.75 and class scores [0.2, 0.6, 0.1]. What class and confidence does it represent?
Show answer
It represents class 1 with confidence 0.75 × 0.6 = 0.45. The class name comes from the model's class-name list.