🤖AI/ML

Object Detection

Object Detection

A computer vision technique that identifies both the location (bounding box) and type (class) of objects in images or video. Models such as YOLO, Faster R-CNN, and DETR are used in autonomous driving, security, and medical image analysis.

📖 Detailed Explanation

Object Detection is a computer vision technique that simultaneously identifies the location (bounding box) and type (class) of specific objects in images or videos. Unlike simple image classification, it predicts both "where" and "what" is present, and it is used as a core technology in autonomous driving, security cameras, medical image analysis, manufacturing quality inspection, and more.

Object detection is broadly divided into two approaches. Two-stage methods (R-CNN, Fast R-CNN, Faster R-CNN) first extract candidate regions with a Region Proposal Network (RPN) and then classify each region, which gives high accuracy. One-stage methods (YOLO, SSD, RetinaNet) process the entire image at once, which makes them fast. Recently, the Transformer-based DETR has emerged and is presenting a new paradigm.

mAP (mean Average Precision) and IoU (Intersection over Union) are used for performance evaluation. mAP@0.5 accepts an IoU of 50% or higher as correct, and model performance is compared on the basis of the COCO dataset. YOLOv8/v9/v10 are recent models that strike a good balance between real-time performance and accuracy, and RT-DETR is Transformer-based yet capable of real-time processing.

In practice, data quality is the most important factor. Labeling accuracy, class imbalance, and whether objects of various sizes/angles are included directly affect model performance. For edge device deployment, model compression (Pruning, Quantization) and ONNX/TensorRT conversion are essential.

📊 Performance & Cost

Comparison of Major Object Detection Model Performance (based on COCO val2017, January 2025)

Model mAP@0.5:0.95 FPS (T4 GPU) Parameter Use case
YOLOv8n 37.3% ~450 3.2M Edge/Mobile
YOLOv8m 50.2% ~180 25.9M Balanced
YOLOv8x 53.9% ~60 68.2M High Accuracy
YOLOv10x 54.4% ~55 56.9M Latest SOTA
RT-DETR-L 53.0% ~114 32M Transformer-based
Faster R-CNN 43.0% ~15 41M Research/High Precision

Selection Guide: If real-time processing is needed, we recommend YOLOv8n/s; if accuracy is important, YOLOv8x or YOLOv10x; and if small object detection is important, RT-DETR. When deploying to the edge, INT8 quantization can deliver a 2-4x speedup.

💻 Code Example

This is an object detection example using Ultralytics YOLOv8.

# pip install ultralytics

from ultralytics import YOLO
import cv2

# YOLOv8 모델 로드 (nano 버전 - 가장 빠름)
model = YOLO('yolov8n.pt')

# 이미지에서 객체 탐지
image_path = 'street.jpg'
results = model(image_path)

# 결과 처리
for result in results:
    boxes = result.boxes  # 바운딩 박스

    for box in boxes:
        # 좌표 추출 (x1, y1, x2, y2)
        x1, y1, x2, y2 = box.xyxy[0].tolist()

        # 클래스와 신뢰도
        cls_id = int(box.cls[0])
        cls_name = model.names[cls_id]
        confidence = float(box.conf[0])

        print(f"객체: {cls_name}")
        print(f"  위치: ({x1:.0f}, {y1:.0f}) - ({x2:.0f}, {y2:.0f})")
        print(f"  신뢰도: {confidence:.2%}")

# 결과 이미지 저장
result_img = results[0].plot()  # 바운딩 박스가 그려진 이미지
cv2.imwrite('result.jpg', result_img)

# 실시간 웹캠 탐지
# results = model(source=0, show=True, stream=True)  # 웹캠

# 출력 예시:
# 객체: car
#   위치: (120, 200) - (450, 380)
#   신뢰도: 94.32%

This is a Fine-tuning example with a custom dataset.

# 커스텀 학습 - YOLO 포맷 데이터셋 필요
# data.yaml 예시:
# path: /data/custom_dataset
# train: images/train
# val: images/val
# names:
#   0: helmet
#   1: vest
#   2: person

