简体中文 | English
This example demonstrates how to perform model inference using CLI, Python, and C++ with the YOLOv8s model as an example.
Important
If you want to use the EfficientRotatedNMS plugin to infer an OBB model, please refer to Building TensorRT Custom Plugins for guidance.
-
Download the YOLOv8s model and save it to the
models
folder. -
Use the following command to export the model to ONNX format with the EfficientNMS plugin:
trtyolo export -w models/yolov8s.pt -v yolov8 -o models
After running the above command, a
yolov8s.onnx
file will be generated in themodels
folder. Next, use thetrtexec
tool to convert the ONNX file to a TensorRT engine:trtexec --onnx=models/yolov8s.onnx --saveEngine=models/yolov8s.engine --fp16
-
Download the YOLOv8s-obb model and save it to the
models
folder. -
Use the following command to export the model to ONNX format with the EfficientRotatedNMS plugin:
trtyolo export -w models/yolov8s-obb.pt -v yolov8 -o models
After running the above command, a
yolov8s-obb.onnx
file will be generated in themodels
folder. Next, use thetrtexec
tool to convert the ONNX file to a TensorRT engine:trtexec --onnx=models/yolov8s-obb.onnx --saveEngine=models/yolov8s-obb.engine --fp16
- Download the coco128 dataset.
- After extraction, move the images from the
coco128/images/train2017
folder to theimages
folder for inference.
- Download the DOTA-v1.0 dataset.
- After extraction, move the images from the
part1/images
folder to theimages
folder for inference.
-
Use the
trtyolo
command-line tool for inference. Run the following command to view the help information:trtyolo infer --help
-
Run the following commands for inference:
[!NOTE] The
--cudaGraph
option, introduced in version 4.0, can further accelerate the inference process, but this feature only supports static models.From version 4.2 onwards, OBB model inference is supported, with the new
-m, --mode
option for selecting Detection or OBB models.# Detection Model trtyolo infer -e models/yolov8s.engine -m 0 -i images -o output -l labels_det.txt --cudaGraph # Oriented Bounding Box Model trtyolo infer -e models/yolov8s-obb.engine -m 1 -i images -o output -l labels_obb.txt --cudaGraph
The inference results will be saved to the
output
folder and generate visualized results.
-
Use the
tensorrt_yolo
library for Python inference. The sample scriptdetect.py
is ready for use. -
Run the following commands for inference:
[!NOTE] The
--cudaGraph
option can further accelerate the inference process, but this feature only supports static models.# Detection Model python detect.py -e models/yolov8s.engine -m 0 -i images -o output -l labels_det.txt --cudaGraph # Oriented Bounding Box Model python detect.py -e models/yolov8s-obb.engine -m 1 -i images -o output -l labels_obb.txt --cudaGraph
-
Ensure that the project has been compiled according to the Deploy Compilation Guide.
-
Use
xmake
to compiledetect.cpp
into an executable file:xmake f -P . --tensorrt="/path/to/your/TensorRT" --deploy="/path/to/your/TensorRT-YOLO" xmake -P . -r
After compilation, the executable file will be generated in the
build
folder at the project root. -
Run the following commands for inference:
[!NOTE] The
--cudaGraph
option can further accelerate the inference process, but this feature only supports static models.# Detection Model xmake run -P . detect -e models/yolov8s.engine -m 0 -i images -o output -l labels_det.txt --cudaGraph # Oriented Bounding Box Model xmake run -P . detect -e models/yolov8s-obb.engine -m 1 -i images -o output -l labels_obb.txt --cudaGraph
By following the steps above, you can successfully complete model inference.