ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.97k stars 16.4k forks source link

C++ inference pipeline for TensorRT #7892

Closed pk-cb closed 2 years ago

pk-cb commented 2 years ago

Hi, Is there a inference pipeline written in C++ as well similar to detect.py in python3. I am running the model on a jetson nano, and wanted to use C++ tensorrt api for inference and pre/post processing.

Thanks

github-actions[bot] commented 2 years ago

👋 Hello @pk-cb, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

JWLee89 commented 2 years ago

If you want an inference pipeline written in C++, I recommend checking out Nvidia's DeepStream: https://developer.nvidia.com/deepstream-sdk Nvidia DeepStream is designed to run on edge devices such as Jetson Nano or Xavier. It can also run on a standard dGPU server.

The inference pipeline is based off Gstreamer ( https://gstreamer.freedesktop.org/ ) and once you serialize your model into TensorRT format, you can run the object detection model on the pipeline, provided that you write the bounding box parsing algorithm.

Some open-source work that you can take a look at for bounding box parsing is DeepStream-yolo: https://github.com/marcoslucianops/DeepStream-Yolo

For DeepStream Application references in C++, take a look at: https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps

If you are more used to Python, DeepStream also supports python bindings. Examples can be found here: https://github.com/NVIDIA-AI-IOT/deepstream_python_apps

JWLee89 commented 2 years ago

If you just want the model outputs, but want to do the inference via the TensorRT API, you can simply use torch2trt (link: https://github.com/NVIDIA-AI-IOT/torch2trt) which will run the model on TensorRT. That will allow you to do your own pre / post-processing

zhiqwang commented 2 years ago

FYI @pk-cb and @JWLee89 , cc @glenn-jocher ,

Just for the post-processing, you can use the EfficientNMS_TRT plugin provided by TensorRT, see #6430 for more details. And you can rewrite the OpenCV Python interface to C++ like here for the pre-processing. (It would be better if we could do the pre-processing on deepstream-sdk.)

And there is a PR for registering the EfficientNMS_TRT plugin to YOLOv5 at #7736 , I guess you can do C++ inference on TensorRT with totally following example https://github.com/zhiqwang/yolov5-rt-stack/tree/main/deployment/tensorrt after #7736 is merged.

github-actions[bot] commented 2 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

glenn-jocher commented 1 year ago

@zhiqwang thanks for the suggestion! We've recently added torch2trt, a handy tool for seamless inference via the TensorRT API, perfect for custom pre/post-processing work. Stay tuned for EfficientNMS_TRT plugin integration with yolo5 for streamlined inference. For further assistance, feel free to check the Ultralytics Docs (https://docs.ultralytics.com/yolov5/) or reach out here!