Object Detection
Detecting Objects in Images
Object Detection is a fundamental task in Computer Vision that goes beyond simple image classification. While classification merely states “there is a dog in the image”, detection states “there is a dog here and a cat there”, drawing bounding boxes.
⚙️ How it works: Practical Context
The task involves two simultaneous predictions:
- Regression: Predicting the coordinates of the bounding box (center x, center y, width, height).
- Classification: Predicting the class (label) of the object inside that box.
There are two major families:
- Two-Stage Detectors: (e.g., Faster R-CNN) Propose regions (RPN) and then classify/refine them using roi-pooling. Slower but highly accurate.
- One-Stage Detectors: (e.g., YOLO, SSD) Treat detection as a single regression problem on a grid. Extremely fast, but with slight difficulty regarding small and clustered objects.
🧮 Mathematical Foundation (Multi-task Loss Function)
Because the model needs to optimize two distinct things at the same time, the total loss function () is a linear combination of the classification loss () and the bounding box regression loss ():
Eq. 1: Multi-task Loss function.
Where:
- is the predicted probability distribution (calculated via Softmax).
- is the true object class ( means it’s an object, indicates background).
- is the predicted coordinate vector .
- is the true ground truth bounding box vector.
- is the balancing hyperparameter.
1. Classification Loss (Cross-Entropy)
Usually computed with standard logarithmic cross-entropy over classes (where is the background):
Eq. 2: Cross-entropy loss for classification.
Where:
- : classification loss for the object.
- : probability predicted by the model for the correct class .
2. Regression Loss (Smooth L1 / Huber Loss)
For localization, using Mean Squared Error () can cause gradients to explode on early outliers. Thus, we use the Smooth Loss, which is quadratic for small errors (smoothing convergence) and linear for large errors (outlier resistance):
Eq. 3: Smooth L1 regression loss for bounding box.
Where:
🎯 When to use
- Surveillance and tracking systems.
- Autonomous vehicles (detecting pedestrians, signs).
- Medical image analysis (identifying tumors in scans).
Related: roi-pooling · edge-detection-image-processing