Sub topic 1
What Object Detection Asks of a Model
Object detection answers two questions about an image:
- Which objects are present?
- Where is each object?
Image classification answers only the first question for the image as a whole. A classifier might label an image as bus. An object detector can find three buses, two cars, and several people, each with its own location and confidence.
Prerequisites
This chapter assumes that you know basic Python, understand images as arrays of pixels, and have seen neural networks, convolutional neural networks, and loss functions.
The detector's output
For every detected object, a model usually produces:
- A class, such as
person,car, orcat. - A bounding box, which is a rectangle around the object.
- A confidence score, which estimates how likely the detection is correct.
A detector can return zero, one, or many detections for one image. A useful mental model is a list of records:
| Class | Box | Confidence |
|---|---|---|
| bus | `(x1, y1, x2, y2)` | 0.94 |
| person | `(x1, y1, x2, y2)` | 0.81 |
The box coordinates describe the rectangle's left, top, right, and bottom edges. For an image with width W and height H, the top-left corner is near (0, 0) and the bottom-right corner is near (W, H).
detections = [
{
"class": "bus",
"box": (120, 80, 560, 410),
"confidence": 0.94,
},
{
"class": "person",
"box": (610, 150, 690, 390),
"confidence": 0.81,
},
]
for detection in detections:
print(
detection["class"],
detection["confidence"],
detection["box"],
)The model does not return a perfect fact. It returns predictions. A high score is evidence, not a guarantee. The application must decide which predictions to accept.
Classification, detection, and segmentation
These computer-vision tasks provide different amounts of location information:
- Classification assigns labels to the whole image.
- Object detection assigns a box and label to each object.
- Image segmentation assigns pixels to an object or class.
Detection is useful when approximate location is enough. For example, a warehouse system may need to know which shelf contains a package. It may not need the exact outline of the package.
How YOLO frames the task
YOLO, short for “You Only Look Once,” treats detection as one prediction problem over the complete image. A neural network processes the image in a forward pass and predicts candidate boxes, object confidence, and class information.
The phrase “single pass” describes the main model prediction step. The complete system still performs post-processing, such as filtering weak candidates and removing duplicate boxes. These steps are important because several candidate boxes may describe the same object.
In later steps, box overlap determines whether a predicted box matches a labeled object. This lets you measure not only whether the class is right, but also whether the location is accurate.
Exercise
What additional information does an object detector provide beyond an image classifier?
Show answer
It provides a separate bounding box and confidence score for each predicted object.