from ultralytics import YOLO

# 사전학습된 모델로 시작
model = YOLO('yolov8n.pt')

# Fine-tuning
results = model.train(
    data='data.yaml',
    epochs=100,
    imgsz=640,
    batch=16,
    device=0,  # GPU 0번
    workers=8,
    patience=20,  # Early stopping
    augment=True,
    mosaic=1.0,  # 모자이크 어그멘테이션
    mixup=0.1
)

# 검증
metrics = model.val()
print(f"mAP@0.5: {metrics.box.map50:.3f}")
print(f"mAP@0.5:0.95: {metrics.box.map:.3f}")

# ONNX 내보내기 (엣지 배포용)
model.export(format='onnx', imgsz=640, simplify=True)

# TensorRT 내보내기 (NVIDIA GPU 최적화)
model.export(format='engine', imgsz=640, half=True)  # FP16

🗣️ Examples of Practical Conversations

💬 In a Meeting

"If you use YOLOv8 nano for CCTV video analysis, you can process over 200 frames per second on an RTX 3060. Converting with TensorRT makes it even faster, and although accuracy drops slightly, it's the best option if real-time processing is the priority."

💬 In an Interview

"We built a license plate recognition system. We designed a pipeline that first detects the license plate region with YOLOv8 and then recognizes the characters with CRNN-based OCR. By augmenting with synthetic data for night/backlit conditions, we achieved 97% at mAP@0.5."

💬 In a Technical Discussion

"If small object detection is difficult, you should raise the input resolution to 1280 or use SAHI (Slicing Aided Hyper Inference). If memory is limited, RT-DETR is stronger on small objects. That's because the Transformer's self-attention captures global context well."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Cautions

❌

Ignoring class imbalance

If a particular class is too rare in the training data, the model cannot detect that class well. Focal Loss, oversampling, or per-class weight adjustment is needed.

❌

Neglecting Labeling Quality

If bounding boxes are inaccurate or labels are inconsistent, the model will not train properly. Make labeling guidelines clear and introduce a QA process.

❌

Ignoring Differences in the Operating Environment

If the training data differs from the actual operating environment (lighting, weather, camera angle), performance degrades significantly. Consider Domain Adaptation techniques.

✅

The right way

Apply sufficient data augmentation (rotation, scale, mosaic, color transformation), and adjust the NMS threshold and confidence threshold to fit your domain. When deploying to the edge, optimize with ONNX/TensorRT conversion and INT8 quantization.

🔥 Real-World Incidents

Tesla Autopilot 2016-2021

Multiple Autonomous Driving Accidents Caused by Object Detection Failures

Cause: A white trailer/truck was mistaken for a bright sky background, stationary emergency vehicles were not detected, and recognition failed in backlit conditions

Impact: Multiple fatal accidents occurred, with an NHTSA investigation and recall recommendations

Resolution: Switched from camera-based to camera+radar fusion (later reverted to camera-only), and diversified training data

Lesson: Safety-critical systems should not rely on a single sensor/model; multimodal fusion and sufficient edge case testing are essential.

📎 NHTSA Report
Amazon 2018

Controversy over Racial Bias in Rekognition Facial Recognition

Cause: Due to racial imbalance in the training data, the false positive rate for Black women was 31% higher than for white men

Impact: Requests to halt use by law enforcement agencies, decline in trust

Resolution: Secured diversity in training data and introduced fairness testing

Lesson: The fairness and bias of AI models must be verified in advance, and uniform performance must be ensured across diverse demographic groups.

📎 Gender Shades Study

📝 Comprehension Quiz

Q1. Which is a representative model of the Two-stage approach in object detection?

Q2. Which metric indicates the degree of overlap between bounding boxes in object detection performance evaluation?

Q3. Which of the following is NOT a technique commonly used for speed optimization when deploying an object detection model to edge devices?

🔗 Related Terms

📚 Learn More