GitHub - sunsmarterjie/yolov12 at Seg (original) (raw)

YOLOv12

YOLOv12: Attention-Centric Real-Time Object Detectors

Yunjie Tian1, Qixiang Ye2, David Doermann1

1 University at Buffalo, SUNY, 2 University of Chinese Academy of Sciences.

Main Results

Instance segmentation:

Model size(pixels) mAPbox50-95 mAPmask50-95 SpeedT4 TensorRT10 params(M) FLOPs(B)
YOLOv12n-seg 640 39.9 32.8 1.84 2.8 9.9
YOLOv12s-seg 640 47.5 38.6 2.84 9.8 33.4
YOLOv12m-seg 640 52.4 42.3 6.27 21.9 115.1
YOLOv12l-seg 640 54.0 43.2 7.61 28.8 137.7
YOLOv12x-seg 640 55.2 44.2 15.43 64.5 308.7

Installation

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
conda create -n yolov12 python=3.11
conda activate yolov12
pip install -r requirements.txt
pip install -e .

Validation

yolov12n-seg yolov12s-seg yolov12m-seg yolov12l-seg yolov12x-seg

from ultralytics import YOLO

model = YOLO('yolov12{n/s/m/l/x}-seg.pt') model.val(data='coco.yaml', save_json=True)

Training

from ultralytics import YOLO

model = YOLO('yolov12n-seg.yaml')

Train the model

results = model.train( data='coco.yaml', epochs=600, batch=128, imgsz=640, scale=0.5, # S:0.9; M:0.9; L:0.9; X:0.9 mosaic=1.0, mixup=0.0, # S:0.05; M:0.15; L:0.15; X:0.2 copy_paste=0.1, # S:0.15; M:0.4; L:0.5; X:0.6 device="0,1,2,3", )

Evaluate model performance on the validation set

metrics = model.val()

Perform object detection on an image

results = model("path/to/image.jpg") results[0].show()

Prediction

from ultralytics import YOLO

model = YOLO('yolov12{n/s/m/l/x}-seg.pt') model.predict()

Export

from ultralytics import YOLO

model = YOLO('yolov12{n/s/m/l/x}-seg.pt') model.export(format="engine", half=True) # or format="onnx"

Demo

python app.py
# Please visit http://127.0.0.1:7860

Acknowledgement

The code is based on ultralytics. Thanks for their excellent work!

Citation

@article{tian2025yolov12, title={YOLOv12: Attention-Centric Real-Time Object Detectors}, author={Tian, Yunjie and Ye, Qixiang and Doermann, David}, journal={arXiv preprint arXiv:2502.12524}, year={2025} }