- 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.-
Install
Eigen
referring to this guide. Maybe need administrative privileges. -
Set
OpenCV
andTensorRT
installation paths in CMakeLists.txt:
# Find and include OpenCV
set(OpenCV_DIR "your path to OpenCV")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# Set TensorRT path if not set in environment variables
set(TENSORRT_DIR "your path to TensorRT")
-
Build a project:
- Windows:
mkdir build cd build cmake .. cmake --build . --config Release
- Linux(not tested):
mkdir build cd build && mkdir out_dir cmake .. make