-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for YOLO OBB Export and Inference with EfficientRotatedNM…
…S Plugin (#16)
- Loading branch information
1 parent
0caaf27
commit c2686cc
Showing
22 changed files
with
840 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,120 @@ | ||
English | [简体中文](README.md) | ||
[简体中文](README.md) | English | ||
|
||
# Model Inference Examples | ||
|
||
In this example, we demonstrate how to perform model inference using YOLOv8s with CLI, Python, and C++. | ||
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/efficientRotatedNMSPlugin) plugin to infer an OBB model, please refer to [Building TensorRT Custom Plugins](../../docs/en/build_trt_custom_plugin.md) for guidance. | ||
## Model Export | ||
|
||
First, download the YOLOv8s model from [YOLOv8s](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt) and save it to the `models` folder. | ||
### Detection Model | ||
|
||
Then, export the model to ONNX format with the [EfficientNMS](https://github.com/NVIDIA/TensorRT/tree/main/plugin/efficientNMSPlugin) plugin using the following command: | ||
1. Download the [YOLOv8s](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt) model and save it to the `models` folder. | ||
2. Use the following command to export the model to ONNX format with the [EfficientNMS](https://github.com/NVIDIA/TensorRT/tree/main/plugin/efficientNMSPlugin) plugin: | ||
|
||
```bash | ||
trtyolo export -w models/yolov8s.pt -v yolov8 -o models | ||
``` | ||
```bash | ||
trtyolo export -w models/yolov8s.pt -v yolov8 -o models | ||
``` | ||
|
||
After executing the above command, a file named `yolov8s.onnx` will be generated in the `models` folder. Next, convert the ONNX file to a TensorRT engine using the `trtexec` tool: | ||
After running the above command, a `yolov8s.onnx` file will be generated in the `models` folder. Next, use the `trtexec` tool to convert the ONNX file to a TensorRT engine: | ||
|
||
```bash | ||
trtexec --onnx=models/yolov8s.onnx --saveEngine=models/yolov8s.engine --fp16 | ||
``` | ||
```bash | ||
trtexec --onnx=models/yolov8s.onnx --saveEngine=models/yolov8s.engine --fp16 | ||
``` | ||
|
||
Now, we will perform model inference using different methods. | ||
### Oriented Bounding Box Model (OBB) | ||
|
||
## Model Inference | ||
1. Download the [YOLOv8s-obb](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s-obb.pt) model and save it to the `models` folder. | ||
2. Use the following command to export the model to ONNX format with the [EfficientRotatedNMS](../../plugin/efficientRotatedNMSPlugin/) plugin: | ||
|
||
```bash | ||
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 the `models` folder. Next, use the `trtexec` tool to convert the ONNX file to a TensorRT engine: | ||
|
||
```bash | ||
trtexec --onnx=models/yolov8s-obb.onnx --saveEngine=models/yolov8s-obb.engine --fp16 | ||
``` | ||
|
||
## Dataset Preparation | ||
|
||
Download the [coco128](https://ultralytics.com/assets/coco128.zip) dataset, unzip it, and move the images from the `coco128/images/train2017` folder to the `images` folder for inference. | ||
### Detection Model | ||
|
||
1. Download the [coco128](https://ultralytics.com/assets/coco128.zip) dataset. | ||
2. After extraction, move the images from the `coco128/images/train2017` folder to the `images` folder for inference. | ||
|
||
### Oriented Bounding Box Model (OBB) | ||
|
||
1. Download the [DOTA-v1.0](https://drive.google.com/file/d/1fwiTNqRRen09E-O9VSpcMV2e6_d4GGVK/view) dataset. | ||
2. After extraction, move the images from the `part1/images` folder to the `images` folder for inference. | ||
|
||
## Model Inference | ||
|
||
### Inference using CLI | ||
### Inference Using CLI | ||
|
||
You can use the `trtyolo` command-line tool provided by `tensorrt_yolo` for inference. Run the following command to see the help information related to inference: | ||
1. Use the `trtyolo` command-line tool for inference. Run the following command to view the help information: | ||
|
||
```bash | ||
trtyolo infer --help | ||
``` | ||
```bash | ||
trtyolo infer --help | ||
``` | ||
|
||
Then, perform inference using the following command: | ||
2. Run the following commands for inference: | ||
|
||
> To further speed up the inference process, use the `--cudaGraph` option, but this feature only supports static models, not dynamic models. (not supported before version 4.0) | ||
> [!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. | ||
|
||
```bash | ||
trtyolo infer -e models/yolov8s.engine -i images -o output -l labels.txt --cudaGraph | ||
``` | ||
```bash | ||
# 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 | ||
``` | ||
|
||
This command will generate visualized inference results in the `output` folder. | ||
The inference results will be saved to the `output` folder and generate visualized results. | ||
|
||
### Inference using Python | ||
### Inference Using Python | ||
|
||
You can also write a script using the `tensorrt_yolo` library for inference. The script `detect.py` is already written for this purpose. | ||
1. Use the `tensorrt_yolo` library for Python inference. The sample script `detect.py` is ready for use. | ||
2. Run the following commands for inference: | ||
|
||
> To further speed up the inference process, use the `--cudaGraph` option, but this feature only supports static models, not dynamic models. | ||
> [!NOTE] | ||
> The `--cudaGraph` option can further accelerate the inference process, but this feature only supports static models. | ||
|
||
```bash | ||
python detect.py -e models/yolov8s.engine -i images -o output -l labels.txt --cudaGraph | ||
``` | ||
```bash | ||
# 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 | ||
``` | ||
|
||
### Inference using C++ | ||
### Inference Using C++ | ||
|
||
Before performing inference using C++, ensure that you have compiled Deploy as per the [Deploy Build Guide](../../docs/en/build_and_install.md#deploy-Build). | ||
1. Ensure that the project has been compiled according to the [Deploy Compilation Guide](../../docs/en/build_and_install.md#deploy-compilation). | ||
2. Use `xmake` to compile `detect.cpp` into an executable file: | ||
|
||
Next, compile `detect.cpp` into an executable using xmake: | ||
```bash | ||
xmake f -P . --tensorrt="/path/to/your/TensorRT" --deploy="/path/to/your/TensorRT-YOLO" | ||
```bash | ||
xmake f -P . --tensorrt="/path/to/your/TensorRT" --deploy=/path/to/your/TensorRT-YOLO | ||
xmake -P . -r | ||
``` | ||
|
||
xmake -P . -r | ||
``` | ||
After compilation, the executable file will be generated in the `build` folder at the project root. | ||
|
||
After executing the above commands, an executable named `detect` will be generated in the `build` directory at the root. Finally, you can run the executable directly or use the `xmake run` command for inference. Use `--help` to see detailed command options: | ||
3. Run the following commands for inference: | ||
|
||
> To further speed up the inference process, use the `--cudaGraph` option, but this feature only supports static models, not dynamic models. | ||
> [!NOTE] | ||
> The `--cudaGraph` option can further accelerate the inference process, but this feature only supports static models. | ||
|
||
```bash | ||
xmake run -P . detect -e models/yolov8s.engine -i images -o output -l labels.txt --cudaGraph | ||
``` | ||
```bash | ||
# 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 | ||
``` | ||
|
||
The above are examples of how to perform model inference. | ||
By following the steps above, you can successfully complete model inference. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.