YOLO
You Only Look Once
A real-time object detection algorithm. Detects objects in a single forward pass.
You Only Look Once
A real-time object detection algorithm. Detects objects in a single forward pass.
YOLO (You Only Look Once) is a real-time object detection algorithm proposed by Joseph Redmon in 2015. Unlike the earlier R-CNN family, which performed region proposal and classification in two stages, YOLO processes the entire image in a single forward pass of a neural network and predicts bounding boxes and class probabilities simultaneously. This single-stage approach made real-time processing possible.
The core idea of YOLO is to divide an image into an S x S grid, where each grid cell predicts B bounding boxes and C class probabilities. Each bounding box has five values (x, y, w, h, confidence), and confidence is the product of the probability that an object exists in the box and the IoU (Intersection over Union). Detection, converted into this regression problem, is processed very quickly on a GPU.
YOLO has evolved through various versions. From YOLOv1 (2015) to YOLOv3 (2018, Darknet-53 backbone), it was developed by the original author, and afterwards YOLOv4 and YOLOv5 emerged under community leadership. YOLOv8 (2023), developed by Ultralytics, improved accuracy and speed with an anchor-free approach and a decoupled head structure. YOLOv9 (2024) resolved the information loss problem with PGI (Programmable Gradient Information) and the GELAN architecture, and YOLO11 (2024) achieved higher accuracy with 22% fewer parameters.
YOLO is widely used in fields that require real-time object detection, such as autonomous vehicles, CCTV analysis, drone video processing, sports analytics, and manufacturing quality inspection. In addition to detection, it supports various computer vision tasks such as segmentation, pose estimation, and tracking. It can be exported to various formats such as TensorRT, ONNX, and CoreML for edge device deployment.
# YOLO11 κ°μ²΄ νμ§ μμ (Ultralytics)
from ultralytics import YOLO
import cv2
# ============================================
# 1. λͺ¨λΈ λ‘λ λ° μΆλ‘
# ============================================
# μ¬μ νμ΅λ YOLO11 λͺ¨λΈ λ‘λ (n, s, m, l, x ν¬κΈ°)
model = YOLO("yolo11n.pt") # nano λ²μ (κ°μ₯ λΉ λ¦)
# model = YOLO("yolo11s.pt") # small
# model = YOLO("yolo11m.pt") # medium
# model = YOLO("yolo11l.pt") # large (μ νλ μ΅λ)
# μ΄λ―Έμ§ μΆλ‘
results = model("image.jpg")
# κ²°κ³Ό νμΈ
for result in results:
boxes = result.boxes # λ°μ΄λ© λ°μ€
print(f"νμ§λ κ°μ²΄ μ: {len(boxes)}")
for box in boxes:
# μ’ν, ν΄λμ€, μ λ’°λ
x1, y1, x2, y2 = box.xyxy[0].tolist()
conf = box.conf[0].item()
cls_id = int(box.cls[0].item())
cls_name = model.names[cls_id]
print(f" - {cls_name}: {conf:.2f} at ({x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f})")
# κ²°κ³Ό μκ°ν λ° μ μ₯
result.save("result.jpg")
# ============================================
# 2. λΉλμ€/μΉμΊ μ€μκ° μΆλ‘
# ============================================
# μΉμΊ μ€μκ° νμ§
results = model.predict(source=0, show=True, stream=True)
for r in results:
pass # μ€μκ° νλ©΄ νμ
# λΉλμ€ νμΌ μ²λ¦¬
results = model.predict(
source="video.mp4",
save=True, # κ²°κ³Ό μ μ₯
conf=0.5, # μ λ’°λ μκ³κ°
iou=0.45, # NMS IoU μκ³κ°
device="cuda:0" # GPU μ¬μ©
)
# ============================================
# 3. 컀μ€ν
λ°μ΄ν°μ
νμ΅
# ============================================
# YAML νμμ λ°μ΄ν°μ
μ€μ νμ
# data.yaml μμ:
# train: ./train/images
# val: ./val/images
# nc: 3 # ν΄λμ€ μ
# names: ['cat', 'dog', 'bird']
model = YOLO("yolo11n.pt") # μ¬μ νμ΅ κ°μ€μΉλ‘ μμ
# νμ΅ μμ
results = model.train(
data="data.yaml",
epochs=100,
imgsz=640,
batch=16,
device="cuda:0",
patience=20, # Early stopping
save=True,
project="runs/detect",
name="my_model"
)
# ============================================
# 4. λͺ¨λΈ λ΄λ³΄λ΄κΈ° (λ°°ν¬μ©)
# ============================================
# ONNX ν¬λ§· (λ²μ©)
model.export(format="onnx", simplify=True)
# TensorRT (NVIDIA GPU μ΅μ ν)
model.export(format="engine", device=0)
# CoreML (Apple λλ°μ΄μ€)
model.export(format="coreml")
# TFLite (λͺ¨λ°μΌ/μ£μ§)
model.export(format="tflite")
# ============================================
# 5. λ€μν νμ€ν¬
# ============================================
# μΈμ€ν΄μ€ μΈκ·Έλ©ν
μ΄μ
seg_model = YOLO("yolo11n-seg.pt")
seg_results = seg_model("image.jpg")
# ν¬μ¦ μΆμ
pose_model = YOLO("yolo11n-pose.pt")
pose_results = pose_model("image.jpg")
# μ΄λ―Έμ§ λΆλ₯
cls_model = YOLO("yolo11n-cls.pt")
cls_results = cls_model("image.jpg")
# κ°μ²΄ μΆμ (BoT-SORT, ByteTrack)
track_results = model.track(
source="video.mp4",
tracker="botsort.yaml", # λλ "bytetrack.yaml"
persist=True
)
COCO val2017 benchmark (640x640 resolution, based on NVIDIA T4 GPU)
| Model | mAP@50-95 | Parameter | FLOPs | Inference speed |
|---|---|---|---|---|
| YOLOv8n | 37.3% | 3.2M | 8.7G | ~16ms (~61 FPS) |
| YOLOv8s | 44.9% | 11.2M | 28.6G | ~21ms (~48 FPS) |
| YOLOv8m | 50.2% | 25.9M | 78.9G | ~33ms (~30 FPS) |
| YOLOv9t | 38.3% | 2.0M | 7.7G | ~15ms (~67 FPS) |
| YOLOv9s | 46.8% | 7.2M | 26.7G | ~18ms (~56 FPS) |
| YOLOv9c | 53.0% | 25.5M | 102.8G | ~28ms (~36 FPS) |
| YOLO11n | 39.5% | 2.6M | 6.5G | ~17ms (~57 FPS) |
| YOLO11s | 47.0% | 9.4M | 21.5G | ~24ms (~42 FPS) |
| YOLO11m | 51.5% | 20.1M | 68.0G | ~27ms (~37 FPS) |
| YOLO11l | 53.4% | 25.3M | 86.9G | ~33ms (~30 FPS) |
Key features by version:
Recommended choices:
* Cost: Ultralytics YOLO is AGPL-3.0 open source (free). A commercial license requires contacting Ultralytics Enterprise.
"If you need real-time detection, try YOLO11n first, and if the accuracy is insufficient, move up to s or m."
-> When discussing model size selection
"If you convert to TensorRT and deploy, inference speed gets 2-3 times faster."
-> When optimizing production deployment
"When fine-tuning on custom data, start from the pretrained weights."
-> When guiding custom training
"YOLO11 has the best performance relative to its parameters, so I start new projects with it."
-> When advising on version selection
Input image size mismatch
If you train at 640x640 but use a different size at inference, performance drops. Match the imgsz parameter.
Setting the conf threshold too low
With a low value such as conf=0.1, false positives (False Positive) surge. Usually start between 0.25 and 0.5.
Excessive data augmentation
Excessive augmentation such as mosaic and mixup is actually harmful for detecting small objects. Turn off augmentation for the last 10 epochs (close_mosaic option).
Correct approach: incremental optimization
1) Establish a baseline with default settings 2) Adjust the conf/iou thresholds 3) Change the model size 4) Fine-tune hyperparameters 5) Optimize the deployment format (ONNX/TensorRT)