Sub topic 1
What an Object Detector Must Output
An object detector takes an image and returns a collection of detected objects. Each detection describes what was found, where it appears, and how confident the model is.
This chapter assumes that you understand image tensors, convolutional neural networks, classification, and regression. You should also be comfortable with basic Python and NumPy.
Prerequisites
You should know:
- An image can be represented as a height-by-width-by-channel array.
- A feature map is an intermediate tensor produced by a neural network.
- Classification predicts a class label.
- Regression predicts continuous values.
- A model is trained by minimizing a loss function with gradient descent.
The Detection Output
For each detected object, a typical detector returns:
- A bounding box, which is a rectangle around the object.
- A class label, such as
cat,car, orperson. - A confidence score, which estimates how likely the detection is correct.
A bounding box is often stored as four numbers. In the corner format, these numbers are (x1, y1, x2, y2):
(x1, y1)is the top-left corner.(x2, y2)is the bottom-right corner.xincreases from left to right.yincreases from top to bottom.
For an image with width 640 and height 480, a detection might look like this:
| Box | Class | Confidence |
|---|---|---|
| `(120, 80, 310, 420)` | `person` | `0.96` |
| `(400, 210, 570, 360)` | `dog` | `0.88` |
The detector does not usually return exactly one box. An image can contain many objects, and the number of objects changes from image to image. Therefore, the output is a variable-length set or list of detections.
detections = [
{
"box": (120, 80, 310, 420),
"class_id": 0,
"class_name": "person",
"confidence": 0.96,
},
{
"box": (400, 210, 570, 360),
"class_id": 1,
"class_name": "dog",
"confidence": 0.88,
},
]
for detection in detections:
x1, y1, x2, y2 = detection["box"]
print(
f"{detection['class_name']}: "
f"score={detection['confidence']:.2f}, "
f"box=({x1}, {y1}, {x2}, {y2})"
)From Pixels to a Set of Objects
A detector commonly follows this abstract process:
The network first extracts visual features. Prediction layers then estimate box coordinates and class scores. The raw predictions often contain duplicate boxes or very low-confidence candidates. Later stages filter these predictions to produce the final output.
A detector differs from an image classifier in an important way. A classifier might answer, “There is a dog in this image.” A detector answers, “There is a dog in this region, and a person in that other region.” Detection therefore combines classification with localization.
Confidence Is Not Correctness
A confidence score is a model output, not a guarantee. A detector can assign a high score to an incorrect box, especially when objects are partially hidden, unusually shaped, or absent from the training data.
At inference time, a threshold is often applied:
- Keep detections with scores above the threshold.
- Discard detections below it.
- Use later processing to remove duplicate boxes.
A higher threshold usually produces fewer false positives but can miss real objects. A lower threshold keeps more possible objects but also retains more incorrect predictions.
Exercise
Exercise
For an image containing two cars and one person, what information should each final detection contain, and why is a classifier-only output insufficient?
Show answer
Each detection should contain a bounding box, a class label, and a confidence score. A classifier-only output may identify classes present in the image, but it does not identify the location of each object or distinguish multiple objects of the same class.