Using YOLOv4 on NVIDIA DeepStream 5.0
This article will guide you to install and use Yolo-v4 on NVIDIA DeepStream 5.0. If you are new to NVIDIA DeepStream 5.0 kindly follow my previous article link.
I assume you already aware of YOLOv4. It’s claims to have state-of-the-art accuracy while maintains a high processing frame rate. It achieves an accuracy of 43.5% AP (65.7% AP₅₀) for the MS COCO with an approximately 65 FPS inference speed on Tesla V100. You can find more information on YOLOv4 on this link.
Now introduction is over, Lets jump directly into installation.
Prerequisites
- Hardware Platform (Jetson or GPU)
- DeepStream Version 5.0
- TensorRT Version 7.0.0.11
- NVIDIA GPU Driver Version (valid for GPU only) 440.33.01
- OS Ubuntu 18.04
- CUDA 10.2
- Pytorch 1.4.0
At present DeepStream 5.0 not support YOLOv4. But they gave the steps to use YOLOv4. Thanks to NVIDIA officials and Community.
Pytorch or DarkNet → ONNX →TensorRT → Deepstream
DarkNet to ONNX
git clone https://github.com/Tianxiaomo/pytorch-YOLOv4.git
cd pytorch-YOLOv4
pip install onnxruntime
download pretrained YOLOv4 weights and cfg file here . If you want to convert Pytorch to ONNX, follow the steps in the repository.
python demo_darknet2onnx.py yolov4.cfg yolov4.weights ./data/giraffe.jpg 1
ONNX to TensorRT
Before running the below command, change the parameter for your configuration.
trtexec --onnx=<onnx_file> --explicitBatch --saveEngine=<tensorRT_engine_file> --workspace=<size_in_megabytes> --fp16
Example:
trtexec --onnx=yolov4_1_3_608_608.onnx --explicitBatch --saveEngine=yolov4_1_3_608_608_fp16.engine --workspace=4096 --fp16
if you get trtexec command not found issue. Try to give explicit path /usr/src/tensorrt/bin/trtexec
Rebuild
- Add following C++ functions into
objectDetector_Yolo/nvdsinfer_custom_impl_Yolo/nvdsparsebbox_Yolo.cpp
and rebuildlibnvdsinfer_custom_impl_Yolo.so
cd /opt/nvidia/deepstream/deepstream-5.0/sources/objectDetector_Yolo/nvdsinfer_custom_impl_Yolomake clean
make
Here are YOLOv4 configuration files for you as references
- config_infer_primary_yoloV4.txt
- deepstream_app_config_yoloV4.txt
Run the app
deepstream-app -c ./deepstream_app_config_yoloV4.txt
Output
References
[1] https://github.com/AlexeyAB/darknet
[2] https://github.com/Tianxiaomo/pytorch-YOLOv4
Thanks for reading.
If you have any suggestions/Questions kindly let us know in the comments section!