Paper: YOLOv12: Attention-Centric Real-Time Object Detectors (NeurIPS 2025)
Official Repo: github.com/sunsmarterjie/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.
| 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.
- 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.
# 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/
├── 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.
path: ./dataset
train: images/train
val: images/val
nc: 3
names:
0: cat
1: dog
2: bird# 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 | Use Case |
|---|---|
yolov12n |
Fastest, laptop/edge GPU |
yolov12s |
Balanced speed & accuracy |
yolov12m |
Medium accuracy |
yolov12l |
High accuracy |
yolov12x |
Best accuracy, needs VRAM |
| VRAM | Recommended Settings |
|---|---|
| 4 GB | batch=4, imgsz=416, yolov12n |
| 6 GB | batch=8, imgsz=512, yolov12s |
| 8 GB+ | batch=16, imgsz=640, yolov12m |
yolo val model=runs/train/exp/weights/best.pt data=dataset.yamlmodel = YOLO('runs/train/exp/weights/best.pt')
metrics = model.val(data='dataset.yaml')
print("mAP50:", metrics.box.map50)
print("mAP50-95:", metrics.box.map)# Image
yolo predict model=yolov12n.pt source=image.jpg conf=0.5
# Webcam
yolo predict model=yolov12n.pt source=0 show=Truemodel = YOLO('yolov12n.pt')
results = model.predict('image.jpg', conf=0.5, save=True)yolo export model=yolov12n.pt format=onnxSupported formats: onnx, torchscript, tflite, engine (TensorRT)
yolov12-training/
├── dataset/
│ ├── images/
│ └── labels/
├── configs/
│ └── dataset.yaml
├── scripts/
│ ├── train.py
├── runs/ # Training outputs (auto-generated)
├── requirements.txt
└── README.md
This project follows the license of the official YOLOv12 repository.