Object Detection: R-CNN to YOLO
Identifying what objects are in an image and predicting their exact 2D bounding box locations.
What is Object Detection?
While Image Classification assigns a single label to an entire image ("Dog"), Object Detection predicts category labels AND bounding boxes for multiple objects in the image:
IMAGE CLASSIFICATION OBJECT DETECTION
Input: Image ──► Output: "Dog" Input: Image ──► Output:
- Dog: [x=120, y=80, w=200, h=150]
- Cat: [x=350, y=40, w=100, h=90]
Bounding Box Parameterization
A predicted bounding box $b$ is represented as a 4-dimensional vector:
b = [ x_center, y_center, width, height ]
Coordinates are normalized relative to image dimensions ($[0, 1]$ interval).
The Object Detection System Pipeline
Input Image ──► [ Backbone (ResNet) ] ──► [ Feature Pyramid Network (FPN) ] ──► [ Detection Head ]
├── Class Scores
├── Bounding Boxes
└── Objectness Score
- Backbone: Pre-trained CNN (ResNet, DarkNet) or Vision Transformer extracting deep feature maps.
- Neck (Feature Pyramid Network - FPN): Combines multi-scale feature maps so small objects are detected on high-resolution layers, while large objects are detected on deep semantic layers.
- Head: Predicts classification probabilities, bounding box regression offsets, and objectness presence scores.
Bounding Box Loss Functions
Early detectors used Smooth $L_1$ loss independently on $x, y, w, h$.
Modern detectors use IoU-based losses that treat the 4 coordinates as a unified 2D box:
- GIoU (Generalized IoU): Adds a penalty for the area of the smallest enclosing box covering both prediction and ground truth, resolving zero-gradient issues when boxes do not overlap.
- DIoU (Distance IoU): Penalizes center point distance $|b - b^{\text{gt}}|_2^2$ to accelerate box alignment.
- CIoU (Complete IoU): Considers overlap area, center point distance, AND aspect ratio consistency.
Say this out loud
Object detection predicts both object category labels and 4D bounding box coordinates [x, y, w, h]. Architectures combine a Backbone for feature extraction, a Feature Pyramid Network (FPN) to merge multi-scale feature maps for detecting small and large objects, and a Detection Head optimizing multi-task loss (Focal Loss for classification + CIoU Loss for bounding box regression).
Follow-ups to expect
- What is Objectness Score? A probability confidence score [0, 1] predicting whether a candidate grid cell / anchor box contains ANY foreground object, filtering out background noise.
- What is Focal Loss? A modified cross-entropy loss $FL(p_t) = -\alpha_t (1 - p_t)^\gamma \log(p_t)$ that down-weights easy background samples, solving extreme class imbalance in dense object detection.
Check yourself
What are the four bounding box coordinate outputs predicted by an object detection model?