Skip to content

Latest commit

 

History

History
249 lines (171 loc) · 15.7 KB

File metadata and controls

249 lines (171 loc) · 15.7 KB

Comparison between the two major object detection paradigms: Two-Stage Detectors (like R-CNN, Fast R-CNN, Faster R-CNN, Mask R-CNN) and One-Stage Detectors (like YOLO, SSD, RetinaNet, FCOS, CenterNet).


Two-Stage vs One-Stage Object Detectors


1. Conceptual Overview

Aspect Two-Stage Detectors One-Stage Detectors
Core Idea Detection happens in two steps: (1) generate region proposals (potential object regions), (2) classify and refine boxes. Detection happens in one step: directly predict object classes and bounding boxes from dense feature maps without separate proposal generation.
Philosophy “Propose first, then classify.” “Detect everything directly.”
Examples R-CNN, Fast R-CNN, Faster R-CNN, Mask R-CNN, Cascade R-CNN YOLO (all versions), SSD, RetinaNet, CenterNet, FCOS, EfficientDet

2. Architectural Workflow

Two-Stage Detectors

Stage 1: Region Proposal Generation

  • Propose candidate regions likely to contain objects.
  • Early methods used Selective Search (R-CNN), later replaced by Region Proposal Network (RPN) (Faster R-CNN).
  • RPN slides small windows (anchors) over feature maps to predict objectness scores and bounding box proposals.

Stage 2: Classification and Refinement

  • Extract region features using RoI Pooling / RoI Align.
  • Feed them into a fully connected classification head to predict class scores and refine box coordinates.
  • Optionally, segmentation masks (Mask R-CNN) or keypoints (Keypoint R-CNN) can be added.

One-Stage Detectors

  • Skip proposal stage completely.

  • Treat detection as a dense prediction problem — each spatial location in a feature map predicts multiple boxes and classes.

  • Uses anchor boxes (SSD, RetinaNet) or is anchor-free (FCOS, CenterNet).

  • Predict directly on multiple scales via FPN (Feature Pyramid Networks).

  • Common backbone + neck + head architecture:

    • Backbone: e.g., ResNet, CSPDarknet.
    • Neck: FPN, PANet.
    • Head: parallel branches for class probabilities and bounding box regression.

3. Computational Pipeline Comparison

Step Two-Stage One-Stage
Feature extraction Shared CNN backbone (e.g., ResNet) Same backbone
Proposal generation Region Proposal Network or Selective Search No proposal generation
RoI feature extraction Required (RoI Pooling / Align) Not needed
Classification Done per RoI Done per grid cell / pixel
Bounding box regression Per RoI Per grid / anchor point
Post-processing Non-Maximum Suppression (NMS) Same (NMS / Soft-NMS)

4. Training Dynamics

Aspect Two-Stage One-Stage
Supervision Two-step training (sometimes separate losses for RPN and classifier) Single loss combining classification and localization
Class imbalance Less severe (RPN reduces background regions) Severe (most anchors are background) → Focal Loss introduced
Anchor matching Anchors matched in RPN and again in detection head Anchors matched in a single pass
End-to-End Training Initially not (R-CNN, Fast R-CNN) but later possible (Faster R-CNN) Always end-to-end
Gradient flow More complex (RPN + Head) Simple and unified

5. Accuracy and Performance

Criterion Two-Stage Detectors One-Stage Detectors
Accuracy (mAP) Typically higher accuracy, especially on small and complex objects due to refined RoIs. Slightly lower accuracy but improving rapidly with modern designs (YOLOv7, RetinaNet).
Speed (FPS) Slower because of sequential proposal and classification steps. Much faster; designed for real-time performance (YOLO, SSD).
Localization precision High — refined box regression after proposals. Moderate — direct regression without proposal refinement.
Detection of small objects Better — multi-scale RoIs and high-res feature fusion. Challenging — downsampling reduces small-object sensitivity (unless FPN is used).
Compute cost Heavier; multiple forward passes for proposals. Lighter; single forward pass.

Example comparison (COCO, approximate):

Model mAP@[.5:.95] FPS
Faster R-CNN (ResNet-50) 38 ~10
RetinaNet (ResNet-50) 37 ~25
YOLOv5-L 50+ 40–60

6. Complexity and Implementation

Aspect Two-Stage One-Stage
Implementation complexity High – multiple sub-networks (RPN + ROI classifier) Lower – single pipeline
Memory requirement High (stores RoIs and per-region features) Lower (dense feature maps only)
Inference pipeline Multi-step (proposal → classification → NMS) Simple (direct prediction → NMS)
Hardware usage Requires more GPU memory and time Lighter, suitable for edge devices

7. Loss Functions

Two-Stage

  • RPN loss: Binary cross-entropy (objectness) + Smooth L1 (bbox regression).
  • Detection head loss: Multi-class cross-entropy + Smooth L1.
  • Combined multi-task loss for both stages.

One-Stage

  • Unified loss combining classification and localization: [ L = L_{cls} + \lambda L_{loc} ]
  • Often uses Focal Loss to handle background–foreground imbalance.
  • IoU-based losses (GIoU, DIoU, CIoU) common for better localization.

