├── .gitignore
├── system_drawing.png
├── deepstream-rtspsrc-yolo-app
├── common
└── includes
│ ├── nvdsgstutils.h
│ ├── deepstream_config.h
│ ├── deepstream_common.h
│ └── gst-nvdssr.h
├── yolo
├── nvdsinfer_custom_impl_Yolo
│ ├── Makefile
│ ├── kernels.cu
│ ├── trt_utils.h
│ ├── yolo.h
│ ├── yoloPlugins.cpp
│ ├── nvdsinfer_yolo_engine.cpp
│ ├── yoloPlugins.h
│ ├── trt_utils.cpp
│ ├── yolo.cpp
│ └── nvdsparsebbox_Yolo.cpp
└── README
├── Makefile
├── config
└── pgie_config.txt
├── src
├── main.h
└── deepstream_rtspsrc_yolo.cpp
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.so
3 | *.onnx
4 | *.engine
5 | *.mp4
6 | *.sh
--------------------------------------------------------------------------------
/system_drawing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/belarbi2733/deepstream-rtspsrc-yolo/HEAD/system_drawing.png
--------------------------------------------------------------------------------
/deepstream-rtspsrc-yolo-app:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/belarbi2733/deepstream-rtspsrc-yolo/HEAD/deepstream-rtspsrc-yolo-app
--------------------------------------------------------------------------------
/common/includes/nvdsgstutils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 | *
4 | * NVIDIA Corporation and its licensors retain all intellectual property
5 | * and proprietary rights in and to this software, related documentation
6 | * and any modifications thereto. Any use, reproduction, disclosure or
7 | * distribution of this software and related documentation without an express
8 | * license agreement from NVIDIA Corporation is strictly prohibited.
9 | */
10 |
11 | /**
12 | * @file
13 | * Defines NVIDIA DeepStream GStreamer Utilities
14 | *
15 | * @b Description: This file specifies the NVIDIA DeepStream GStreamer utility
16 | * functions.
17 | *
18 | */
19 | /**
20 | * @defgroup gstreamer_utils Utilities: Gstreamer utilities API
21 | *
22 | * Specifies GStreamer utilities functions, used to configure the source to generate NTP Sync values.
23 | *
24 | * @ingroup NvDsUtilsApi
25 | * @{
26 | */
27 | #ifndef __NVDS_GSTUTILS_H__
28 | #define __NVDS_GSTUTILS_H__
29 |
30 | #include
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 | #include
36 |
37 | /**
38 | * Configure the source to generate NTP sync values for RTSP sources.
39 | *
40 | * These values are used by the DeepStream GStreamer element NvStreamMux to
41 | * calculate the NTP time of the frames at the source.
42 | *
43 | * This functionality is dependent on the RTSP sending the RTCP Sender Reports.
44 | * source.
45 | *
46 | * This function only works for RTSP sources i.e. GStreamer elements "rtspsrc"
47 | * or "uridecodebin" with an RTSP uri.
48 | *
49 | * params[in] src_elem GStreamer source element to be configured.
50 | */
51 | void configure_source_for_ntp_sync (GstElement *src_elem);
52 |
53 | #ifdef __cplusplus
54 | }
55 | #endif
56 |
57 | #endif
58 |
59 | /** @} */
--------------------------------------------------------------------------------
/yolo/nvdsinfer_custom_impl_Yolo/Makefile:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 | #
4 | # Permission is hereby granted, free of charge, to any person obtaining a
5 | # copy of this software and associated documentation files (the "Software"),
6 | # to deal in the Software without restriction, including without limitation
7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | # and/or sell copies of the Software, and to permit persons to whom the
9 | # Software is furnished to do so, subject to the following conditions:
10 | #
11 | # The above copyright notice and this permission notice shall be included in
12 | # all copies or substantial portions of the Software.
13 | #
14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | # DEALINGS IN THE SOFTWARE.
21 | ################################################################################
22 |
23 | CUDA_VER:=10.2
24 | NVDS_VERSION:=5.0
25 |
26 | CC:= g++
27 | NVCC:=/usr/local/cuda-$(CUDA_VER)/bin/nvcc
28 |
29 | CFLAGS:= -Wall -std=c++11 -shared -fPIC -Wno-error=deprecated-declarations
30 | CFLAGS+= -I/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/sources/includes -I/usr/local/cuda-$(CUDA_VER)/include
31 |
32 | LIBS:= -lnvinfer_plugin -lnvinfer -lnvparsers -L/usr/local/cuda-$(CUDA_VER)/lib64 -lcudart -lcublas -lstdc++fs
33 | LFLAGS:= -shared -Wl,--start-group $(LIBS) -Wl,--end-group
34 |
35 | INCS:= $(wildcard *.h)
36 | SRCFILES:= nvdsinfer_yolo_engine.cpp \
37 | nvdsparsebbox_Yolo.cpp \
38 | yoloPlugins.cpp \
39 | trt_utils.cpp \
40 | yolo.cpp \
41 | kernels.cu
42 | TARGET_LIB:= libnvdsinfer_custom_impl_Yolo.so
43 |
44 | TARGET_OBJS:= $(SRCFILES:.cpp=.o)
45 | TARGET_OBJS:= $(TARGET_OBJS:.cu=.o)
46 |
47 | all: $(TARGET_LIB)
48 |
49 | %.o: %.cpp $(INCS) Makefile
50 | $(CC) -c -o $@ $(CFLAGS) $<
51 |
52 | %.o: %.cu $(INCS) Makefile
53 | $(NVCC) -c -o $@ --compiler-options '-fPIC' $<
54 |
55 | $(TARGET_LIB) : $(TARGET_OBJS)
56 | $(CC) -o $@ $(TARGET_OBJS) $(LFLAGS)
57 |
58 | clean:
59 | rm -rf $(TARGET_LIB)
60 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
3 | #
4 | # Permission is hereby granted, free of charge, to any person obtaining a
5 | # copy of this software and associated documentation files (the "Software"),
6 | # to deal in the Software without restriction, including without limitation
7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | # and/or sell copies of the Software, and to permit persons to whom the
9 | # Software is furnished to do so, subject to the following conditions:
10 | #
11 | # The above copyright notice and this permission notice shall be included in
12 | # all copies or substantial portions of the Software.
13 | #
14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | # DEALINGS IN THE SOFTWARE.
21 | ################################################################################
22 |
23 | CUDA_VER?=
24 | ifeq ($(CUDA_VER),)
25 | $(error "CUDA_VER is not set")
26 | endif
27 |
28 | APP:= deepstream-rtspsrc-yolo-app
29 | CC = g++
30 | TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)
31 |
32 | NVDS_VERSION:=5.0
33 |
34 | LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/
35 | APP_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/bin/
36 |
37 | SRCS:= $(wildcard src/*.cpp)
38 | INCS:= $(wildcard *.h)
39 | INCS:= $(wildcard common/includes/*.h)
40 |
41 | ifeq ($(TARGET_DEVICE),aarch64)
42 | PKGS:= gstreamer-1.0 opencv4 gstreamer-video-1.0 x11 gstreamer-rtsp-1.0
43 | else
44 | PKGS:= gstreamer-1.0 opencv gstreamer-video-1.0 x11 gstreamer-rtsp-1.0
45 | endif
46 |
47 | CFLAGS:= -fPIC -std=c++11 \
48 | -I /opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/sources/includes \
49 | -I /usr/local/cuda-$(CUDA_VER)/include
50 |
51 | CFLAGS+= `pkg-config --cflags $(PKGS)`
52 | LIBS:= `pkg-config --libs $(PKGS)`
53 |
54 | LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_meta -lnvds_meta -lnvds_inferutils -lnvds_utils -lnvdsgst_helper -lm \
55 | -lgstrtspserver-1.0 -ldl -L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart \
56 | -Wl,-rpath,$(LIB_INSTALL_DIR)
57 |
58 | ifeq ($(TARGET_DEVICE),aarch64)
59 | CFLAGS+= -DPLATFORM_TEGRA
60 | SRCS+=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/sources/libs/nvdsinfer_customparser/nvdsinfer_custombboxparser.cpp
61 | else
62 | LIBS+= -L$(LIB_INSTALL_DIR) -lnvds_infercustomparser
63 | endif
64 |
65 | OBJS:= $(SRCS:.cpp=.o)
66 |
67 | all: $(APP)
68 |
69 | %.o: %.cpp $(INCS) Makefile
70 | $(CC) -c -o $@ $(CFLAGS) $<
71 |
72 | $(APP): $(OBJS) Makefile
73 | $(CC) -o $(APP) $(OBJS) $(LIBS)
74 |
75 | install: $(APP)
76 | cp -rv $(APP) $(APP_INSTALL_DIR)
77 |
78 | clean:
79 | rm -rf $(OBJS) $(APP)
80 |
--------------------------------------------------------------------------------
/common/includes/deepstream_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | #ifndef __NVGSTDS_CONFIG_H__
24 | #define __NVGSTDS_CONFIG_H__
25 |
26 | #ifdef __aarch64__
27 | #define IS_TEGRA
28 | #endif
29 |
30 | #define MEMORY_FEATURES "memory:NVMM"
31 |
32 | #ifdef IS_TEGRA
33 | #define NVDS_ELEM_SRC_CAMERA_CSI "nvarguscamerasrc"
34 | #else
35 | #define NVDS_ELEM_SRC_CAMERA_CSI "videotestsrc"
36 | #endif
37 | #define NVDS_ELEM_SRC_CAMERA_V4L2 "v4l2src"
38 | #define NVDS_ELEM_SRC_URI "uridecodebin"
39 | #define NVDS_ELEM_SRC_MULTIFILE "multifilesrc"
40 | #define NVDS_ELEM_SRC_ALSA "alsasrc"
41 |
42 | #define NVDS_ELEM_DECODEBIN "decodebin"
43 | #define NVDS_ELEM_WAVPARSE "wavparse"
44 |
45 | #define NVDS_ELEM_QUEUE "queue"
46 | #define NVDS_ELEM_CAPS_FILTER "capsfilter"
47 | #define NVDS_ELEM_TEE "tee"
48 |
49 | #define NVDS_ELEM_PGIE "nvinfer"
50 | #define NVDS_ELEM_SGIE "nvinfer"
51 | #define NVDS_ELEM_INFER_SERVER "nvinferserver"
52 | #define NVDS_ELEM_TRACKER "nvtracker"
53 |
54 | #define NVDS_ELEM_VIDEO_CONV "nvvideoconvert"
55 | #define NVDS_ELEM_STREAM_MUX "nvstreammux"
56 | #define NVDS_ELEM_STREAM_DEMUX "nvstreamdemux"
57 | #define NVDS_ELEM_TILER "nvmultistreamtiler"
58 | #define NVDS_ELEM_OSD "nvdsosd"
59 | #define NVDS_ELEM_DSANALYTICS_ELEMENT "nvdsanalytics"
60 | #define NVDS_ELEM_DSEXAMPLE_ELEMENT "dsexample"
61 |
62 | #define NVDS_ELEM_DEWARPER "nvdewarper"
63 | #define NVDS_ELEM_SPOTANALYSIS "nvspot"
64 | #define NVDS_ELEM_NVAISLE "nvaisle"
65 | #define NVDS_ELEM_BBOXFILTER "nvbboxfilter"
66 | #define NVDS_ELEM_MSG_CONV "nvmsgconv"
67 | #define NVDS_ELEM_MSG_BROKER "nvmsgbroker"
68 |
69 | #define NVDS_ELEM_SINK_FAKESINK "fakesink"
70 | #define NVDS_ELEM_SINK_FILE "filesink"
71 | #define NVDS_ELEM_SINK_EGL "nveglglessink"
72 |
73 | #define NVDS_ELEM_SINK_OVERLAY "nvoverlaysink"
74 | #define NVDS_ELEM_EGLTRANSFORM "nvegltransform"
75 |
76 | #define NVDS_ELEM_MUX_MP4 "qtmux"
77 | #define NVDS_ELEM_MKV "matroskamux"
78 |
79 | #define NVDS_ELEM_ENC_H264_HW "nvv4l2h264enc"
80 | #define NVDS_ELEM_ENC_H265_HW "nvv4l2h265enc"
81 | #define NVDS_ELEM_ENC_MPEG4 "avenc_mpeg4"
82 |
83 | #define NVDS_ELEM_ENC_H264_SW "x264enc"
84 | #define NVDS_ELEM_ENC_H265_SW "x265enc"
85 |
86 | #define MAX_SOURCE_BINS 1024
87 | #define MAX_SINK_BINS (1024)
88 | #define MAX_SECONDARY_GIE_BINS (16)
89 | #define MAX_MESSAGE_CONSUMERS (16)
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/yolo/nvdsinfer_custom_impl_Yolo/kernels.cu:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved.
3 | *
4 | * NVIDIA Corporation and its licensors retain all intellectual property
5 | * and proprietary rights in and to this software, related documentation
6 | * and any modifications thereto. Any use, reproduction, disclosure or
7 | * distribution of this software and related documentation without an express
8 | * license agreement from NVIDIA Corporation is strictly prohibited.
9 | *
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | inline __device__ float sigmoidGPU(const float& x) { return 1.0f / (1.0f + __expf(-x)); }
19 |
20 | __global__ void gpuYoloLayerV3(const float* input, float* output, const uint gridSize, const uint numOutputClasses,
21 | const uint numBBoxes)
22 | {
23 | uint x_id = blockIdx.x * blockDim.x + threadIdx.x;
24 | uint y_id = blockIdx.y * blockDim.y + threadIdx.y;
25 | uint z_id = blockIdx.z * blockDim.z + threadIdx.z;
26 |
27 | if ((x_id >= gridSize) || (y_id >= gridSize) || (z_id >= numBBoxes))
28 | {
29 | return;
30 | }
31 |
32 | const int numGridCells = gridSize * gridSize;
33 | const int bbindex = y_id * gridSize + x_id;
34 |
35 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]
36 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]);
37 |
38 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]
39 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]);
40 |
41 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]
42 | = __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]);
43 |
44 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]
45 | = __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]);
46 |
47 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]
48 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]);
49 |
50 | for (uint i = 0; i < numOutputClasses; ++i)
51 | {
52 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]
53 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]);
54 | }
55 | }
56 |
57 | cudaError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize,
58 | const uint& numOutputClasses, const uint& numBBoxes,
59 | uint64_t outputSize, cudaStream_t stream);
60 |
61 | cudaError_t cudaYoloLayerV3(const void* input, void* output, const uint& batchSize, const uint& gridSize,
62 | const uint& numOutputClasses, const uint& numBBoxes,
63 | uint64_t outputSize, cudaStream_t stream)
64 | {
65 | dim3 threads_per_block(16, 16, 4);
66 | dim3 number_of_blocks((gridSize / threads_per_block.x) + 1,
67 | (gridSize / threads_per_block.y) + 1,
68 | (numBBoxes / threads_per_block.z) + 1);
69 | for (unsigned int batch = 0; batch < batchSize; ++batch)
70 | {
71 | gpuYoloLayerV3<<>>(
72 | reinterpret_cast(input) + (batch * outputSize),
73 | reinterpret_cast(output) + (batch * outputSize), gridSize, numOutputClasses,
74 | numBBoxes);
75 | }
76 | return cudaGetLastError();
77 | }
78 |
--------------------------------------------------------------------------------
/yolo/nvdsinfer_custom_impl_Yolo/trt_utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 |
24 | #ifndef __TRT_UTILS_H__
25 | #define __TRT_UTILS_H__
26 |
27 | #include
28 | #include