DeepStream進階插件之路

一、DeepStream的gst插件

gst插件,即GStreamer插件,是用於實現DeepStream功能嵌入GStreamer編解碼流程使用。

GStreamer插件:

GStreamer是用於插件,數據流和媒體類型處理/協商的框架。它用於創建流媒體應用程序。插件是在運行時動態加載的共享庫,可以獨立擴展和升級。當安排並鏈接在一起時,插件形成處理流水線,該流水線定義了流媒體應用程序的數據流。您可以通過其廣泛的在線文檔,從“什麼是GStreamer?”開始瞭解有關GStreamer的更多信息。

開源GStreamer插件:

  • GstFileSrc-從文件中讀取數據:視頻數據或圖像。
  • GstH264Parse-解析傳入的H264流。對於H265編解碼器,請使用H265Parse。
  • GstRtpH264Pay-將H264編碼的有效負載轉換爲RTP數據包(RFC 3984)。
  • GstUDPSink-將UDP數據包發送到網絡。與RTP有效負載(GstRtpH264Pay)配對時,它可以實現RTP流。
  • GstCapsFilter-在不修改數據的情況下限制數據格式。
  • GstV4l2Src-從v4l2設備捕獲視頻。
  • GstQTMux-將流(音頻和視頻)合併到QuickTime(.mov)文件中。
  • GstFileSink-將傳入數據寫入本地文件系統中的文件。
  • GstURIDecodeBin-將數據從URI解碼到原始媒體中。它選擇可以處理給定“ uri”方案的源元素,並將其連接到解碼器。
DeepStream的gst插件:

除了在GStreamer框架庫中提供的開源插件之外,DeepStream SDK還包括利用GPU功能的NVIDIA硬件加速插件。有關DeepStream GStreamer插件的完整列表,請參見《 NVIDIA DeepStream插件手冊》。

NVIDIA硬件加速插件:

  • Gst-nvstreammux-在發送AI推理之前批處理流。
  • Gst-nvinfer-使用TensorRT運行推理。
  • Gst-nvvideo4linux2-使用硬件加速解碼器(NVDEC)解碼視頻流;使用硬件加速編碼器(NVENC)將I420格式的RAW數據編碼爲H264或H265輸出視頻流。
  • Gst-nvvideoconvert-執行視頻顏色格式轉換。Gst-nvdsosd插件之前的第一個Gst-nvvideoconvert插件將流數據從I420轉換爲RGBA,Gst-nvdsosd插件將Gst-nvdsosd插件將數據從RGBA轉換爲I420。
  • Gst-nvdsosd-繪製邊界框,文本和關注區域(ROI)多邊形。
  • Gst-nvtracker-跟蹤幀之間的對象。
  • Gst-nvmultistreamtiler-從批處理緩衝區合成2D切片。
  • Gst-nvv4l2decoder-解碼視頻流。
  • Gst-Nvv4l2h264enc-編碼視頻流。
  • Gst-NvArgusCameraSrc-提供使用Argus API控制ISP屬性的選項。
DeepStream SDK

NVIDIA DeepStream SDK是基於開源GStreamer多媒體框架的流分析工具包。DeepStream SDK加快了可伸縮IVA應用程序的開發速度,使開發人員更容易構建核心深度學習網絡,而不必從頭開始設計端到端應用程序。包含NVIDIA Jetson模塊或NVIDIA dGPU適配器的系統均支持該SDK。它由可擴展的硬件加速插件集合組成,這些插件與低級庫進行交互以優化性能,並定義了標準化的元數據結構,可實現自定義/用戶特定的添加。

有關DeepStream SDK的更多詳細信息和說明,請參考以下材料:
NVIDIA DeepStream SDK開發指南
NVIDIA DeepStream插件手冊
NVIDIA DeepStream SDK API參考文檔

二、官方插件

通過gst命令可以查看到有很多nvidia官方插件:

nvidia@nvidia-desktop:~/projects/deepstream-test1-app_toson/build$ gst-inspect-1.0 -a |grep NVIDIA
dsexample:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
dsexample:   Description              NVIDIA example plugin for integration with DeepStream on DGPU
dsexample:   Binary package           NVIDIA DeepStream 3rdparty IP integration example plugin
nvof:   Author                   NVIDIA Corporation. Post on Deepstream for Jetson/Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvof:   Description              NVIDIA opticalflow plugin for integration with DeepStream on DGPU
nvof:   Binary package           NVIDIA DeepStream 3rdparty IP integration opticalflow plugin
nvinfer:   Author                   NVIDIA Corporation. Deepstream for Tesla forum: https://devtalk.nvidia.com/default/board/209
nvinfer:   Description              NVIDIA DeepStreamSDK TensorRT plugin
nvinfer:   Binary package           NVIDIA DeepStreamSDK TensorRT plugin
nvmultistreamtiler:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvmultistreamtiler:   Description              NVIDIA Multistream Tiler plugin
nvmultistreamtiler:   Binary package           NVIDIA Multistream Plugins
nvdewarper:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvsegvisual:   Author                   NVIDIA Corporation. Post on Deepstream for Jetson/Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvsegvisual:   Description              NVIDIA segmentation visualization plugin for integration with DeepStream on DGPU
nvsegvisual:   Binary package           NVIDIA DeepStream Segmantation Visualization Plugin
nvdsosd:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvmsgconv:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvofvisual:   Author                   NVIDIA Corporation. Post on Deepstream for Jetson/Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvofvisual:   Description              NVIDIA opticalflow visualization plugin for integration with DeepStream on DGPU
nvofvisual:   Binary package           NVIDIA DeepStream Optical Flow Visualization Plugin
nvmsgbroker:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvstreamdemux:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvstreamdemux:   Description              NVIDIA Multistream mux/demux plugin
nvstreamdemux:   Binary package           NVIDIA Multistream Plugins
nvstreammux:   Author                   NVIDIA Corporation. Post on Deepstream for Tesla forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvstreammux:   Description              NVIDIA Multistream mux/demux plugin
nvstreammux:   Binary package           NVIDIA Multistream Plugins
nvtracker:   Author                   NVIDIA Corporation. Post on Deepstream SDK forum for any queries @ https://devtalk.nvidia.com/default/board/209/
nvv4l2decoder:   Long-name                NVIDIA v4l2 video decoder

