Paper commentary
YOLOv12: Attention-Centric Real-Time Object Detectors
Attention-centric design makes YOLO detectors more accurate at real-time speed
- Problem Attention models are more accurate than CNNs but have been too slow for real-time YOLO detectors. Their quadratic cost and slow memory access have kept YOLO on CNN-based designs.
- Method YOLOv12 uses area attention and R-ELAN blocks for real-time detection.
- Results YOLOv12-N reaches 40.6% mAP with 1.64 ms latency on a T4 GPU. That beats YOLOv10-N and YOLO11-N by 2.1% and 1.2% mAP at comparable speed.
Why attention has been slow in YOLO
Real-time YOLO detectors have kept CNN-centred block designs, even though attention-based vision models are known to model features more strongly, including in small models. The authors trace the gap to two costs of the attention mechanism: quadratic computational complexity and inefficient memory access, with the memory side being the target of FlashAttention.
Under a similar computational budget, the cited comparison puts CNN-based architectures ahead of attention-based ones by about 3×, which keeps attention out of YOLO systems where inference speed is critical.
For a sequence of L tokens with feature dimension d, the attention matrix costs \(O(L^2 d)\) because each token attends to every other token, while a convolution with kernel size k scales as \(O(kLd)\). The memory cost comes from the attention map \(QK^T\) and the \(L \times L\) softmax map, which are written from fast on-chip SRAM to high-bandwidth GPU memory and read back, and the paper says the read and write speed of SRAM is more than 10 times that of HBM.
Irregular access patterns add further latency, whereas CNN kernels read structured, localized memory.
Both costs are handled in different ways: memory by FlashAttention, and complexity by a cheaper attention pattern, since sparse attention and approximations such as Linformer and Performer were already aimed at the quadratic scaling.
Area attention as a cheaper local attention
Linear attention is the first cheap option considered, reducing the cost from \(2n^2hd\) to \(2nhd^2\) for a visual feature with n tokens, h heads and head size d. The authors reject it for YOLO because it weakens global dependency, can be unstable, is sensitive to the distribution, and offers limited speed gains at 640 × 640 inputs. Local attention, such as shifted windows, criss-cross attention and axial attention, is the second option, but partitioning a feature map into windows can add overhead or shrink the receptive field.
Area attention keeps full attention inside each region and changes only the partition: a feature map of size (H, W) is cut into l equal segments of size (H/l, W) or (H, W/l), vertically or horizontally. Because the split is a simple reshape, no explicit window partitioning is needed, which is where the speed comes from. The default l is 4, which the authors describe as reducing the receptive field to one quarter of the original while still keeping it large.
With this split, the attention cost is written as reduced from \(2n^2hd\) to \(\tfrac{1}{2}n^2hd\), and the authors keep the quadratic form because n is fixed at 640 in the YOLO setting, which they judge fast enough for real-time use. The authors report that this change has only a slight effect on accuracy and a clear gain in speed.
R-ELAN and the residual shortcut
ELAN starts with a 1 × 1 transition layer whose output is split, one split passes through several modules, and all outputs are concatenated and passed through another 1 × 1 transition layer. The authors argue that this layout can be unstable, causes gradient blocking, and has no residual connection from input to output.
R-ELAN adds a residual shortcut from the block input to its output, scaled by a factor whose default is 0.01. The scaling resembles layer scaling for deep vision transformers, but applying layer scaling to each area attention did not solve the convergence problem and added latency, according to the authors. The authors conclude that the ELAN layout itself, not attention alone, contributes to the instability, which is the reason for the R-ELAN design.
The aggregation is rewritten as well: a transition layer adjusts channels to produce one feature map, which passes through the subsequent blocks and is then concatenated, forming a bottleneck. The authors state that this keeps feature integration while reducing computation and parameter or memory use.
Changes around the attention block
YOLOv12 keeps the hierarchical stage layout of earlier YOLO systems rather than a plain transformer stack. The first two backbone stages are inherited from YOLOv11 without R-ELAN, and the stack of three blocks in the last stage is replaced by a single R-ELAN block.
Several vanilla attention defaults change: the MLP ratio goes from 4 to 1.2, or to 2 for the N, S and M scales, which shifts compute toward attention. nn.Conv2d+BN replaces nn.Linear+LN, and positional encoding is removed.
Without positional encoding, the Position Perceiver applies a separable 7 × 7 convolution to the attention value \(v\) and adds its output back to the attention output, which the authors say preserves pixel positions for the attention to use.
Diagnostic tables for the attention choices
In Table 5a, Conv+BN reaches 40.6 AP at 1.64 ms, Linear+LN 40.5 AP at 1.68 ms, Conv+LN 40.3 AP at 1.66 ms and Linear+BN 39.5 AP at 1.70 ms. With convolution, batch normalization is better than layer normalization, which the authors connect to the PSA module in YOLOv10.
In Table 5b, the plain vision transformer layout (N/A) gives 38.3 AP, removing the first stage (S1) gives 40.1 AP, removing the fourth stage (S4) gives 39.8 AP, and the default gives 40.6 AP. These diagnostics use YOLOv12-N trained for 600 epochs from scratch unless otherwise stated.
Table 5g gives 53.8 AP at 6.77 ms for an MLP ratio of 1.2, 53.6 AP at 6.75 ms for 2.0, and 53.1 AP at 6.68 ms for 4.0.
Without any positional embedding, the N model reaches 40.6 AP at 1.64 ms, against 40.5 AP at 1.69 ms with APE and 40.3 AP at 1.76 ms with RPE.
Table 5d shows that kernels of 3 × 3, 5 × 5, 7 × 7 and 9 × 9 reach 40.4, 40.4, 40.6 and 40.7 AP, with latencies of 1.60, 1.61, 1.64 and 1.79 ms. The authors choose 7 × 7 because the 9 × 9 kernel slows the model noticeably.
Training for 300, 500, 600 and 800 epochs gives 39.5, 40.3, 40.6 and 40.4 AP for N, and 47.0, 47.8, 48.0 and 47.7 AP for S. The authors note that YOLOv12 needs about 600 epochs for peak accuracy, longer than the roughly 500 epochs some earlier detectors need.
Residual branch in the R-ELAN ablation
Adding a residual with scaling 0.1 lowers the N model to 40.3 AP, so for the small model the residual branch lowers accuracy, though it does not affect convergence, according to the authors.
For YOLOv12-L, the rows without a residual branch have no values in the table, and the text says such L and X models fail to converge or remain unstable.
The authors state that X needs the minimal scaling factor of 0.01 to converge, and the X row with scaling 0.1 has no values in the table.
Accuracy against YOLO and DETR detectors
Table 1 uses 640 × 640 inputs and reports latency on a T4 GPU with TensorRT FP16. Its latency of 1.64 ms is below YOLOv10-N at 1.84 ms, but YOLO11-N is listed at 1.5 ms, so the gain over YOLO11-N comes with slightly higher latency.
The introduction states that YOLOv12-S runs 42% faster than RT-DETR-R18, with 36% of its computation and 45% of its parameters.
YOLOv12-L reaches 53.7 AP at 88.9 GFLOPs and 6.77 ms, which is 0.4 points above YOLO11-L, and the text says it has 31.4G fewer FLOPs than YOLOv10-L. YOLOv12-X reaches 55.2 AP at 199.0 GFLOPs and 11.79 ms, which is 0.8 points above YOLOv10-X and 0.6 points above YOLO11-X, with comparable speed, FLOPs and parameters.
Speed with area attention, FlashAttention and GPUs
The same table gives YOLOv12-S at 5.1/4.4 ms falling to 3.5/3.1 ms in FP32, and YOLOv12-X at 26.4/21.9 ms falling to 18.2/14.3 ms. On the CPU column the N, S and X models fall from 62.9, 130.0 and 804.2 to 31.4, 78.4 and 512.5.
The text summarizes this as roughly 0.3 ms for N and 0.4 ms for S, without other costs.
Table 4 times the models on RTX 3080, RTX A5000 and RTX A6000 in FP32 and FP16, with YOLOv9 and YOLOv10 evaluated in the ultralytics codebase. On RTX 3080, YOLOv12-N takes 1.7 ms in FP32 and 1.1 ms in FP16, while YOLO11-N takes 1.6 ms and 1.0 ms.
Heat map comparison
The heat maps come from the third backbone stage of X-scale models for YOLOv10, YOLOv11 and YOLOv12. The authors report clearer object contours and more precise foreground activation for YOLOv12 than for YOLOv10 and YOLOv11. They attribute this to area attention having a larger receptive field than convolution, which they say gives YOLOv12 wider context.
The comparison is visual, and the paper attaches no score to it.
Limitations
YOLOv12 requires FlashAttention, which the paper says supports Turing, Ampere, Ada Lovelace or Hopper GPUs. The L and X models need the residual scaling in R-ELAN, because without it the text says they fail to converge or remain unstable. Latency figures come from specific setups: a T4 with TensorRT FP16 for the main table, RTX 3080, A5000 and A6000 for the GPU analysis, and an Intel Core i7-10700K for CPU timing.
The ablation diagnostics use YOLOv12-N trained from scratch for 600 epochs, and the MLP ratio table does not name its model scale.
Paper info
- Authors
- Yunjie Tian, Qixiang Ye, David Doermann
- Venue
- arXiv · Preprint
- First published
- 2025-2-18
- Added
- 2026-11-12
- Updated
- 2025-2-18
- Version
- v1
- arXiv
- 2502.12524
- Category
- cs.CV · cs.AI
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Yunjie Tian, Qixiang Ye, David Doermann (2025). YOLOv12: Attention-Centric Real-Time Object Detectors. arXiv:2502.12524v1. https://arxiv.org/abs/2502.12524v1
BibTeX
@misc{tian2025yolov12,
title = {{YOLOv12: Attention-Centric Real-Time Object Detectors}},
author = {Yunjie Tian and Qixiang Ye and David Doermann},
year = {2025},
eprint = {2502.12524},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2502.12524v1}
}