8. Handling Class Imbalance

  • Two-Stage: RPN filters out most negative anchors before second stage, reducing imbalance naturally.
  • One-Stage: Predicts directly over dense grids → 99% background. Focal Loss (RetinaNet) solved this by down-weighting easy negatives.

9. Real-World Applications

Domain Two-Stage One-Stage
Autonomous driving (real-time) Usually not used (too slow) YOLO, SSD, CenterNet widely used
Medical imaging (accuracy critical) Faster/Mask R-CNN popular Used for coarse detection (e.g., YOLO for faster scanning)
Video surveillance Real-time → one-stage preferred Offline analysis → two-stage
Instance segmentation Mask R-CNN One-stage rarely used
Aerial imagery (small objects) Two-stage better handles small details New one-stage with FPN narrowing the gap

10. Feature Pyramid and Multi-Scale Handling

  • Two-Stage: FPN is a standard backbone extension to handle multi-scale features; proposals are generated from pyramid levels P2–P6.
  • One-Stage: FPN is also integrated (e.g., SSD, YOLOv3+, RetinaNet). Predictions made from multiple scales simultaneously.

Both have adapted FPN, but one-stage must rely on it more heavily because no RoI refinement exists.


11. Anchors and Representation

Aspect Two-Stage One-Stage
Anchor-based Yes (RPN uses anchors) Yes (SSD, RetinaNet) and No (anchor-free variants like FCOS, CenterNet)
Anchor-free options Few (later versions like RepPoints) Common in modern models (FCOS, YOLOv8)

Anchor-free designs reduce hyperparameters and simplify training in one-stage models.


12. Modern Hybrids and the Blurred Boundary

Recent architectures blur the line:

  • Deformable DETR: Transformer-based end-to-end detection removes need for NMS.
  • Cascade R-CNN: Multi-stage refinement improves precision but adds cost.
  • YOLOv8 / RT-DETR: End-to-end, anchor-free, transformer-based, combining one-stage speed and two-stage accuracy.
  • DETR (Facebook AI): Fully end-to-end detection using attention, conceptually neither one-stage nor two-stage, but closer to one-stage inference.

The distinction between two- and one-stage detectors is less rigid today — it’s now about speed–accuracy trade-off and architectural design philosophy.


13. Practical Summary Table

Factor Two-Stage (Faster/Mask R-CNN) One-Stage (YOLO/SSD/RetinaNet)
Architecture Proposal-based (RPN + classifier) End-to-end (no proposals)
Speed Slower (10–15 FPS typical) Real-time possible (30–200 FPS)
Accuracy High (better mAP, especially small objects) Slightly lower but closing gap
Complexity Multi-component pipeline Simpler and unified
Training Multi-task (RPN + head) Single-task joint optimization
Loss Cross-entropy + Smooth L1 Focal/IoU losses
Memory Usage Higher Lower
Class Imbalance Handling Easier Needs focal loss or reweighting
Small Object Performance Excellent Moderate (improving via FPN)
Best Use Case Offline, accuracy-critical applications Real-time, resource-limited applications
Examples Faster R-CNN, Mask R-CNN, Cascade R-CNN YOLO series, SSD, RetinaNet, FCOS, EfficientDet

14. Mathematical View of Both

Two-Stage:

[ P(object, class, box) = P(object) \cdot P(class|object) \cdot P(box|object) ]

  • Explicit modeling of objectness and conditional class probability.
  • RPN gives (P(object)), classifier gives (P(class|object)).

One-Stage:

[ P(class, box) = P(class) \cdot P(box|class) ]

  • Merged estimation; predicts class and box jointly for each cell.

This joint formulation is simpler but statistically noisier, which explains earlier accuracy gaps.


15. Summary: The Trade-Off

Trade-off Dimension Description
Speed vs Accuracy Two-stage more accurate, one-stage faster.
Precision vs Recall Two-stage has higher precision (fewer false positives), one-stage higher recall (detects more, sometimes noisy).
Complexity vs Deployability Two-stage harder to implement/deploy, one-stage lighter and edge-friendly.
Flexibility Two-stage easier to extend (mask, keypoints, cascades).

16. Future Trends

  • Transformer-based detectors (DETR, DINO, RT-DETR) blur traditional definitions: they directly learn object queries, eliminating anchors and NMS, while maintaining one-stage simplicity with two-stage accuracy.
  • Self-supervised and foundation models (SAM, CLIP, Segment Anything) now unify segmentation and detection.
  • Vision-Language Models (VLMs) like GroundingDINO and OWL-ViT expand object detection into open-world (detect anything described by text).

17. Bottom Line

  • Two-Stage Detectors: Ideal when accuracy is critical and inference speed is secondary (research, medical, high-precision vision, robotics). Best choice for segmentation and instance-level analysis.

  • One-Stage Detectors: Ideal for real-time, edge, and large-scale deployment scenarios (autonomous vehicles, drones, mobile apps, surveillance). Simpler, scalable, and increasingly accurate with FPN and anchor-free designs.

Both methods are complementary, not competing. Modern detection ecosystems often combine both philosophies — proposal refinement from two-stage and direct dense prediction from one-stage — to achieve high accuracy, robustness, and efficiency.