Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

YOLOv12 — Attention-Centric Real-Time Object Detection

Paper: YOLOv12: Attention-Centric Real-Time Object Detectors (NeurIPS 2025)
Official Repo: github.com/sunsmarterjie/yolov12


What is YOLOv12?

YOLOv12 is the first attention-based YOLO model that matches the speed of CNN-based detectors while leveraging the accuracy benefits of attention mechanisms. It introduces two key innovations:

  • Area Attention (A²) — splits feature maps into local segments (horizontal/vertical) to reduce the quadratic complexity of full self-attention, keeping inference fast.
  • R-ELAN (Residual Efficient Layer Aggregation Network) — adds scaled residual connections for better training stability, especially on larger model scales.

Performance Highlights

Model mAP (COCO) Latency (T4 GPU)
YOLOv12-N 40.6% 1.64 ms
YOLOv12-S 48.0% 2.61 ms
YOLOv12-M 52.5% 4.86 ms
YOLOv12-L 53.7% 6.77 ms
YOLOv12-X 55.2% 11.79 ms

YOLOv12-N outperforms YOLOv11-N by +1.2% mAP at comparable speed.


Requirements

  • Python 3.11
  • CUDA-compatible GPU (Turing, Ampere, Ada Lovelace, or Hopper recommended for FlashAttention)
    • Examples: RTX 20/30/40 series, A100, H100, T4
  • PyTorch 2.2+

⚠️ Older GPU architectures (e.g., GTX 10 series) may not support FlashAttention. Training will still work but at reduced speed.


Installation

# Clone the repo
git clone https://github.com/sunsmarterjie/yolov12.git
cd yolov12

# Create a conda environment
conda create -n yolov12 python=3.11
conda activate yolov12

# Install FlashAttention (for supported GPUs)
wget https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.3/flash_attn-2.7.3+cu11torch2.2cxx11abiFALSE-cp311-cp311-linux_x86_64.whl

# Install dependencies
pip install -r requirements.txt
pip install -e .

Dataset Structure

dataset/
├── images/
│   ├── train/
│   └── val/
└── labels/
    ├── train/
    └── val/

Each label .txt file (YOLO format):

<class_id> <x_center> <y_center> <width> <height>

All values normalized between 0.0 and 1.0.

dataset.yaml

path: ./dataset
train: images/train
val: images/val

nc: 3
names:
  0: cat
  1: dog
  2: bird

Training

# Train from CLI
yolo train model=yolov12n.pt data=dataset.yaml epochs=100 imgsz=640

# Or with Python
from ultralytics import YOLO

model = YOLO('yolov12n.pt')
model.train(data='dataset.yaml', epochs=100, imgsz=640, batch=16, device=0)

Model Variants

Model Use Case
yolov12n Fastest, laptop/edge GPU
yolov12s Balanced speed & accuracy
yolov12m Medium accuracy
yolov12l High accuracy
yolov12x Best accuracy, needs VRAM

Laptop GPU Tips

VRAM Recommended Settings
4 GB batch=4, imgsz=416, yolov12n
6 GB batch=8, imgsz=512, yolov12s
8 GB+ batch=16, imgsz=640, yolov12m

Validation

yolo val model=runs/train/exp/weights/best.pt data=dataset.yaml
model = YOLO('runs/train/exp/weights/best.pt')
metrics = model.val(data='dataset.yaml')
print("mAP50:", metrics.box.map50)
print("mAP50-95:", metrics.box.map)

Inference

# Image
yolo predict model=yolov12n.pt source=image.jpg conf=0.5

# Webcam
yolo predict model=yolov12n.pt source=0 show=True
model = YOLO('yolov12n.pt')
results = model.predict('image.jpg', conf=0.5, save=True)

Export

yolo export model=yolov12n.pt format=onnx

Supported formats: onnx, torchscript, tflite, engine (TensorRT)


Project Structure

yolov12-training/
├── dataset/
│   ├── images/
│   └── labels/
├── configs/
│   └── dataset.yaml
├── scripts/
│   ├── train.py
├── runs/              # Training outputs (auto-generated)
├── requirements.txt
└── README.md

License

This project follows the license of the official YOLOv12 repository.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages