From 3f14b0d95de5d5f0f32bb31e2e79b267be44d63d Mon Sep 17 00:00:00 2001 From: Marcos Luciano Date: Wed, 31 May 2023 15:58:17 -0300 Subject: [PATCH] Add DeepStream 5.1 support --- README.md | 45 +++++++++++++++++++++- docs/DAMOYOLO.md | 18 +++++++++ docs/PPYOLOE.md | 18 +++++++++ docs/YOLONAS.md | 18 +++++++++ docs/YOLOR.md | 18 +++++++++ docs/YOLOX.md | 18 +++++++++ docs/YOLOv5.md | 18 +++++++++ docs/YOLOv6.md | 18 +++++++++ docs/YOLOv7.md | 18 +++++++++ docs/YOLOv8.md | 18 +++++++++ nvdsinfer_custom_impl_Yolo/Makefile | 11 +++++- nvdsinfer_custom_impl_Yolo/yolo.cpp | 13 ++++++- nvdsinfer_custom_impl_Yolo/yoloPlugins.cpp | 5 +++ nvdsinfer_custom_impl_Yolo/yoloPlugins.h | 4 ++ 14 files changed, 236 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9635023..536117d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DeepStream-Yolo -NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO models +NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 / 5.1 configuration for YOLO models -------------------------------------------------------------------------------------------------- ### Important: please generate the ONNX model and the TensorRT engine again with the updated files @@ -21,8 +21,9 @@ NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO mod * Models benchmarks * **Support for Darknet YOLO models (YOLOv4, etc) using cfg and weights conversion with GPU post-processing** * **Support for YOLO-NAS, PPYOLOE+, PPYOLOE, DAMO-YOLO, YOLOX, YOLOR, YOLOv8, YOLOv7, YOLOv6 and YOLOv5 using ONNX conversion with GPU post-processing** -* **Add GPU bbox parser (it is slightly slower than CPU bbox parser on V100 GPU tests)** +* **GPU bbox parser (it is slightly slower than CPU bbox parser on V100 GPU tests)** * **Dynamic batch-size for ONNX exported models (YOLO-NAS, PPYOLOE+, PPYOLOE, DAMO-YOLO, YOLOX, YOLOR, YOLOv8, YOLOv7, YOLOv6 and YOLOv5)** +* **Support for DeepStream 5.1** ## @@ -92,6 +93,16 @@ NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO mod * [GStreamer 1.14.5](https://gstreamer.freedesktop.org/) * [DeepStream-Yolo](https://github.com/marcoslucianops/DeepStream-Yolo) +#### DeepStream 5.1 on x86 platform + +* [Ubuntu 18.04](https://releases.ubuntu.com/18.04.6/) +* [CUDA 11.1](https://developer.nvidia.com/cuda-11.1.0-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal) +* [TensorRT 7.2.2](https://developer.nvidia.com/nvidia-tensorrt-7x-download) +* [NVIDIA Driver 460.32.03](https://www.nvidia.com.br/Download/index.aspx) +* [NVIDIA DeepStream SDK 5.1](https://developer.nvidia.com/deepstream-sdk-download-tesla-archived) +* [GStreamer 1.14.5](https://gstreamer.freedesktop.org/) +* [DeepStream-Yolo](https://github.com/marcoslucianops/DeepStream-Yolo) + #### DeepStream 6.2 on Jetson platform * [JetPack 5.1.1 / 5.1](https://developer.nvidia.com/embedded/jetpack) @@ -116,6 +127,12 @@ NVIDIA DeepStream SDK 6.2 / 6.1.1 / 6.1 / 6.0.1 / 6.0 configuration for YOLO mod * [NVIDIA DeepStream SDK 6.0.1 / 6.0](https://developer.nvidia.com/embedded/deepstream-on-jetson-downloads-archived) * [DeepStream-Yolo](https://github.com/marcoslucianops/DeepStream-Yolo) +#### DeepStream 5.1 on Jetson platform + +* [JetPack 4.5.1](https://developer.nvidia.com/embedded/jetpack-sdk-451-archive) +* [NVIDIA DeepStream SDK 5.1](https://developer.nvidia.com/embedded/deepstream-on-jetson-downloads-archived) +* [DeepStream-Yolo](https://github.com/marcoslucianops/DeepStream-Yolo) + ## ### Suported models @@ -950,6 +967,12 @@ cd DeepStream-Yolo CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -962,6 +985,12 @@ cd DeepStream-Yolo CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + #### 4. Edit the `config_infer_primary.txt` file according to your model (example for YOLOv4) ``` @@ -1073,6 +1102,12 @@ sudo apt-get install libopencv-dev CUDA_VER=11.4 OPENCV=1 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 OPENCV=1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -1085,6 +1120,12 @@ sudo apt-get install libopencv-dev CUDA_VER=10.2 OPENCV=1 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 OPENCV=1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + #### 3. For COCO dataset, download the [val2017](https://drive.google.com/file/d/1gbvfn7mcsGDRZ_luJwtITL-ru2kK99aK/view?usp=sharing), extract, and move to DeepStream-Yolo folder * Select 1000 random images from COCO dataset to run calibration diff --git a/docs/DAMOYOLO.md b/docs/DAMOYOLO.md index 2c352ea..e55b49a 100644 --- a/docs/DAMOYOLO.md +++ b/docs/DAMOYOLO.md @@ -43,6 +43,12 @@ Generate the ONNX model file (example for DAMO-YOLO-S*) python3 export_damoyolo.py -w damoyolo_tinynasL25_S_477.pth -c configs/damoyolo_tinynasL25_S.py --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 11 or lower. + +``` +--opset 11 +``` + **NOTE**: To change the inference size (defaut: 640) ``` @@ -98,6 +104,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -110,6 +122,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_damoyolo file diff --git a/docs/PPYOLOE.md b/docs/PPYOLOE.md index bb4672b..cd61bf1 100644 --- a/docs/PPYOLOE.md +++ b/docs/PPYOLOE.md @@ -41,6 +41,12 @@ pip3 install onnx onnxsim onnxruntime python3 export_ppyoloe.py -w ppyoloe_plus_crn_s_80e_coco.pdparams -c configs/ppyoloe/ppyoloe_plus_crn_s_80e_coco.yml --simplify ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 11. + +``` +--opset 12 +``` + #### 5. Copy generated files Copy the generated ONNX model file and labels.txt file (if generated) to the `DeepStream-Yolo` folder. @@ -75,6 +81,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -87,6 +99,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_ppyoloe_plus file diff --git a/docs/YOLONAS.md b/docs/YOLONAS.md index 3b7badf..a28172e 100644 --- a/docs/YOLONAS.md +++ b/docs/YOLONAS.md @@ -46,6 +46,12 @@ Generate the ONNX model file (example for YOLO-NAS S) python3 export_yolonas.py -m yolo_nas_s -w yolo_nas_s_coco.pth --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 14. + +``` +--opset 12 +``` + **NOTE**: Model names ``` @@ -119,6 +125,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -131,6 +143,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_yolonas file diff --git a/docs/YOLOR.md b/docs/YOLOR.md index 600c42f..bfa28c7 100644 --- a/docs/YOLOR.md +++ b/docs/YOLOR.md @@ -55,6 +55,12 @@ Generate the ONNX model file python3 export_yolor.py -w yolor-p6.pt --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 12. + +``` +--opset 12 +``` + **NOTE**: To convert a P6 model ``` @@ -116,6 +122,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -128,6 +140,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_yolor file diff --git a/docs/YOLOX.md b/docs/YOLOX.md index ffabc4d..2b719e9 100644 --- a/docs/YOLOX.md +++ b/docs/YOLOX.md @@ -46,6 +46,12 @@ Generate the ONNX model file (example for YOLOX-s) python3 export_yolox.py -w yolox_s.pth -c exps/default/yolox_s.py --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 11. + +``` +--opset 12 +``` + #### 5. Copy generated file Copy the generated ONNX model file to the `DeepStream-Yolo` folder. @@ -80,6 +86,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -92,6 +104,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_yolox file diff --git a/docs/YOLOv5.md b/docs/YOLOv5.md index 6e06eeb..66a0309 100644 --- a/docs/YOLOv5.md +++ b/docs/YOLOv5.md @@ -47,6 +47,12 @@ Generate the ONNX model file (example for YOLOv5s) python3 export_yoloV5.py -w yolov5s.pt --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 17. + +``` +--opset 12 +``` + **NOTE**: To convert a P6 model ``` @@ -108,6 +114,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -120,6 +132,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_yoloV5 file diff --git a/docs/YOLOv6.md b/docs/YOLOv6.md index 7d77726..38d70f1 100644 --- a/docs/YOLOv6.md +++ b/docs/YOLOv6.md @@ -47,6 +47,12 @@ Generate the ONNX model file (example for YOLOv6-S 4.0) python3 export_yoloV6.py -w yolov6s.pt --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 13. + +``` +--opset 12 +``` + **NOTE**: To convert a P6 model ``` @@ -108,6 +114,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -120,6 +132,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_yoloV6 file diff --git a/docs/YOLOv7.md b/docs/YOLOv7.md index b046520..d75cde4 100644 --- a/docs/YOLOv7.md +++ b/docs/YOLOv7.md @@ -49,6 +49,12 @@ Generate the ONNX model file (example for YOLOv7) python3 export_yoloV7.py -w yolov7.pt --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 12. + +``` +--opset 12 +``` + **NOTE**: To convert a P6 model ``` @@ -110,6 +116,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -122,6 +134,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_yoloV7 file diff --git a/docs/YOLOv8.md b/docs/YOLOv8.md index 0239573..64955d7 100644 --- a/docs/YOLOv8.md +++ b/docs/YOLOv8.md @@ -46,6 +46,12 @@ Generate the ONNX model file (example for YOLOv8s) python3 export_yoloV8.py -w yolov8s.pt --simplify --dynamic ``` +**NOTE**: If you are using DeepStream 5.1, use opset 12 or lower. The default opset is 16. + +``` +--opset 12 +``` + **NOTE**: To change the inference size (defaut: 640) ``` @@ -101,6 +107,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=11.4 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on x86 platform + + ``` + CUDA_VER=11.1 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + * DeepStream 6.2 / 6.1.1 / 6.1 on Jetson platform ``` @@ -113,6 +125,12 @@ Open the `DeepStream-Yolo` folder and compile the lib CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo ``` +* DeepStream 5.1 on Jetson platform + + ``` + CUDA_VER=10.2 LEGACY=1 make -C nvdsinfer_custom_impl_Yolo + ``` + ## ### Edit the config_infer_primary_yoloV8 file diff --git a/nvdsinfer_custom_impl_Yolo/Makefile b/nvdsinfer_custom_impl_Yolo/Makefile index 9d7316d..f22527f 100644 --- a/nvdsinfer_custom_impl_Yolo/Makefile +++ b/nvdsinfer_custom_impl_Yolo/Makefile @@ -33,6 +33,11 @@ ifeq ($(OPENCV),) OPENCV=0 endif +LEGACY?= +ifeq ($(LEGACY),) + LEGACY=0 +endif + CC:= g++ NVCC:=/usr/local/cuda-$(CUDA_VER)/bin/nvcc @@ -40,11 +45,15 @@ CFLAGS:= -Wall -std=c++11 -shared -fPIC -Wno-error=deprecated-declarations CFLAGS+= -I/opt/nvidia/deepstream/deepstream/sources/includes -I/usr/local/cuda-$(CUDA_VER)/include ifeq ($(OPENCV), 1) - COMMON= -DOPENCV + COMMON+= -DOPENCV CFLAGS+= $(shell pkg-config --cflags opencv4 2> /dev/null || pkg-config --cflags opencv) LIBS+= $(shell pkg-config --libs opencv4 2> /dev/null || pkg-config --libs opencv) endif +ifeq ($(LEGACY), 1) + COMMON+= -DLEGACY +endif + CUFLAGS:= -I/opt/nvidia/deepstream/deepstream/sources/includes -I/usr/local/cuda-$(CUDA_VER)/include LIBS+= -lnvinfer_plugin -lnvinfer -lnvparsers -L/usr/local/cuda-$(CUDA_VER)/lib64 -lcudart -lcublas -lstdc++fs diff --git a/nvdsinfer_custom_impl_Yolo/yolo.cpp b/nvdsinfer_custom_impl_Yolo/yolo.cpp index 7ed490a..3f39d59 100644 --- a/nvdsinfer_custom_impl_Yolo/yolo.cpp +++ b/nvdsinfer_custom_impl_Yolo/yolo.cpp @@ -54,7 +54,13 @@ Yolo::createEngine(nvinfer1::IBuilder* builder, nvinfer1::IBuilderConfig* config nvinfer1::INetworkDefinition *network = builder->createNetworkV2(0); if (parseModel(*network) != NVDSINFER_SUCCESS) { + +#ifdef LEGACY + network->destroy(); +#else delete network; +#endif + return nullptr; } @@ -105,7 +111,12 @@ Yolo::createEngine(nvinfer1::IBuilder* builder, nvinfer1::IBuilderConfig* config else std::cerr << "Building engine failed\n" << std::endl; - delete network; +#ifdef LEGACY + network->destroy(); +#else + delete network; +#endif + return engine; } diff --git a/nvdsinfer_custom_impl_Yolo/yoloPlugins.cpp b/nvdsinfer_custom_impl_Yolo/yoloPlugins.cpp index 633d336..4f54a1f 100644 --- a/nvdsinfer_custom_impl_Yolo/yoloPlugins.cpp +++ b/nvdsinfer_custom_impl_Yolo/yoloPlugins.cpp @@ -120,9 +120,14 @@ YoloLayer::configureWithFormat(const nvinfer1::Dims* inputDims, int nbInputs, co assert(inputDims != nullptr); } +#ifdef LEGACY +int +YoloLayer::enqueue(int batchSize, const void* const* inputs, void** outputs, void* workspace, cudaStream_t stream) +#else int32_t YoloLayer::enqueue(int batchSize, void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept +#endif { void* output = outputs[0]; CUDA_CHECK(cudaMemsetAsync((float*) output, 0, sizeof(float) * m_OutputSize * 6 * batchSize, stream)); diff --git a/nvdsinfer_custom_impl_Yolo/yoloPlugins.h b/nvdsinfer_custom_impl_Yolo/yoloPlugins.h index e2e711f..e586b7e 100644 --- a/nvdsinfer_custom_impl_Yolo/yoloPlugins.h +++ b/nvdsinfer_custom_impl_Yolo/yoloPlugins.h @@ -71,8 +71,12 @@ class YoloLayer : public nvinfer1::IPluginV2 { return maxBatchSize * sizeof(int); } +#ifdef LEGACY + int enqueue(int batchSize, const void* const* inputs, void** outputs, void* workspace, cudaStream_t stream) override; +#else int32_t enqueue(int batchSize, void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept override; +#endif size_t getSerializationSize() const noexcept override;