According to the reference:sunsmarterjie/yolov12#122 (comment) and https://github.com/mohamedsamirx/YOLOv12-ONNX-CPP
Step-1 windows compile
- make sure VS2019 installed sucesss
- make sure anaconda installed sucess
- create conda environment:conda create -n yolov12 python=3.11
- install PyTorch + CUDA 12.9(12.1):pip install torch==2.4.1+cu121 torchvision==0.19.1+cu121 torchaudio==2.4.1 --extra-index-url https://download.pytorch.org/whl/cu121
- prepare the packet for next Flash-Attention:pip install ninja packaging wheel gitpython
- Flash-Attention setup: git config --system core.longpaths true git clone --recurse-submodules -b v2.7.4 https://github.com/Dao-AILab/flash-attention.git cd flash-attention python setup.py develop python setup.py bdist_wheel
- Then the Flash-Attention will be installed as .whl file,which can be seen from pip-list
- then pip install the following: timm==1.0.14 albumentations==2.0.4 onnx==1.14.0 onnxruntime==1.15.1 pycocotools==2.0.7 PyYAML==6.0.1 scipy==1.13.0 onnxslim==0.1.31 onnxruntime-gpu==1.18.0 gradio==4.44.1 opencv-python==4.9.0.80 psutil==5.9.8 py-cpuinfo==9.0.0 huggingface-hub==0.23.2 safetensors==0.4.3 numpy==1.26.4
- The yolov12-windows have installed sucess: you can check by command: yolo predict model=./yolov12x.pt source=./bus.jpg show=True
- to transcode from pt to onnx by the command: from ultralytics import YOLO model = YOLO('yolov12{n/s/m/l/x}.pt') model.export(format="onnx", half=True) # half=ture means fp16, otherwise is FP32
- then in VS2019, you pick up the cpp files,in onnx environment, I use the onnxruunming-time 18.1
Note:
I sucess achieve in VS2019, cuda 12.1 and onnxrunningtime-1.18 in windows10 and windows server2012.
1.C++ inference in step 11, If you use cudnn9.x please use onnxruunming-time 18.1.1, and if you use cudnn8.x use onnx 18.1.0
2.If "out of memory" displayed in Flash-Attention setup, you can config more virtual memory in windows system
3. Ampere GPUs and newer is needed for Flash-Attention in step 6!!!!But the inference in vs2019 is no need the Ampere GPU and newer
4. the Flash-Attention setup cost to much time, I use i9-14900k and ultra9-295K, use 2-hours long.
