An open API service indexing awesome lists of open source software.

https://github.com/cvhub520/rtdetr-onnxruntime-deploy

This project showcases the deployment of the RT-DETR model using ONNXRUNTIME in C++ and Python.
https://github.com/cvhub520/rtdetr-onnxruntime-deploy

Last synced: about 1 year ago
JSON representation

This project showcases the deployment of the RT-DETR model using ONNXRUNTIME in C++ and Python.

Awesome Lists containing this project

README

          

# RT-DETR-onnxruntime-project πŸ’»



This project showcases the deployment of the RT-DETR model using ONNXRUNTIME in C++ and Python.

## Environment Dependencies πŸ› οΈ

- OpenCV: 4.x
- ONNXRuntime: Tested on 1.14
- OS: Tested on Ubuntu 18.04
- CUDA: 11+ [Optional]

## Installation and Model Conversion πŸš€

```bash
$ conda create -n rtdetr python=3.8 -y
$ conda activate rtdetr

$ python -m pip install paddlepaddle-gpu==2.4.2.post117 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html

# Clone PaddleDetection repository
$ git clone https://github.com/PaddlePaddle/PaddleDetection.git
$ cd PaddleDetection
$ git checkout develop

# Compile and install paddledet
$ pip install -r requirements.txt
$ python setup.py install

# Validation
$ python tools/infer.py -c configs/rtdetr/rtdetr_r50vd_6x_coco.yml -o weights=https://bj.bcebos.com/v1/paddledet/models/rtdetr_r50vd_6x_coco.pdparams --infer_img=bus.jpg
```

- Modify the configuration file [PaddleDetection/configs/rtdetr/_base_/rtdetr_r50vd.yml]:

![](./images/example_img-1.png)

- Modify the processing code according to the illustration [PaddleDetection/ppdet/modeling/architectures/detr.py]:

![](./images/example_img-2.png)

```bash
# Download the pretrained weight
$ wget https://bj.bcebos.com/v1/paddledet/models/rtdetr_r50vd_6x_coco.pdparams && mkdir weights && mv rtdetr_r50vd_6x_coco.pdparams ./weights

$ python tools/export_model.py -c configs/rtdetr/rtdetr_r50vd_6x_coco.yml \
-o weights=https://bj.bcebos.com/v1/paddledet/models/rtdetr_r50vd_6x_coco.pdparams trt=True \
--output_dir=output_inference

$ pip install onnx==1.13.0
$ pip install paddle2onnx==1.0.5

$ paddle2onnx --model_dir=./output_inference/rtdetr_r50vd_6x_coco/ \
--model_filename model.pdmodel \
--params_filename model.pdiparams \
--opset_version 16 \
--save_file ./output_inference/rtdetr_r50vd_6x_coco/rtdetr_r50vd_6x_coco.onnx

$ pip3 install -U pip && pip3 install onnxsim
$ onnxsim input_onnx_model output_onnx_model

# Check the converted model [Option]
$ pip install netron

```

## Python 🐍

```bash
$ git clone https://github.com/CVHub520/rtdetr-onnxruntime-deploy.git
$ cd rtdetr-onnxruntime-deploy
$ mkdir weights && cd weights
$ wget https://github.com/CVHub520/rtdetr-onnxruntime-deploy/releases/download/v1.0.0/rtdetr_r50vd_6x_coco_cvhub.onnx
$ cd ../python
$ python3 main.py
```

## C++ πŸ€–

```bash
$ cd rtdetr-onnxruntime-deploy
$ mkdir weights && cd weights
$ wget https://github.com/CVHub520/rtdetr-onnxruntime-deploy/releases/download/v1.0.0/rtdetr_r50vd_6x_coco_cvhub.onnx
$ cd ../cplusplus
```

NOTE: To build the project, ensure that onnxruntime and opencv are correctly installed. Then, run the commands as instructed. Don’t forget to update the ONNXRUNTIME_DIR and OpenCV_DIR cmake options in the CMakeLists.txt file to match your custom environment.

```bash
$ mkdir build && cd build
$ cmake ..
$ make
$ ./main
# ./main --use_cuda
```

## Demo 🎬

| Python | C++ |
|:---:|:---:|
| ![](./images/bus_python_result.jpg) | ![](./images/bus_cpp_result.jpg) |

## Contact πŸ‘‹

Please feel free to use this project as a starting point for your own deployment needs, or as a reference for learning purposes. If you have any questions or suggestions, please don't hesitate to raise an issue or submit a pull request.

| Platform | Account |
| --- | --- |
| Wechat πŸ’¬ | cv_huber |
| Zhihu 🧠 | [CVHub](https://www.zhihu.com/people/cvhub-40) |
| CSDN πŸ“š | [CVHub](https://blog.csdn.net/CVHub?spm=1010.2135.3001.5343) |
| Github 🐱 | [CVHub](https://github.com/CVHub520) |

![](./images/contact.png)