- Clone YOLOv9 repo and install its requirements:
git clone https://github.com/WongKinYiu/yolov9
cd yolov9
pip install -r requirements.txt
- Download yolov9-c.pt or yolov9-e.pt model.
- Convert the model to onnx format:
- Put
reparameterize.py
file to YOLOv9 installation folder and perform re-parameterization:
python reparameterize.py yolov9-c.pt yolov9-c-converted.pt
-
Or you can skip re-parameterization and downloaded the re-parameterized models yolov9-c-converted.pt and yolov9-e-converted.pt.
-
Then export the model:
python export.py --weights yolov9-c-converted.pt --include onnx
- Build a TensorRT engine:
trtexec.exe --onnx=yolov9-c-converted.onnx --explicitBatch --saveEngine=yolov9-c.engine --fp16
Note
'--fp16' is an optional argument for performing inference using fp16 precision.- Set
opencv
andtensorrt
installation paths in CMakeLists.txt:
# Find and include OpenCV
set(OpenCV_DIR "your path to OpenCV")
# Set TensorRT path if not set in environment variables
set(TENSORRT_DIR "your path to TensorRT")
- Build the project:
mkdir build
cd build
cmake ..
cmake --build . --config Release
- TensorRT 8.6
- CUDA 11.8
- Windows 10