三、開源插件源碼

請參閱官方文檔:https://docs.nvidia.com/metropolis/deepstream/dev-guide/DeepStream%20Development%20Guide/deepstream_custom_plugin.html#wwpID0E0TB0HA

瞭解到有幾個插件源碼,大部分都未開源,暫時可以從僅有的插件入手,如果不能支持則需要自己寫插件就比較繁瑣了。

deepstream開源插件在目錄:/opt/nvidia/deepstream/deepstream-4.0/sources/gst-plugins/

nvidia@nvidia-desktop:/opt/nvidia/deepstream/deepstream-4.0/sources/gst-plugins$ ls
gst-dsexample  gst-nvinfer  gst-nvmsgbroker  gst-nvmsgconv

在這裏插入圖片描述在這裏插入圖片描述

我們可以先從dsexample開始:
/opt/nvidia/deepstream/deepstream-4.0/sources/gst-plugins/gst-dsexample/gstdsexample.cpp

gst-dsexample插件的描述:
GStreamer示例插件(gst-dsexample)演示了以下內容:

  • 處理整個幀,並根據需要進行縮小/顏色轉換。
  • 處理主要檢測器檢測到的對象,特別是從幀中裁剪這些對象,然後進行裁剪。

請參閱官方文檔:https://docs.nvidia.com/metropolis/deepstream/dev-guide/DeepStream%20Development%20Guide/deepstream_custom_plugin.html#wwpID0E0TB0HA

可以使用命令行簡單測試:

#----------------------- use dsexample plugin -----------------------
# use mp4 files
gst-launch-1.0 filesrc location=/opt/nvidia/deepstream/deepstream-4.0/samples/streams/sample_720p.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1280 height=720 ! nvvideoconvert ! dsexample full-frame=1 ! nvdsosd ! nvegltransform ! nveglglessink
# use rtsp camera
gst-launch-1.0 rtspsrc latency=2000 location="rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0" ! rtph264depay ! h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1280 height=720 ! nvvideoconvert ! dsexample full-frame=1 ! nvdsosd ! nvegltransform ! nveglglessink

結果:
(如圖,畫了2個固定不動的框,不明白在表達什麼,可以從gstdsexample.cpp裏去了解,我正在研究中。)
在這裏插入圖片描述

四、我的研究之路

1. nvidia官網教程

《使用NVIDIA DeepStream構建實時修訂應用程序》:
《Building a Real-time Redaction App Using NVIDIA DeepStream, Part 1: Training》
《Building a Real-time Redaction App Using NVIDIA DeepStream, Part 2: Deployment》
Part 1中,學習如何使用ResNet34骨幹訓練RetinaNet網絡以進行對象檢測。這包括使用容器,準備數據集,調整超參數以及訓練模型。
Part 2中,學習如何構建和部署基於AI的實時應用程序。該模型使用DeepStream SDK 部署在NVIDIA Jetson驅動的AGX Xavier邊緣設備上,以實時編輯多個視頻流上的人臉。
PS:遺憾的是我沒有完成調試,沒有環境訓練,並且由於得不到part1中的onnx模型文件,所以part2也未能完成。

注:part2中編譯/opt/nvidia/deepstream/deepstream-4.0/sources/apps/retinanet_for_redaction_with_deepstream的時候,有一個坑,需要修改Makfile:47行:
增加庫-lgstrtp-1.0

2. deepstream源碼例程

問了相關人員,暫時未能瞭解到其他的學習資源,所以還是回到deepstream源碼例程中去研究。

objectDetector_SSD例程:
源碼路徑:/opt/nvidia/deepstream/deepstream-4.0/sources/objectDetector_SSD
方法請查閱README
該例程需要安裝tensorflow:For Jetson, refer to https://elinux.org/Jetson_Zoo#TensorFlow
並且下載:http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2017_11_17.tar.gz

$ cd ssd_inception_v2_coco_2017_11_17
     $ python /usr/lib/python2.7/dist-packages/uff/bin/convert_to_uff.py \
         frozen_inference_graph.pb -O NMS \
         -p /usr/src/tensorrt/samples/sampleUffSSD/config.py \
         -o sample_ssd_relu6.uff

再將得到的sample_ssd_relu6.uff模型文件複製到README目錄。
編譯並運行:

# 需要指定cuda版本
$ export CUDA_VER=10.0
$ make -C nvdsinfer_custom_impl_ssd
$ gst-launch-1.0 filesrc location=../../samples/streams/sample_1080p_h264.mp4 ! \
        decodebin ! m.sink_0 nvstreammux name=m batch-size=1 width=1280 \
        height=720 ! nvinfer config-file-path= config_infer_primary_ssd.txt ! \
        nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink
# 或者:
$ deepstream-app -c deepstream_app_config_ssd.txt

objectDetector_Yolo例程:
源碼路徑:/opt/nvidia/deepstream/deepstream-4.0/sources/objectDetector_Yolo
方法請查閱README
需要先下載yolo模型文件:$ ./prebuild.sh
(注:其中下載了有yolo-v2、yolo-v2-tiny、yolo-v3、yolo-v3-tiny,根據自己的需要可以關閉不需要的下載)
根據README修改配置文件config_infer_primary_yolo[...].txt

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章