레이블이 NVIDIA-DeepStream SDK 3.0인 게시물을 표시합니다. 모든 게시물 표시
레이블이 NVIDIA-DeepStream SDK 3.0인 게시물을 표시합니다. 모든 게시물 표시

7/04/2019

OpenCV Object Tracking 관련자료 수집 (추후 보완)

OpenCV 기반의 Tracking

OpenCV 기반의 Tracking 알고리즘이 많이 제공을 해주고 있는 것 같으며, 관련자료를 모으고,  좀 더 알 수 있다면, 동작방식 및 원리도 알아보자.

  https://www.pyimagesearch.com/2018/07/30/opencv-object-tracking/
  https://www.pyimagesearch.com/2018/08/06/tracking-multiple-objects-with-opencv/

DeepStream의 nvtracker의 경우 아래의 KLT와 IOU를 사용하는데 이 부분에 대해서 좀 더 알아보자.
  https://devtalk.nvidia.com/default/topic/1044828/deepstream-for-tesla/how-nvtracker-to-deal-with-batch-data-/


KLT(Kanade-Lucas-Tomasi) Tracker
  http://www.cs.cmu.edu/~16385/s17/Slides/15.1_Tracking__KLT.pdf
  https://kr.mathworks.com/help/vision/examples/face-detection-and-tracking-using-the-klt-algorithm.html
  https://www.learnopencv.com/object-tracking-using-opencv-cpp-python/
  http://web.yonsei.ac.kr/jksuhr/articles/Kanade-Lucas-Tomasi%20Tracker.pdf


IOU(intersection over Union) Tracker
  https://github.com/bochinski/iou-tracker
  https://stackoverflow.com/questions/28723670/intersection-over-union-between-two-detections/28726781#28726781
  https://www.researchgate.net/figure/Basic-principle-of-the-IOU-Tracker-with-high-accuracy-detections-at-high-frame-rates_fig1_319502501
  https://pdfs.semanticscholar.org/eb6b/21d1c535859dd320d93504d39975c5498aff.pdf

  https://eehoeskrap.tistory.com/124?category=570078

7/02/2019

Deepstream 3.0 SDK 기반의 DeepStream Referece Apps (Yolo)

1. DeepStream Reference Apps (SDK 3.0)

Jetson AGX Xavier에서 Jetapck 4.1.1를 설치하고 DeepStream SDK 3.0를 설치 진행한 후 , NVIDIA에서 제공하는 DeepStream Referece Apps들을 실행해보자.


NVIDIA에서 제공하는 Deepstream Reference App
  https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps

  • Deepstream Reference Apps 설치 및 구조파악 
 
$ cd ~

$ git clone https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps

$ tree -L 3 deepstream_reference_apps
deepstream_reference_apps
├── anomaly
│   ├── apps
│   │   └── deepstream-anomaly-detection
│   ├── config
│   │   └── ds_pgie_config.txt
│   ├── plugins
│   │   ├── gst-dsdirection
│   │   └── gst-dsopticalflow
│   └── README.md
├── CaffeMNIST
│   ├── config_infer_primary_CaffeMNIST.txt
│   ├── data
│   │   └── mnist3d.prototxt
│   ├── deepstream_app_config_CaffeMNIST.txt
│   ├── labels.txt
│   ├── nvdsinfer_custom_impl_CaffeMNIST
│   │   ├── CMakeLists.txt
│   │   ├── factoryCaffeMNISTLegacy.h
│   │   ├── nvdsiplugin_CaffeMNIST.cpp
│   │   └── nvdsparseoutput_CaffeMNIST.cpp
│   └── README.md
├── LICENSE
├── Makefile.config
├── README.md
├── senet
│   ├── apps
│   │   ├── deepstream-senet
│   │   └── trt-senet
│   ├── config
│   │   ├── config_infer_primary_resnet10.txt
│   │   └── config_infer_secondary_senet.txt
│   ├── data
│   │   ├── imagenet_labels.txt
│   │   └── resnet10_labels.txt
│   ├── lib
│   │   ├── calibrator.cpp
│   │   ├── calibrator.h
│   │   ├── CMakeLists.txt
│   │   ├── ds_image.cpp
│   │   ├── ds_image.h
│   │   ├── network_config.cpp
│   │   ├── network_config.h
│   │   ├── se_resnet50.cpp
│   │   ├── se_resnet50.h
│   │   ├── trt_utils.cpp
│   │   └── trt_utils.h
│   ├── LICENSE
│   ├── README.md
│   └── Revised_Scripts
│       ├── base_revised.py
│       └── dumpTFWts_revised.py
└── yolo
    ├── apps
    │   ├── deepstream-yolo
    │   └── trt-yolo
    ├── config
    │   ├── yolov2-tiny.txt
    │   ├── yolov2.txt
    │   ├── yolov3-tiny.txt
    │   └── yolov3.txt
    ├── data
    │   ├── calibration_images.txt
    │   ├── labels.txt
    │   ├── test_images.txt
    │   ├── yolov2-calibration.table
    │   ├── yolov2-tiny-calibration.table
    │   ├── yolov3-calibration.table
    │   └── yolov3-tiny-calibration.table
    ├── lib    // 내부를 보면 이것도 IPlugin 을 사용하여 Custom Layer
    │   ├── calibrator.cpp
    │   ├── calibrator.h
    │   ├── CMakeLists.txt
    │   ├── ds_image.cpp
    │   ├── ds_image.h
    │   ├── kernels.cu
    │   ├── plugin_factory.cpp   // IPlugIn
    │   ├── plugin_factory.h
    │   ├── trt_utils.cpp
    │   ├── trt_utils.h
    │   ├── yolo_config_parser.cpp
    │   ├── yolo_config_parser.h
    │   ├── yolo.cpp
    │   ├── yolo.h
    │   ├── yoloplugin_lib.cpp
    │   ├── yoloplugin_lib.h
    │   ├── yolov2.cpp
    │   ├── yolov2.h
    │   ├── yolov3.cpp
    │   └── yolov3.h
    ├── plugins
    │   ├── gst-yoloplugin-tegra
    │   └── gst-yoloplugin-tesla
    ├── prebuild.sh
    ├── README.md
    └── samples
        └── objectDetector_YoloV3

Deepstream 기반의 Example이며, Deepstream SDK를 설치하고 이를 설치하여 동작해보도록 하자.

DeepStream Reference Apps
  https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps


2. DeepStream Yolo 관련내용 

Yolo Readme를 읽어보면, Jetson Xavier가 지원이 가능하며, Jetson TX1/2도 지원이 가능한것을 확인가능.

  • Yolo Deepstream를 위해 Plugin 설치 
 
$ cd deepstream_reference_apps/yolo   // yolo main 

$ sh prebuild.sh  

$ cd plugins/gst-yoloplugin-tegra/

$ mkdir build && cd build

$ cmake -D DS_SDK_ROOT=~/deepstream_sdk_on_jetson -D CMAKE_BUILD_TYPE=Release ..

$ make && sudo make install
....
[100%] Built target gstnvyolo
[ 84%] Built target yolo-lib
[100%] Built target gstnvyolo
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvyolo.so
-- Set runtime path of "/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvyolo.so" to "/usr/local/cuda-10.0/lib64:/usr/lib/aarch64-linux-gnu/tegra"


2.1 deepstream-yolo-app 설치 및 실행 

  • deepstream-yolo-app 설치
yolo를 이용하여  deepstream을 진행하는 예제이며,  세부사항은 소스를 분석을 해봐야 알 것 같다.

$ cd  ~/deepstream_reference_apps/yolo   // yolo main 

$ cd apps/deepstream-yolo

$ mkdir build && cd build

$ cmake -D DS_SDK_ROOT=~/deepstream_sdk_on_jetson -D CMAKE_BUILD_TYPE=Release ..

$ make && sudo make install
...
[100%] Linking CXX executable deepstream-yolo-app
[100%] Built target deepstream-yolo-app
[100%] Built target deepstream-yolo-app
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/bin/deepstream-yolo-app


$ cd ../../../

  • deepstream-yolo-app 실행 
$ pwd
/home/nvidia/deepstream_reference_apps/yolo

//config의 변경해보면서 각 개별 테스트 

$ deepstream-yolo-app Tegra  ~/deepstream_sdk_on_jetson/samples/streams/sample_720p.h264 config/yolov3.txt         //느리지만, 잘 인식 , Frame별로 인식확인가능
........
yolo_83
yolo_95
yolo_107
Using previously generated plan file located at data/yolov3-kFLOAT-kGPU-batch1.engine
Loading TRT Engine...
Loading Complete!
Running...
NvMMLiteOpen : Block : BlockType = 261 
NvMMLiteBlockCreate : Block : BlockType = 261 
Allocating new output: 1280x720 (x 12), ThumbnailMode = 0
OPENMAX: HandleNewStreamFormat: 3528: Send OMX_EventPortSettingsChanged: nFrameWidth = 1280, nFrameHeight = 720 
Frame Number = 0 Number of objects = 10 Car Count = 3 Person Count = 5 Bicycle Count = 0 Truck Count = 0 
Frame Number = 1 Number of objects = 10 Car Count = 3 Person Count = 5 Bicycle Count = 0 Truck Count = 0 
Frame Number = 2 Number of objects = 10 Car Count = 4 Person Count = 4 Bicycle Count = 0 Truck Count = 0 
Frame Number = 3 Number of objects = 10 Car Count = 4 Person Count = 4 Bicycle Count = 0 Truck Count = 0 
Frame Number = 4 Number of objects = 10 Car Count = 5 Person Count = 4 Bicycle Count = 0 Truck Count = 0 
Frame Number = 5 Number of objects = 11 Car Count = 5 Person Count = 4 Bicycle Count = 0 Truck Count = 0 
Frame Number = 6 Number of objects = 9 Car Count = 6 Person Count = 2 Bicycle Count = 0 Truck Count = 0 
Frame Number = 7 Number of objects = 11 Car Count = 7 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 8 Number of objects = 13 Car Count = 8 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 9 Number of objects = 13 Car Count = 8 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
.......

$ deepstream-yolo-app Tegra  ~/deepstream_sdk_on_jetson/samples/streams/sample_720p.h264 config/yolov3-tiny.txt    //빠르지만, 잘 인식못함.
Output blob names :
yolo_17
yolo_24
Using previously generated plan file located at data/yolov3-tiny-kFLOAT-kGPU-batch1.engine
Loading TRT Engine...
Loading Complete!
Running...
NvMMLiteOpen : Block : BlockType = 261 
NvMMLiteBlockCreate : Block : BlockType = 261 
Allocating new output: 1280x720 (x 12), ThumbnailMode = 0
OPENMAX: HandleNewStreamFormat: 3528: Send OMX_EventPortSettingsChanged: nFrameWidth = 1280, nFrameHeight = 720 
Frame Number = 0 Number of objects = 3 Car Count = 0 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 1 Number of objects = 4 Car Count = 1 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 2 Number of objects = 4 Car Count = 1 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 3 Number of objects = 4 Car Count = 1 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 4 Number of objects = 3 Car Count = 0 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 5 Number of objects = 4 Car Count = 1 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 6 Number of objects = 3 Car Count = 0 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 7 Number of objects = 4 Car Count = 1 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 8 Number of objects = 3 Car Count = 0 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
Frame Number = 9 Number of objects = 4 Car Count = 1 Person Count = 3 Bicycle Count = 0 Truck Count = 0 
...

현재 제공해주는 deepstream-app과 차이는Network도 차이도 있겠지만,  Yolo는 Track 부분을 별도로 연결하지 않아 상위와 같이 Frame 당 인식한 것을 분석하여 보여준다.

이곳도 분석을 보면 osd_sink_pad_buffer_probe 의 Callback Function을 보면 대충 알겠다.
이 소스는 기존의 구성된 소스와 다르게 yolo에서 한번에 모든것을 분석 Detection 및 분류를 다한다.

  • trt-yolo-app 설치 및 실행
이 App은 Deepstream의 App이 아니라고 하며,  테스트 이미지를 inference할때 사용하는 것 같다.
현재 필요한 data/test_images.txt의 test Image들이 없어서 동작이 안되지만, 아래와 같이 넣어주고 동작확인만 하자.
정확하게 확인할 경우는 yolo가 구분할 수 있는 그림을 넣어주면 될 것 같다.
 
$ cd  ~/deepstream_reference_apps/yolo   // yolo main 

$ cd apps/trt-yolo

$ mkdir build && cd build

$ cmake -D CMAKE_BUILD_TYPE=Release ..

$ make && sudo make install
...
-- Found TensorRT headers at /usr/include/aarch64-linux-gnu
-- Found TensorRT libs at /usr/lib/aarch64-linux-gnu/libnvinfer.so;/usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nvidia/nvyolo/deepstream_reference_apps/yolo/apps/trt-yolo/build
[  7%] Linking CXX static library libyolo-lib.a
[ 84%] Built target yolo-lib
[ 92%] Linking CXX executable trt-yolo-app
[100%] Built target trt-yolo-app
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/bin/trt-yolo-app
-- Set runtime path of "/usr/local/bin/trt-yolo-app" to ""

$ cd ../../../

$ trt-yolo-app --flagfile=config/yolov3.txt 

$ find / -name *.jpg 2> /dev/null > data/test_images.txt   // jpg 파일이 없어서 에러발생, 

$ trt-yolo-app --flagfile=config/yolov3.txt      // 상위와 같이 만들어주면, inference 가능하며, 실제 image파일 넣어 테스트 하자  

  https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps/tree/master/yolo


3.  CaffeMNIST 관련내용 

추후 사용할 일이 있다면, 그때 사용

  https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps/blob/master/CaffeMNIST/README.md


4.  Anomaly Detection Reference Apps (Xavier 미지원)

Deepstream의 또 따른 예제이며, 이것도 진행을 했지만, 아래의 링크를 보면, Xavier에서는 미지원이다.
혹시나 해서 관련부분을 수정하면서 해보려고 했지만, DeepStream SDK에서 지원을 해줘야 가능한 소스이다.

너무 좋은 예제라서 한번 돌려보고 싶지만, 이번에 말고 다음기회에 하자 (반드시 기억하자)

이상감지 (Anomaly Detection)
  http://intothedata.com/02.scholar_category/anomaly_detection/

  • OpenCV 4.0 설치진행 (용량이 부족하므로 확장해야함)
아래를 설치를 진행을 하다보면, Jetson Xavier의 용량이 부족하여, Build를 할수가 없어지는 현상이 발생하는데, 이부분은  NFS  or 확장 Storage로 부족한 용량을 해결하고 진행하자.
(나의 경우는 확장 Storage가 없어서 NFS로 진행)

$ cd ~
$ wget https://github.com/opencv/opencv/archive/4.0.1.zip
$ wget https://github.com/opencv/opencv_contrib/archive/4.0.1.zip
$ ls             // 상위 이름이 동일함 
4.0.1.zip  4.0.1.zip.1

$ unzip 4.0.1.zip
$ unzip 4.0.1.zip.1
$ ls 
...  4.0.1.zip  4.0.1.zip.1  opencv-4.0.1  opencv_contrib-4.0.1
$ mv opencv-4.0.1 opencv                                               // Build 시 두 Directory의 용량이 너무 커서 NFS or 확장 Storage를 사용해야함 
$ mv opencv_contrib-4.0.1 opencv_contrib

$ cd ~/opencv/
$ mkdir build

$ cd build

$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -DCMAKE_INSTALL_PREFIX=/usr/local \
        -DWITH_CUDA=ON \
        -DINSTALL_PYTHON_EXAMPLES=ON \
        -DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
        -DBUILD_EXAMPLES=ON \
        -DBUILD_opencv_cudacodec=OFF \
        -DCMAKE_CXX_FLAGS="" .. 

........ 로그를 보면, Caffe 도 찾고  tessract 도 찾고  freetype2도 찾고 많이 찾는데, 추후 필요사용할 경우, 미리설치해놓고 설치해보자. 

--     Disabled:                    cudacodec world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv freetype hdf java js matlab ovis python3 sfm viz
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI: 
--     GTK+:                        NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        libjpeg-turbo (ver 1.5.3-62)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         build (ver 1.6.35)
--     TIFF:                        build (ver 42 - 4.0.9)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   
--       base:                      YES (ver 1.14.4)
--       video:                     YES (ver 1.14.4)
--       app:                       YES (ver 1.14.4)
--       riff:                      YES (ver 1.14.4)
--       pbutils:                   YES (ver 1.14.4)
--     v4l/v4l2:                    linux/videodev2.h
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (built-in)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.3.4)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
-- 
--   NVIDIA CUDA:                   YES (ver 10.0, CUFFT CUBLAS)
--     NVIDIA GPU arch:             72
--     NVIDIA PTX archs:
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/nvidia/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.15)
--     Libraries:                   /usr/lib/aarch64-linux-gnu/libpython2.7.so (ver 2.7.15+)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.13.3)
--     install path:                lib/python2.7/dist-packages/cv2/python-2.7
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Java:                          
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /usr/local

$ sudo make                      //시간이 많이 걸리며, Jetson Xavier의 용량부족발생 (50%까지도 못감)   (NFS로 연결하여 용량부분 해결)
$ sudo make install                
$ sudo ldconfig



  • Deepstream PlugIn 부분 빌드  ( Xavier에서 미지원)
아래와 같이 진행을 하면, Xavier의 DeepStream SDK 3.0의 source에서 미지원되는 부분이 존재하여, 빌드가 제대로 되지 않음

$ pwd
/home/nvidia/opencv/build

$ export DS_SDK_ROOT=/home/nvidia/deepstream_sdk_on_jetson
$ export OPENCV_ROOT=/home/nvidia/opencv/build

$ echo $DS_SDK_ROOT
/home/nvidia/deepstream_sdk_on_jetson
$ echo $OPENCV_ROOT

$ cd  ~/deepstream_reference_apps/anomaly/plugins/gst-dsopticalflow

$ mkdir build
$ cd build

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D DS_SDK_ROOT=$DS_SDK_ROOT -D OPENCV_ROOT=$OPENCV_ROOT ..
.....
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda-10.0 (found suitable version "10.0", minimum required is "10.0") 
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Found OpenCV: /home/nvidia/opencv/build (found version "4.0.1") found components:  core imgproc imgcodecs highgui dnn 
-- Checking for modules 'gstreamer-1.0>=1.4;gstreamer-video-1.0>=1.4;gstreamer-app-1.0>=1.4'
--   Found gstreamer-1.0, version 1.14.4
--   Found gstreamer-video-1.0, version 1.14.4
--   Found gstreamer-app-1.0, version 1.14.4
-- Found OpenCV: /home/nvidia/opencv/build (found suitable version "4.0.1", minimum required is "4.0") found components:  opencv_calib3d opencv_core opencv_dnn opencv_features2d opencv_flann opencv_gapi opencv_highgui opencv_imgcodecs opencv_imgproc opencv_ml opencv_objdetect opencv_photo opencv_stitching opencv_video opencv_videoio opencv_aruco opencv_bgsegm opencv_bioinspired opencv_ccalib opencv_cudaarithm opencv_cudabgsegm opencv_cudafeatures2d opencv_cudafilters opencv_cudaimgproc opencv_cudalegacy opencv_cudaobjdetect opencv_cudaoptflow opencv_cudastereo opencv_cudawarping opencv_cudev opencv_datasets opencv_dnn_objdetect opencv_dpm opencv_face opencv_fuzzy opencv_hfs opencv_img_hash opencv_line_descriptor opencv_optflow opencv_phase_unwrapping opencv_plot opencv_reg opencv_rgbd opencv_saliency opencv_shape opencv_stereo opencv_structured_light opencv_superres opencv_surface_matching opencv_text opencv_tracking opencv_videostab opencv_xfeatures2d opencv_ximgproc opencv_xobjdetect opencv_xphoto
.......

$ make   // Deepstream SDK에서 아래를 지원해줘야 하는데, 미지원
/home/nvidia/deepstream_reference_apps/anomaly/plugins/gst-dsopticalflow/gstdsopticalflow.cpp:488:13: error: ‘CHECK_NVDS_MEMORY_AND_GPUID’ was not declared in this scope
         if (CHECK_NVDS_MEMORY_AND_GPUID (dsopticalflow, surface))
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nvidia/deepstream_reference_apps/anomaly/plugins/gst-dsopticalflow/gstdsopticalflow.cpp:506:80: error: ‘NvBufSurface {aka struct _NvBufSurface}’ has no member named ‘buf_data’; did you mean ‘buf_fds’?
         if (DsOpticalFlowProcess(dsopticalflow->dsopticalflowlib_ctx, surface->buf_data[0],
                                                                                ^~~~~~~~

$ sudo make install
$ cd ../../../



  • 상위 Make Error 관련사항 ( Deepstream SDK가 지원해줘함)
  https://devtalk.nvidia.com/default/topic/1045243/deepstream-for-tesla/could-the-deepstream-plugins-github-be-run-on-p40-/
  https://devtalk.nvidia.com/default/topic/1049374/deepstream-sdk-on-jetson/ai-iot-deepstream_reference_apps-gst_dsoptical-flow-build-error/


  • 이상감지 관련소스 
  https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps/blob/master/anomaly/README.md

6/25/2019

DeepStream SDK 3.0 기본자료 및 설치/실행 (Jetpack 4.2 와 4.1.1 )

1. DeepStream SDK 3.0 설치 및 기본자료수집  

  • Jetson TX2의 DeepStream 관련기능 및 세부내용 
Jetson TX2에서도 TensorRT의 확장성을 위해서 Multimedia 자료를 테스트 진행했고,  NVIDIA의 Manual을 읽는 도중에 DeepStream기능을
알게되었으며, 현재 Jetson TX2 의 DeepStream 관련자료를 정리한다.
아래의 자료를 보면 쉽게 이해를 할수 있다.

TensorRT 와 Deepstream 관련부분
  https://ahyuo79.blogspot.com/2019/06/tensorrt-50-deepstream.html

TensorRT 와 Multimedia Sample 의 기본이해
  https://ahyuo79.blogspot.com/2019/06/tensorrt-50-multimedia-sample.html

Deepstream SDK 1.5의 에러사항
  https://ahyuo79.blogspot.com/2019/06/deepstream-sdk-15-jetson-tx2-test.html


  • Jeston AGX Xavier 의 DeepStream SDK 3.0 
현재 Jetson AGX Xavier에서는 DeepStream 3.0 beta version 지원하며, Telsa 경우와는 다르지만 비교적 괜찮게 동작된다고 한다. ( 라이센스를 보면 정식버전이 아님)
물론 x86기반의 Tesla version 안정화되어있으며, NVIDIA에서 Docker까지 제공해주는 것으로 보인다.

DeepStream의 Version은 각각의 HW에 따라 지원사항이 다르며, 구성도 다르므로, 관련 HW에 따라서 반드시 확인을 하자.
(Tesla (x86) , Jetson-x 보드에 따라 다름)

Jetson AGX Xavier에 이미 설치된 JetPack 4.2에서 테스트를 진행 후 JetPack 4.1.1를 재설치 후 다시 진행예정

Jetpack 4.1.1
   https://developer.nvidia.com/embedded/jetpack-4-1-1

1.1  NVIDIA DeepStream SDK 관련자료수집 

DeepStream SDK
  https://developer.nvidia.com/deepstream-sdk

DeepStream  SDK for Jetson 과 Manual Download
  https://developer.nvidia.com/embedded/deepstream-on-jetson-downloads

DeepStream  (중국/일본) GTC 자료로추정
 http://on-demand.gputechconf.com/gtc-cn/2018/pdf/CH8307.pdf
 https://www.slideshare.net/NVIDIAJapan/1-jetson

DeepStream 2.0 Webinar 자료
 https://docplayer.net/98984804-Deepstream-sdk-2-0-webinar-james-jeun-july-2018.html

NVIDIA Deepstream Youtube 자료 ( GTC자료와 중복)
  https://www.youtube.com/watch?v=Hdew1P1nXBc
  https://www.youtube.com/watch?v=H2blB7MGnx4

NVIDIA AGX Xavier Deepstream 3.0 동작 (현재 동일하게 확인가능)
  https://www.youtube.com/watch?v=gbjUW_4l-hw

NVIDIA Webinar 자료 (무료)
  https://www.nvidia.com/en-us/about-nvidia/webinar-portal/

NVIDIA GTC Keynote
  https://on-demand-gtc.gputechconf.com/gtcnew/on-demand-gtc.php

NVIDIA GTC on Demand
- Using the Deepstream SDK for AI-Based Video Analytics
  http://on-demand-gtc.gputechconf.com/gtc-quicklink/hqGEv


1.2 DeepStream SDK 3.0  설치방법 

Jetson AGX Xavier에서 Deepstream 3.0을 각 Jetpack Version 마다 설치를 진행

  • DeepStream 3.0 SDK 설치방법 (Host)
Host에서 Key 중복 및 상위에서 download한 file target copy

$ ssh-keygen -R 192.168.55.1  // Key 재발행 후 재접속, 기존에 Jetson TX2사용  

$ scp ./DeepStreamSDK-Jetson-3.0_EA_beta5.0.tbz2 nvidia@192.168.55.1:~

$ ssh -X nvidia@192.168.55.1   // Jetson USB로 연결됨  ( Target 접속)


  • DeepStream 3.0 SDK 설치방법 (Target)
아래와 같이 직접 Deepstream Binary File을 설치하여 기본적인 테스트를 진행하자.
$ cd ~  // Jetson TX2 

$ tar xpvf DeepStreamSDK-Jetson-3.0_EA_beta5.0.tbz2

$ cd deepstream_sdk_on_jetson                   //deepstream app 설치된 장소 

$ sudo tar -xvf binaries.tbz2 -C /       //deepstream binary package 설치 
usr/
usr/lib/
usr/lib/aarch64-linux-gnu/
usr/lib/aarch64-linux-gnu/tegra/
usr/lib/aarch64-linux-gnu/tegra/libnvds_msgconv.so.1.0.0  //sources/libs/nvmsgconv 참고
usr/lib/aarch64-linux-gnu/tegra/libnvll_infer.so.1.0.0
usr/lib/aarch64-linux-gnu/tegra/libnvds_logger.so                  //sources/libs/nvds_logger 참고 
usr/lib/aarch64-linux-gnu/tegra/libgstnvquery.so
usr/lib/aarch64-linux-gnu/tegra/libnvds_kafka_proto.so           //sources/libs/kafka_protocol_adaptor 참고 (config에서 [message-broker]  설정가능)
usr/lib/aarch64-linux-gnu/tegra/libnvtracker.so.1.0.0
usr/lib/aarch64-linux-gnu/libgstnvdsmeta.so
usr/lib/aarch64-linux-gnu/gstreamer-1.0/
usr/lib/aarch64-linux-gnu/gstreamer-1.0/libnvdsgst_msgbroker.so       //sources/gst-plugins/gst-nvmsgbroker  
usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvtracker.so
usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvmultistream.so
usr/lib/aarch64-linux-gnu/gstreamer-1.0/libnvdsgst_msgconv.so             //sources/gst-plugins/gst-nvmsgconv
usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvinfer.so
usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvdsexample.so             //sources/gst-plugins/gst-dsexample
usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvosd.so
usr/bin/
usr/bin/deepstream-test2-app  // source 의 deepstream-app 4 종류 
usr/bin/deepstream-test1-app
usr/bin/deepstream-test3-app
usr/bin/deepstream-app

$ tree -L 3               //Deepstream SDK 3.0 전체 구조 파악 
.
├── binaries.tbz2         // DeepStream Binary Package , 아래의 Source 부분의 app들  관련 Library 들 
├── LicenseAgreement.pdf
├── README                // 설치전 Deepstream 설치참고 Manual   
├── samples                // DeepStream Model/Sample/Config File 구성 
│   ├── configs
│   │   └── deepstream-app   // Config File 상위 README 에서 확인
│   ├── models    //GIE의 Primary 와 Secondary 설정옵션이 다름                                 
│   │   ├── Primary_Detector            // Caffe Model 및 label 과   1st GIE(TensorRT Engine) 생성
│   │   ├── Secondary_CarColor        // Caffe Model 및 label 과  2nd GIE(TensorRT Engine) 생성
│   │   ├── Secondary_CarMake        // Caffe Model 및 label 과  3th GIE(TensorRT Engine) 생성
│   │   └── Secondary_VehicleTypes  // Caffe Model 및 label 과  4th GIE(TensorRT Engine) 생성
│   └── streams
│       ├── sample_720p.h264
│       └── sample_720p.mp4
└── sources                 // DeepStream 관련 전체소스 
    ├── apps
    │   ├── apps-common
    │   └── sample_apps
    ├── gst-plugins          // 상위 binaries.tbz2 에서 이미설치되고, 아래의 Libs와 연결 
    │   ├── gst-dsexample       // openCV로 ROI형식으로 지정하는 예제이며, 이기반으로 PlugIn을 만들수 있다.
    │   ├── gst-nvmsgbroker    // Source code for a plugin to send data to the server using the Kafka protocol adapter 
    │   └── gst-nvmsgconv      //Source code for a plugin to convert metadata to schema format
    ├── includes
    │   ├── gstnvdsinfer.h
    │   ├── gstnvdsmeta.h
    │   ├── gst-nvquery.h
    │   ├── gstnvstreammeta.h
    │   ├── nvbuffer.h
    │   ├── nvbuf_utils.h
    │   ├── nvdsinfer_custom_impl.h
    │   ├── nvdsinfer.h
    │   ├── nvds_logger.h
    │   ├── nvdsmeta.h
    │   ├── nvds_msgapi.h
    │   └── nvosd.h
    ├── libs     // library와 별도의 test program 존재  (Kafka 추후에 사용예정)
    │   ├── kafka_protocol_adaptor  // (상위binaries.tbz2 설치)  test_kafka_proto_async, test_kafka_proto_sync Test Program 가능 
    │   ├── nvds_logger           // (상위binaries.tbz2 설치)  Test Program 별도 존재 
    │   ├── nvdsparsebbox         // 미설치된 library , 추가설치가능 
    │   └── nvmsgconv             // (상위binaries.tbz2 설치) 
    ├── objectDetector_FasterRCNN              // FasterRCNN IPlugIn 관련부분 연결 (공유 Library 연결필요) 
    │   ├── config_infer_primary_fasterRCNN.txt
    │   ├── deepstream_app_config_fasterRCNN.txt
    │   ├── labels.txt
    │   ├── nvdsinfer_custom_impl_fasterRCNN
    │   └── README
    └── objectDetector_SSD                 // SSD IPlugIn 관련부분 연결  (공유 Library 연결필요) 
        ├── config_infer_primary_ssd.txt
        ├── deepstream_app_config_ssd.txt
        ├── nvdsinfer_custom_impl_ssd
        └── README                              // check README , 상위에서 요약



  • Manual 참조 (상위 SDK Download 와 별도로 Manual 로 Download가능)
(NVIDIA_DeepStream_SDK_on_Jetson_References.tar)

Sample
Path inside sources directory
Description
DsExample plugin
gst-plugins/gst-dsexample
Template plugin for integrating custom algorithms in DeepStream SDK graph.
NvMsgConv plugin
gst-plugins/gst-nvmsgconv
Source code for the NvMsgConv plugin for converting metadata to schema format.
NvMsgBroker plugin
gst-plugins/gst-nvmsgbroker
Source code for the NvMsgBroker plugin for sending data to the server.
NvMsgConv library
libs/nvmsgconv
NvMsgConv library required by the NvMsgConv plugin.
Kafka protocol adapter
libs/kafka_protocol_adapter
Protocol adapter for Kafka.
nvdsparsebbox
libs/nvdsparsebbox
Custom model bounding box parsing library example.
Simple test application 1
apps/sample_apps/deepstream-test1
Simple demonstration of how to use DeepStream SDK elements in the pipeline and extract meaningful insights from a video stream. Uses a single primary detector.
Simple test application 2
apps/sample_apps/deepstream-test2
This example builds on test application 1 to add more elements in the pipeline and extract even more information from the stream.
Simple test application 3
apps/sample_apps/deepstream-test3
Builds on test application 1 to demonstrate how to:
Use multiple sources in the pipeline
Use a uridecodebin to accept any type of input (e.g. RTSP/File), any supported container format, and any codec
Configure stream-muxer to generate a batch of frames and infer on it for better resource utilization
Extract the stream metadata, which contains useful information about the frames in the batched buffer
Simple test application 4
apps/sample_apps/deepstream-test4
Demonstrates how to generate metadata payload and transmit it to the Cloud.
DeepStream reference application
apps/sample_apps/deepstream-app
Source code for the DeepStream reference application.
UFF SSD detector
objectDetector_SSD
Configuration files and custom library implementation for the SSD detector model.
Faster RCNN detector
objectDetector_FasterRCNN
Configuration files and custom library implementation for the FasterRCNN model.

  • README 체크 (요약)
 $ vi README  // 필요사항 및 설치사항 확인  (반드시 JetPack 4.1.1, 기반)
README 관련사항 요약 
=======================================================================
Installing prerequisites on Jetson development board:
=======================================================================
Packages to be installed:
$ sudo apt-get install \
    libssl1.0.0 \
    libgstreamer1.0-0 \
    gstreamer1.0-tools \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly \
    gstreamer1.0-libav \
    libgstrtspserver-1.0-0 \
    libjansson4

=======================================================================
Installing librdkafka to use kafka protocol adaptor with message broker
=======================================================================
Use one of the following steps.

  sudo apt-get install librdkafka1=0.11.3-1build1

=======================================================================
Running the samples
=======================================================================
1. Go to samples directory and run:
   deepstream-app -c 
2. Application config files included in `configs/deepstream-app/`:
   a. source30_720p_dec_infer-resnet_tiled_display_int8.txt (30 Decode + Infer)
   b. source4_720p_dec_infer-resnet_tracker_sgie_tiled_display_int8.txt
      (4 Decode + Infer + SGIE + Tracker)
3. Configuration files for "nvinfer" element in `configs/deepstream-app/`:
   a. config_infer_primary.txt (Primary Object Detector)
   b. config_infer_secondary_carcolor.txt (Secondary Car Color Classifier)
   c. config_infer_secondary_carmake.txt (Secondary Car Make Classifier)
   d. config_infer_secondary_vehicletypes.txt (Secondary Vehicle Type Classifier)


$ dpkg -l  xxxx  // 확인해보면, 이미 아래의 것이 설치되었지만, 재설치 



  • 상위 README 와 같이 설치 진행 
 $ sudo apt-get install \
    libssl1.0.0 \
    libgstreamer1.0-0 \
    gstreamer1.0-tools \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly \
    gstreamer1.0-libav \
    libgstrtspserver-1.0-0 \
    libjansson4

$ sudo apt-get install librdkafka1=0.11.3-1build1

$ sudo ldconfig 


  • Jetson의 성능 최상으로 변경 후 테스트 진행 
$ sudo nvpmodel -m 0 
$ sudo ~/jetson_clocks.sh

처음에는 nvpmodel의 현재 상태를 확인하고, 최상으로 테스트 진행하지 말고 진행하고 두번째 최상으로 변경하고 테스트 진행하자.

1.3 deepstream-app 의 config의 구성과 이해  

실제 구동 가능한  config파일은 1/2번의 config이며, 두개의 gstreamer의 구성이 다르다.


  • deepstream-app -c   config.txt 아래 둘 중 선택 
  1. source30_720p_dec_infer-resnet_tiled_display_int8.txt (30 streams processed with Decode + Primary Infer)
  2. source4_720p_dec_infer-resnet_tracker_sgie_tiled_display_int8.txt (four streams processed with Decode + Primary Infer + Tracker + 3 Secondary GIE)

  • gst-nvinfer config file ( GIE 의 primary 와 secondary 구성)
  1. config_infer_primary.txt (sample configuration file to configure an nvinfer element as primary detector)
  2. config_infer_secondary_carcolor.txt
  3. config_infer_secondary_carmake.txt
  4. config_infer_secondary_vehicletypes.txt (sample configuration files to configure an nvinfer element as secondary classifier)


  • 상세내용은 Manual 참조
(NVIDIA_DeepStream_SDK_on_Jetson_References.tar)


2. deepstream-app 실행 비교 

현재 Deepstream SDK 3.0에서는 deepstream-app이라는 program이 기본으로 지원이 되고 있으며, 이는 상위에서 언급한 Config에 따라 동작방식이 달라진다.
Jetpack 4.2 와 4.1.1에서 각각 설치 한 후 이를 테스트를 진행을 해보며, 에러가 발생한다면, 각각의 상황을 비교해본다.
( 이외에도 다른 Deepstream-test program을 제공)


2.1 deepstream-app 실행  (JetPack 4.2)

TensorRT Engine까지 생성이 되고, 마지막 OpenMAX 진행 후에
buf_convert: Wrong src surface count in Convert Buffer 와 함께 미동작됨

$ deepstream-app -c  samples/configs/deepstream-app/source30_720p_dec_infer-resnet_tiled_display_int8.txt  // 실행과 같이 TRT Model engine을 생성한다.
config_infer_primary.txt             config_infer_secondary_carmake.txt       source30_720p_dec_infer-resnet_tiled_display_int8.txt
config_infer_secondary_carcolor.txt  config_infer_secondary_vehicletypes.txt  source4_720p_dec_infer-resnet_tracker_sgie_tiled_display_int8.txt


$ rm ~/.cache/gstreamer-1.0/registry.aarch64.bin  // ERROR 발생한 경우 , 이 파일을 지우고 다시 실행


  • JetPack4.2의 에러 
아래의 글을 읽어보면, DeepStream 3.0 Beta는 현재 JetPack 4.1.1에서만 돌아간다고 하며, 현재 아래와 동일한 에러 발생

  https://devtalk.nvidia.com/default/topic/1048737/deepstream-sdk-on-jetson/failed-to-run-samples-jetpack-4-2-on-xavier/


2.2 deepstream-app 실행  (JetPack 4.1.1 )

상위와 동일하게 설정하며, 다만 JetPack Version만 변경하고 실행

  • 처음 실행시 문제사항
  1. 공유메모리 못잡는 문제발생 ( 두번 실행하면, 문제 해결) 
  2. TensorRT Engine 생성하는 문제  (시간이 많이 걸림)
두 세번 실행시 상위 문제가 없어지며, 아래의 Cache 정보를 삭제하면, 공유메모리를 못찾는문제가 다시 발생


  • 확인사항 
  1. Perf 측정 FPS 
  2. configs 파일의 구성 및 다른 옵션 

$ rm ~/.cache/gstreamer-1.0/registry.aarch64.bin  // ERROR 발생한 경우 , 이 파일을 지우고 다시 실행 

  • 30 Channel 720 P deepstream-app ( Config 파일 구성 및 옵션체크) 

$ deepstream-app -c  samples/configs/deepstream-app/source30_720p_dec_infer-resnet_tiled_display_int8.txt                         // 실행과 같이 TRT Model engine을 생성하며, 30 Channel  720P로 보여줌 
..........
*PERF: FPS 0 (Avg) FPS 1 (Avg) FPS 2 (Avg) FPS 3 (Avg) FPS 4 (Avg) FPS 5 (Avg)FPS 6 (Avg) FPS 7 (Avg) FPS 8 (Avg) FPS 9 (Avg) FPS 10 (Avg) FPS 11 (Avg) FPS 12 (Avg) FPS 13 (Avg) FPS 14 (Avg) FPS 15 (Avg) FPS 16 (Avg) FPS 17 (Avg) FPS 18 (Avg) FPS 19 (Avg) FPS 20 (Avg) FPS 21 (Avg) FPS 22 (Avg) FPS 23 (Avg) FPS 24 (Avg) FPS 25 (Avg) FPS 26 (Avg) FPS 27 (Avg) FPS 28 (Avg) FPS 29 (Avg) 
**PERF: 35.19 (35.19) 35.19 (35.19) 33.82 (33.82) 35.19 (35.19) 33.82 (33.82) 35.19 (35.19) 33.82 (33.82) 35.19 (35.19) 33.82 (33.82) 35.19 (35.19) 35.19 (35.19) 35.19 (35.19) 35.19 (35.19) 33.82 (33.82) 33.82 (33.82) 35.19 (35.19) 35.19 (35.19) 35.19 (35.19) 33.82 (33.82) 35.19 (35.19) 35.19 (35.19) 35.19 (35.19) 35.19 (35.19) 33.82 (33.82) 33.82 (33.82) 35.19 (35.19) 33.82 (33.82) 35.19 (35.19) 33.82 (33.82) 35.19 (35.19) 
**PERF: 33.18 (33.29) 33.18 (33.29) 33.18 (33.22) 33.18 (33.29) 33.18 (33.22) 33.18 (33.29) 33.18 (33.22) 33.18 (33.29) 33.18 (33.22) 33.18 (33.29) 33.18 (33.29) 33.18 (33.29) 33.18 (33.29) 33.18 (33.22) 33.18 (33.22) 33.18 (33.29) 33.18 (33.29) 33.18 (33.29) 33.18 (33.22) 33.38 (33.48) 33.18 (33.29) 33.18 (33.29) 33.18 (33.29) 33.18 (33.22) 33.18 (33.22) 33.18 (33.29) 33.18 (33.22) 33.18 (33.29) 33.18 (33.22) 33.18 (33.29) 
**PERF: 29.98 (31.68) 29.98 (31.68) 29.98 (31.65) 29.98 (31.68) 29.98 (31.65) 29.98 (31.68) 29.98 (31.65) 29.98 (31.68) 29.98 (31.65) 29.98 (31.68) 29.98 (31.68) 29.98 (31.68) 29.98 (31.68) 29.98 (31.65) 29.98 (31.65) 29.98 (31.68) 29.98 (31.68) 29.98 (31.68) 29.98 (31.65) 29.98 (31.78) 29.98 (31.68) 29.98 (31.68) 29.98 (31.68) 29.98 (31.65) 29.98 (31.65) 29.98 (31.68) 29.98 (31.65) 29.98 (31.68) 29.98 (31.65) 29.98 (31.68) 
**PERF: 30.01 (31.13) 30.01 (31.13) 30.01 (31.11) 30.01 (31.13) 30.01 (31.11) 30.01 (31.13) 30.01 (31.11) 30.01 (31.13) 30.01 (31.11) 30.01 (31.13) 30.01 (31.13) 30.01 (31.13) 30.01 (31.13) 30.01 (31.11) 30.01 (31.11) 30.01 (31.13) 30.01 (31.13) 30.01 (31.13) 30.01 (31.11) 30.01 (31.20) 30.01 (31.13) 30.01 (31.13) 30.01 (31.13) 30.01 (31.11) 30.01 (31.11) 30.01 (31.13) 30.01 (31.11) 30.01 (31.13) 30.01 (31.11) 30.01 (31.13) 
**PERF: 30.01 (30.86) 30.01 (30.86) 30.01 (30.84) 30.01 (30.86) 30.01 (30.84) 30.01 (30.86) 30.01 (30.84) 30.01 (30.86) 30.01 (30.84) 30.01 (30.86) 30.01 (30.86) 30.01 (30.86) 30.01 (30.86) 30.01 (30.84) 30.01 (30.84) 30.01 (30.86) 30.01 (30.86) 30.01 (30.86) 30.01 (30.84) 30.01 (30.91) 30.01 (30.86) 30.01 (30.86) 30.01 (30.86) 30.01 (30.84) 30.01 (30.84) 30.01 (30.86) 30.01 (30.84) 30.01 (30.86) 30.01 (30.84) 30.01 (30.86) 
**PERF: 29.99 (30.69) 29.99 (30.69) 29.99 (30.68) 29.99 (30.69) 29.99 (30.68) 29.99 (30.69) 29.99 (30.68) 29.99 (30.69) 29.99 (30.68) 29.99 (30.69) 29.99 (30.69) 29.99 (30.69) 29.99 (30.69) 29.99 (30.68) 29.99 (30.68) 29.99 (30.69) 29.99 (30.69) 29.99 (30.69) 29.99 (30.68) 29.99 (30.73) 29.99 (30.69) 29.99 (30.69) 29.99 (30.69) 29.99 (30.68) 29.99 (30.68) 29.99 (30.69) 29.99 (30.68) 29.99 (30.69) 29.99 (30.68) 29.99 (30.69) 
**PERF: 29.99 (30.57) 29.99 (30.57) 29.99 (30.56) 29.99 (30.57) 29.99 (30.56) 29.99 (30.57) 29.99 (30.56) 29.99 (30.57) 29.99 (30.56) 29.99 (30.57) 29.99 (30.57) 29.99 (30.57) 29.99 (30.57) 29.99 (30.56) 29.99 (30.56) 29.99 (30.57) 29.99 (30.57) 29.99 (30.57) 29.99 (30.56) 29.99 (30.60) 29.99 (30.57) 29.99 (30.57) 29.99 (30.57) 29.99 (30.56) 29.99 (30.56) 29.99 (30.57) 29.99 (30.56) 29.99 (30.57) 29.99 (30.56) 29.99 (30.57) 
**PERF: 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.52) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 29.81 (30.46) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 30.01 (30.49) 
**PERF: 29.99 (30.43) 29.99 (30.43) 29.99 (30.42) 29.99 (30.43) 29.99 (30.42) 29.99 (30.43) 29.99 (30.42) 29.99 (30.43) 29.99 (30.42) 29.99 (30.43) 29.99 (30.43) 29.99 (30.43) 29.99 (30.43) 29.99 (30.42) 29.99 (30.42) 29.99 (30.43) 29.99 (30.43) 29.99 (30.43) 29.99 (30.42) 29.99 (30.45) 29.99 (30.43) 29.99 (30.43) 29.99 (30.43) 29.99 (30.42) 29.99 (30.42) 29.99 (30.40) 29.99 (30.42) 29.99 (30.43) 29.99 (30.42) 29.99 (30.43) 
**PERF: 30.07 (30.39) 30.07 (30.39) 30.07 (30.38) 30.07 (30.39) 30.07 (30.38) 30.07 (30.39) 30.07 (30.38) 30.07 (30.39) 30.07 (30.38) 30.07 (30.39) 30.07 (30.39) 30.07 (30.39) 30.07 (30.39) 30.07 (30.38) 30.07 (30.38) 29.87 (30.37) 30.07 (30.39) 30.07 (30.39) 30.07 (30.38) 30.07 (30.41) 30.07 (30.39) 30.07 (30.39) 30.07 (30.39) 30.07 (30.38) 30.07 (30.38) 30.07 (30.37) 30.07 (30.38) 30.07 (30.39) 30.07 (30.38) 30.07 (30.39) 
** INFO: : Received EOS. Exiting ...

30 (5x6 ) Channel 의 720p의 H.264영상을 처리


상위 채널중에 더블 클릭시 확대가능

상위 로그에서 Perf의 각 Frame을 확인해야한다.


  • 4 Channel 720P deepstreem-app ( Config 파일의 구성 및 옵션부분 체크)
$ deepstream-app -c  samples/configs/deepstream-app/source4_720p_dec_infer-resnet_tracker_sgie_tiled_display_int8.txt        // 실행과 같이 TRT Model engine을 생성하며,  4 Channel  720P로 보여줌 
....
**PERF: FPS 0 (Avg) FPS 1 (Avg) FPS 2 (Avg) FPS 3 (Avg)             // 왜 40 FPS가 나오는지 동영상을 봐야겠다. 
**PERF: 41.91 (41.91) 41.91 (41.91) 41.91 (41.91) 41.91 (41.91) 
**PERF: 30.01 (32.69) 30.01 (32.69) 30.01 (32.69) 30.01 (32.69) 
**PERF: 29.99 (31.52) 29.99 (31.52) 29.99 (31.52) 29.99 (31.52) 
**PERF: 30.01 (31.06) 30.01 (31.06) 30.01 (31.06) 30.01 (31.06) 
**PERF: 30.00 (30.81) 30.00 (30.81) 30.00 (30.81) 30.00 (30.81) 
**PERF: 30.00 (30.66) 30.00 (30.66) 30.00 (30.66) 30.00 (30.66) 
**PERF: 29.98 (30.55) 29.98 (30.55) 29.98 (30.55) 29.98 (30.55) 
**PERF: 30.02 (30.48) 30.02 (30.48) 30.02 (30.48) 30.02 (30.48) 
**PERF: 30.00 (30.42) 30.00 (30.42) 30.00 (30.42) 30.00 (30.42) 
**PERF: 30.00 (30.38) 30.00 (30.38) 30.00 (30.38) 30.00 (30.38) 
** INFO: : Received EOS. Exiting ...

Quitting


상위 채널중 더블 클릭할 경우




  • 사용되는 Model Network
  1. Primary GIE (1st GIE) : resnet10.caffemodel
  2. Secondary GIE(2nd GIE): resnet18.caffemodel ( 3개다 이 Model 사용)

resnet이 유명하기에 이에 관련되는 부분을 추후에 별도로 공부해야함

  • Deepstream 구조 (deepstream-app 의 경우)


  1. VIDEO DECODE:  부분은 FIle or RTSP 부터 Video Decoder 까지 지원하며, uridecodebin가 이를 둘다 지원
  2. STREAM MUX:  Decode 데이타를 Video MUX와 함께 Car-Detect 도 동작 
  3. PRIMARY DETECTOR:  1 Channel만 선택했을 경우 동작이 후는 다음 그대로 이해하면될 것 같다. 



  http://on-demand.gputechconf.com/gtc-cn/2018/pdf/CH8307.pdf


  • deepstream-app의 Callback 함수의 metadata 처리부분 
소스는 좀 복잡하지만 간단하게 deepstream-app의 metadata 처리하는 Callback 함수만 보고, 어떻게 동작하는지를 이해만 하자
  1. gie_processing_done_buf_prob Pad에 Callback Function 등록 
  2. gie_processing_done_buf_prob->process_buff  Call
  3. Buffer 처리마다 for_each_meta 하도록 Callback 등록 
  4. for_each_meta  실제적인 OSD에 표현할 데이타 구성 


$ cd ~/deepstream_sdk_on_jetson/sources/apps/sample_apps/deepstream-app
$ cat deepstream_app.c 
....

static gboolean
for_each_meta (GstBuffer *buffer, GstMeta **meta, gpointer user_data)            // NvDsInstanceData->NvDsFrameMeta 를 이용한 OSD 처리 
{
  //설정에따라, OSD Label  1st GIE Class 및 Track ID 표시 2nd GIE Class 표시 

}
...
static void
process_buffer (GstBuffer *buf, AppCtx *appCtx, guint index)
{
.....
  // call "for_each_meta" to process metadata.
  gst_buffer_foreach_meta (buf, for_each_meta,
                           &appCtx->pipeline.instance_bins[index]);

}

static GstPadProbeReturn
gie_processing_done_buf_prob (GstPad *pad, GstPadProbeInfo *info,
    gpointer u_data)
{
  GstBuffer *buf = (GstBuffer *) info->data;
  NvDsInstanceBin *bin = (NvDsInstanceBin *) u_data;
  guint index = bin->index;
  AppCtx *appCtx = bin->appCtx;

  if (gst_buffer_is_writable (buf))
    process_buffer (buf, appCtx, index);
  return GST_PAD_PROBE_OK;
}

..........
  if (config->osd_config.enable) {
    NVGSTDS_ELEM_ADD_PROBE (instance_bin->all_bbox_buffer_probe_id,
        instance_bin->osd_bin.nvosd, "sink",
        gie_processing_done_buf_prob, GST_PAD_PROBE_TYPE_BUFFER, instance_bin); //gie_processing_done_buf_prob Call Back 등록 
  } else {
    NVGSTDS_ELEM_ADD_PROBE (instance_bin->all_bbox_buffer_probe_id,
        instance_bin->sink_bin.bin, "sink",
        gie_processing_done_buf_prob, GST_PAD_PROBE_TYPE_BUFFER, instance_bin);   //gie_processing_done_buf_prob Call Back 등록 
  }


2.3  deepstream-app 의 config 파일 (RTSP지원으로변경)

주로 봐야할 Config는 아래의 Config인 것 같으며,  쉽게 설정을 통해서 RTSP변환도 가능하며,이를 통해 IP Camera와 연결가능해지며, 동작화인도 쉽다

  • source4_720p_dec_infer-resnet_tracker_sgie_tiled_display_int8.txt 
아래의 Config 파일에서 Gstreamer의 Plugin들을 설정변경하여, RTSP기반으로 동작가능.

$ vi source4_720p_dec_infer-resnet_tracker_sgie_tiled_display_int8.txt   //RTSP 설정 변경 

[source0]
..
##jhlee
#uri=file://../../streams/sample_720p.mp4        //기본설정 
uri=rtsp://10.0.0.211:554/h264

##jhlee 4->1  Input Chan
num-sources=1

[sink0]
...
type=2
##jhlee 1->0
sync=0
....

참고사항
  https://devtalk.nvidia.com/default/topic/1046315/deepstream-sdk-on-jetson/template-config-file-for-camera-and-rtsp/


  • Gst-nvinfer 용 Configs 설정
아래와 같이 실행하며, 에러가 발생하며, README를 보면,  Gstreamer의 Plugin의 nvinfer 세부설정이라고 한다. 
현재 상위 4Channel에만 해당 아래의 설정들을 Gst-nvinfer 에게 어떻게 전달하는지는 각 소스를 분석을 해봐야 할 것 같으며, 대체적으로 Callback Function으로 Metadata 처리 부분일 것 같다.

$ deepstream-app -c  samples/configs/deepstream-app/config_infer_primary.txt                                                      // 에러 발생 , 아래의 의 Cache를 제거해도 동일함 
$ deepstream-app -c  samples/configs/deepstream-app/config_infer_secondary_carmake.txt                                    // 에러 발생 
$ deepstream-app -c  samples/configs/deepstream-app/config_infer_secondary_carcolor.txt                                     // 에러 발생  
$ deepstream-app -c  samples/configs/deepstream-app/config_infer_secondary_vehicletypes.txt                               // 에러 발생 

** ERROR: : Failed to set pipeline to PAUSED
Quitting
ERROR from src_bin_muxer: Output width not set
Debug info: /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvmultistream/gstnvstreammux.c(1633): gst_nvstreammux_change_state (): /GstPipeline:pipeline/GstBin:multi_src_bin/GstNvStreamMux:src_bin_muxer
App run failed
   
$ rm ~/.cache/gstreamer-1.0/registry.aarch64.bin  // ERROR 발생한 경우 , 이 파일을 지우고 다시 실행



3. deepstream-testX-app  samples
Deepstream SDK 3.0에서 제공해주는 test-app은 총 4개이며, binary package에서 test app은 총 4개 중 3개만 제공하고 있다.

IP Camera or RTSP Server와  RTSP 테스트 할 경우는 아래의 Gstreamer로 기본동작을 확인 후 실행하자.

Binaray Package 이외에도 직접 Source에 가서 쉽게 Build가 가능하며, 이를 Build하여 손쉽게 소스수정해보면서 테스트도 가능하기에, 가능하면 Source에서 Build하면서 하자.

세부내용은 Deepstream SDK Manual 참조

3.1 deepstream-test1-app 

소스보면  단순하며 쉽게 Gstremer Command로 생성가능하며, 분석도 쉬운예제이기에 생략하며, 실행은 아래처럼 Binary Package를 이용하거나,
직접 Build해서 실행하자.

$ cd ~/deepstream_sdk_on_jetson
$ deepstream-test1-app 
Usage: deepstream-test1-app 

$ deepstream-test1-app samples/streams/sample_720p.h264    // Error 발생  
g_key_file_load_from_file failed
g_key_file_load_from_file failed
Now playing: samples/streams/sample_720p.h264
g_key_file_load_from_file failed
g_key_file_load_from_file failed
Running...
ERROR from element primary-nvinference-engine: Failed to parse config file:dstest1_pgie_config.txt
Error: Failed to parse config file:dstest1_pgie_config.txt
Returned, stopping playback
Deleting pipeline

$ cd sources/apps/sample_apps/deepstream-test1    // PATH 변경 ,
$ deepstream-test1-app ../../../../samples/streams/sample_720p.h264  // 실행확인 문제 없음 (상위 config 파일을 못찾아서 에러) 


처음실행시 상위와 같이 에러가 발생했으며, 원인은 각 config file을 못찾아 발생

3.2 deepstream-test2-app

이 예제의 기본구조는 File을 open 하여 1개의 Primary Gst-nvinfer 걸쳐 Gst-nvtracker를 걸쳐 Secondary Gst-nvinfer 3개를 사용하고, 이를 Gst-nvosd에 적용하는 예제이다.
중간에 OSD적용하기위해서  Video layout도 converting도 진행을 한다 (NV12->RGBA)

개인적으로 분석하기에 가장 좋은 예제인 것 같으며, CMD Gstreamer로도 복잡하게 실행도 가능하기에, 이를 분석하고 비교 테스트 한다.

  • make로 생성된 deepstream-test2-app를 실행 
전체화면으로 작동이되며, 이를 소스상에서도 RTSP지원으로 변경가능하며, 수정방법은 test3이 RTSP지원이므로, 이를 참고하여
uridecodebin 사용하면 ( rtspsrc/h264parse/omxh264dec) 의 PlugIn(Elelemnt)가 필요없어진다.

$ cd ~/deepstream_sdk_on_jetson
$ deepstream-test2-app 
Usage: deepstream-test2-app 


$ cd sources/apps/sample_apps/deepstream-test2
$ deepstream-test2-app ../../../../samples/streams/sample_720p.h264  //  실행확인 문제 없음 (상위 config 파일을 못찾아서 에러) 


  • Deepstream SDK 3.0의 Metadata 
Gstreamer와 Deepstream의 차이라면, 이 Metadata와 TensorRT일 것이며, C/C++를 이용하여 Gstreamer Program을 작성하여 Callback function에서 처리를 해야한다.
  1. NvDsObjectParams : Detect를 한 후 각 Object관련된 MetaData
  2. NvDsEventMsgMeta : Event를 위한 Msg MetaData로 현재 TEST4에서만 사용 


  • 소스 Callback Function 의 Metadata 분석 
중요 Callback Function osd_sink_pad_buffer_probe 이며, 이곳에서 Metadata를 처리하여 OSD에 적용한다.
  1. GstMeta  > NvDsMeta    //   구조체 Type 변경하여, Gstreamer 내부 MetaData이용 
  2. NvDsMeta->meta_data  > NvDsFrameMeta     
  3. NvDsFrameMetaNvDsObjectParams 의 정보이용 하여 기본정보를 OSD 표현 


Metadata 의 흐름 과  Kafka 관련사항
  https://devblogs.nvidia.com/intelligent-video-analytics-deepstream-sdk-3-0/


구조체 확인 (NvDsFrameMetaNvDsObjectParams ) 나머지는생략

$ cat  include/gstnvdsmeta.h  //상위참조

/** Holds parameters that describe meta data for one object. */
typedef struct _NvDsObjectParams {
  /** Structure containing the positional parameters of the object in the frame.
   *  Can also be used to overlay borders / semi-transparent boxes on top of objects
   *  Refer NvOSD_RectParams from nvosd.h
   */
  NvOSD_RectParams rect_params;       // Rectangle 위치 및 Size
  /** Text describing the object can be overlayed using this structure.
   *  @see NvOSD_TextParams from nvosd.h. */
  NvOSD_TextParams text_params;     // OSD 표현될 글자적용  
  /** Index of the object class infered by the primary detector/classifier */
  gint class_id;            // 1st GIE가 Detection 했을 때 Class ( Car , Person)
  /** Unique ID for tracking the object. This -1 indicates the object has not been
   * tracked. Custom elements adding new NvDsObjectParams should set this to
   * -1. */
  gint tracking_id;
  /** Secondary classifiers / custom elements update this structure with
   *  secondary classification labels. Each element will only update the
   *  attr_info structure at index specified by the element's unique id.
   */
  NvDsAttrInfo attr_info[NVDS_MAX_ATTRIBUTES];    // Object 의 2nd GIE의 Class 정보들  
  /** Boolean indicating whether attr_info contains new information. */
  gboolean has_new_info;
  /** Boolean indicating whether secondary classifiers should run inference on the object again. Used internally by components. */
  gboolean force_reinference;
  /** Used internally by components. */
  gint parent_class_id;
  /** Used internally by components. */
  struct _NvDsObjectParams *parent_roi;
  /** Used internally by components */
  NvOSD_LineParams line_params[4];
  /** Used internally by components */
  gint lines_present;
  /** Used internally by components */
  gint obj_status;
  /** Provision to add custom object metadata info */
  NvDsObjectParamsEx obj_params_ex;
} NvDsObjectParams;

typedef struct _NvDsFrameMeta {
  /** Array of NvDsObjectParams structure describing each object. */
  NvDsObjectParams *obj_params;           // Rectangle 개수만큼의 배열로 각 개체정보 
  /** Number of rectangles/objects i.e. length of @ref NvDsObjectParams */
  guint num_rects;              // Rectangle 갯수 
  /** Number of valid strings in @ref NvDsObjectParams. */
  guint num_strings;
  /** Index of the frame in the batched buffer to which this meta belongs to. */
  guint batch_id;
  /** NvOSD mode to be used. @see NvOSD_Mode in `nvosd.h`. */
  NvOSD_Mode nvosd_mode;
  /** 1 = Primary GIE, 2 = Secondary GIE, 3 = Custom Elements */
  gint gie_type;
  /** Batch size of the primary detector. */
  gint gie_batch_size;
  /** Unique ID of the primary detector that attached this metadata. */
  gint gie_unique_id;
  /** Frame number. */
  gint frame_num;                  // 동영상 Frame Number
  /** Index of the stream this params structure belongs to. */
  guint stream_id;
  /** Boolean indicating if these params are no longer valid. */
  gint is_invalid;
  /** Indicates Surface Type i.e. Spot or Aisle */
  NvDsSurfaceType surface_type;
  /** Indicates Surface Index for SurfaceType Spot or Aisle */
  gint camera_id;
  /** Indicates Surface Index for SurfaceType Spot or Aisle */
  gint surface_index;
} NvDsFrameMeta;


  • CMD Gstreamer 실행 및 Deepstream 비교 
상위 테스트 소스를 기반으로 command gstreamer로 변경하여 테스트 진행하며, OSD의 TEXT가 제대로 동작이 안됨 (metadata 처리부분이 동작이 안됨)

$ gst-launch-1.0 filesrc location=../../../../samples/streams/sample_720p.h264 ! \
        decodebin ! nvinfer config-file-path= dstest2_pgie_config.txt ! \
        nvtracker ! \
        nvinfer config-file-path= dstest2_sgie1_config.txt ! \
        nvinfer config-file-path= dstest2_sgie2_config.txt ! \
        nvinfer config-file-path= dstest2_sgie3_config.txt ! \
        capsfilter caps=video/x-raw(memory:NVMM), format=NV12 !\        
        nvvidconv ! \
        capsfilter caps=video/x-raw(memory:NVMM), format=RGBA !\
        nvosd font-size=15 ! nvoverlaysink

//상위소스를 분석하면, 위와 같이 명령으로 실행이 가능하지만, osd_sink_pad_buffer_probe의 기능을 필요해서 제대로 표현을 못함 
// decodebin (h264parse/omxh264dec 를 호출할 필요 없음)


  • CMD Gstreamer RTSP Version으로 변경 
decodebin 에서 uridecodebin을 이용하여 다양한 uri을 접속가능하도록 변경

$ gst-launch-1.0 uridecodebin uri=rtsp://10.0.0.196:554/h264 ! \
        nvinfer config-file-path= dstest2_pgie_config.txt ! \
        nvtracker ! \
        nvinfer config-file-path= dstest2_sgie1_config.txt ! \
        nvinfer config-file-path= dstest2_sgie2_config.txt ! \
        nvinfer config-file-path= dstest2_sgie3_config.txt ! \
        capsfilter caps=video/x-raw(memory:NVMM), format=NV12 !\        
        nvvidconv ! \
        capsfilter caps=video/x-raw(memory:NVMM), format=RGBA !\
        nvosd font-size=15 ! nvoverlaysink

// RTSP 지원으로 변경하여 테스트 


  • 다른 version으로 테스트 진행 
상위소스를 보면, OSD에 overlay(전체화면)하기 위해서 하지만, OpenGL을 이용하여 X Window 창으로 재생

$ gst-launch-1.0 filesrc location=../../../../samples/streams/sample_720p.mp4 ! \
        decodebin ! nvinfer config-file-path= dstest2_pgie_config.txt ! \
        nvtracker ! \
        nvinfer config-file-path= dstest2_sgie1_config.txt ! \
        nvinfer config-file-path= dstest2_sgie2_config.txt ! \
        nvinfer config-file-path= dstest2_sgie3_config.txt ! \
        nvvidconv ! nvosd ! nvegltransform ! nveglglessink


3.3 Deepstream TEST3 (RTSP 지원)

RTSP 동작은 잘 동작되며, TEST1과 같이 간단한 구조가  구성되어 생략하지만, 소스참고용은 괜찮은 것 같다.

$ cd ~/deepstream_sdk_on_jetson
$ deepstream-test3-app 
Usage: deepstream-test3-app  [uri2] ... [uriN]

$ cd sources/apps/sample_apps/deepstream-test3
$ deepstream-test3-app ../../../../samples/streams/sample_720p.h264  // 에러 발생, uri를 4개로 늘려도 동일하게 에러발생 
$ deepstream-test3-app rtsp://10.0.0.211:554/h264  // RTSP만 성공 확인  (IP Camera 연결)


3.4 Deepstream TEST 4 (Kafka 예제)

Binary Package에 미포함 되어 있으며, 기존과 다르게,  msgconvmsgbroker를 사용하여 Kafka와 통신하는 구조이다.
Deepstream의 Metadata를 Message(Json)로 변경하여 외부Server로 전송하고 분석하는 구조로 구성이 되고 있음

기존에는 전부 GIE(Gst-nvinfer) config 만 존재했다면 이곳에는 msgconv의 config file도 존재하기 때문에 구조를 잘 살펴보자.


$ cd ~/deepstream_sdk_on_jetson
$ cd sources/apps/sample_apps/deepstream-test4
$ make 
$ ls
deepstream-test4-app  deepstream_test4_app.c  deepstream_test4_app.o  dstest4_msgconv_config.txt  dstest4_pgie_config.txt  Makefile  README

$ ./deepstream-test4-app ../../../../samples/streams/sample_720p.h264  // 에러발생, 


제대로 동작하려면, 소스의 CONNECTION_STRING 설정과 NVDS_META_EVENT_MSG 부분을 잘봐야 겠으며, 상위 설정 dstest4_msgconv_config.txt  의 이해도 필요할 것 같음

현재 이것와 같이 연결될 Server가 존재하지 않아 제대로 동작되지 않는 것 같으며, 이부분은  완벽히 동작될 경우 다시 언급하겠음

msgconv 및 msgbroker 관련내용
  https://devblogs.nvidia.com/intelligent-video-analytics-deepstream-sdk-3-0/

Deepstream 2.0
  https://devblogs.nvidia.com/accelerate-video-analytics-deepstream-2/

4. How To build deepstream Apps

상위 Program은  Binary File을 직접 설치하였기때문에 문제없이 동작했지만,  NVIDIA에서 무료로 제공해주는 Deepstream SDK 3.0 내부의 Source를 직접 빌드를 하여 동작하도록 해보자.

손쉽게 NVIDIA Site에서 무료로 SDK와 Manual을 Download했지만, 라이센스같은 것을 추후에 확인을 해야 할 것 같다.


4.1 빌드시 필요 Package 설치 

Build 전에 아래 Package 설치해야만, Build가 되며, 혹시 빠진 것이 있다면,  dkg -l  명령어로 확인하여 관련필요 Package 설치하자.

$ sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev \
   libgstrtspserver-1.0-dev libx11-dev


4.2  deepstream-app 빌드 진행 

상위 source/apps/sampe_apps 를 보면 총 5개의 app를 제공하고 있으며, main이 되는 deepstream-app를 먼저 분석
다른 deepstream-testx-app은 구조가 비교적 간단한 편임

  • deepstream-app 
Deepstream의 Main Program이며,  핵심소스
$ cd ~/deepstream_sdk_on_jetson/sources/apps/sample_apps/deepstream-app 
$ make


  • deepstream-app 구조 및 분석 
이 프로그램만 구성이 좀 복잡하지만, config를 이용하여 file 과 rtsp 테스트도 가능하다.
하지만, rtsp의 경우 처음만 동작하고, 제대로 동작되지 않는다.

$ vi ../../apps-common/includes/deepstream_config.h   //
$ tree -t .
.
├── deepstream_app.c               //apps-common 의 file들을 호출구조 (Gstreamer)
├── deepstream_app_main.c      // main X 구성 및 기본 동작 제어 
├── Makefile
├── README
├── deepstream_app.o
├── deepstream_app_main.o
└── deepstream-app

$ tree -t ../../apps-common
../../apps-common/
├── includes
│   ├── deepstream_app.h
│   ├── deepstream_colors.h
│   ├── deepstream_common.h
│   ├── deepstream_config_file_parser.h
│   ├── deepstream_config.h                           // gstream plugin  (app-common *.c 참조 )
│   ├── deepstream_dsexample.h
│   ├── deepstream_gie.h
│   ├── deepstream_metadata_pool.h
│   ├── deepstream_osd.h
│   ├── deepstream_perf.h
│   ├── deepstream_primary_gie.h
│   ├── deepstream_secondary_gie.h
│   ├── deepstream_sinks.h
│   ├── deepstream_sources.h
│   ├── deepstream_streammux.h
│   ├── deepstream_tiled_display.h
│   └── deepstream_tracker.h
└── src
    ├── deepstream_common.c
    ├── deepstream_config_file_parser.c         //deepstream-app 의 config parser 로  각 group 별로 설정 ( deepstream-app -c xxxx.txt )
    ├── deepstream_dsexample.c                   // 현재 미사용 
    ├── deepstream_metadata_pool.c             // Metadat 추후 Kafka를 통해 전송 
    ├── deepstream_osd_bin.c                       // OSD 관련 ( Text 설정)
    ├── deepstream_perf.c                            // FPS 측정 
    ├── deepstream_primary_gie_bin.c           // 1st TensorRT(GIE), Primary GIE와 Secondary GIE의 옵션이 다름  
    ├── deepstream_secondary_gie_bin.c      //  2nd TensorRT 
    ├── deepstream_sink_bin.c                     // Gstreamer 의 output 
    ├── deepstream_source_bin.c                 // Gstreamer 의 Input
    ├── deepstream_streammux.c                 // Video 영상 Mux 기능 
    ├── deepstream_tiled_display_bin.c         // 최종 Display Option 설정 (e.g 2x2 4Ch)
    ├── deepstream_tracker_bin.c                 //  Tracker 관련 기능,  KLT or IOU 알고리즘제공 
    ├── deepstream_primary_gie_bin.o
    ├── deepstream_tracker_bin.o
    ├── deepstream_config_file_parser.o
    ├── deepstream_metadata_pool.o
    ├── deepstream_source_bin.o
    ├── deepstream_common.o
    ├── deepstream_perf.o
    ├── deepstream_sink_bin.o
    ├── deepstream_dsexample.o
    ├── deepstream_osd_bin.o
    ├── deepstream_secondary_gie_bin.o
    ├── deepstream_tiled_display_bin.o
    └── deepstream_streammux.o

$ grep -r   gst_element_factory_make  .                                 // Gstreamer Plugin 설정함수 검색하여 구조파악
$ grep -r   gst_element_factory_make   ../../apps-common     // Gstreamer Plugin 설정함수 검색 하여 구조파악 


apps-common 파일에서 돌아가는 시스템의 전체적인 구조를 파악하자.
deepstream-app은 두 개의 config를 제공 (30Ch, 4Ch)에서 streammux기능을 사용하며, 여기서 Batch Size의 의미와 정확한 설정방법을 알아두고
이를 display하는 tiled_dispaly의 기능을 확인하자.





  • 다른 deepstream-testx-app 프로그램 
구성이 간단하며, 쉽게 빌드가 가능하며, gst-infer 설정도 별도로 존재하며, 이해하기가 쉽다.

$ cd ~/deepstream_sdk_on_jetson/sources/apps/sample_apps/deepstream-test1
$ make

$ cd ~/deepstream_sdk_on_jetson/sources/apps/sample_apps/deepstream-test2  // nvinfer의 구성이 기본프로그램과 거의 유사
$ make

$ cd ~/deepstream_sdk_on_jetson/sources/apps/sample_apps/deepstream-test3  //RTSP지원인데, 구성이 독특함
$ make

$ cd ~/deepstream_sdk_on_jetson/sources/apps/sample_apps/deepstream-test4  // Build 에러발생 
$ make


5. Jetson AGX Xavier 기반의 일반 Gstreamer 예제

IP Camera 와 아래와 같이 실행을 해보면 잘동작되는 것을 알수 있다. 세부 메뉴얼은 Gstreamer 관련메뉴얼을 읽자.


$ vi gstreamFake.sh   // Fakesink 
export GST_DEBUG=fpsdisplaysink:5
export RTSP_PATH=rtsp://10.0.0.211:554/h264
gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw ! fpsdisplaysink video-sink=fakesink

$ vi gstream1Ch.sh   // 1Channel Gstream , Fixed Size (not Full Screen)
export GST_DEBUG=fpsdisplaysink:5
export RTSP_PATH=rtsp://10.0.0.211:554/h264
gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! omxh264dec ! nveglglessink window-x=100 window-y=100 window-width=640 window-height=360 

$ vi gstream1Ch.sh   // 1Channel Gstream , Input Size Screen 
export GST_DEBUG=fpsdisplaysink:5
export RTSP_PATH=rtsp://10.0.0.211:554/h264
gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! omxh264dec ! nveglglessink -e

$ vi gstream1Ch.sh   // 1Channel Gstream  File Save 
export GST_DEBUG=fpsdisplaysink:5
export RTSP_PATH=rtsp://10.0.0.211:554/h264
gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! video/x-h264,stream-format=byte-stream ! filesink location=dump.h264

$ vi gstream4.sh     //4 Channel Gstream 
export GST_DEBUG=fpsdisplaysink:5
export RTSP_PATH=rtsp://10.0.0.211:554/h264
gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! omxh264dec ! nveglglessink window-x=100 window-y=100 window-width=640 window-height=360 & gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! omxh264dec ! nveglglessink window-x=800 window-y=100 window-width=640 window-height=360 & gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! omxh264dec ! nveglglessink window-x=100 window-y=500 window-width=640 window-height=360  & gst-launch-1.0 rtspsrc location="$RTSP_PATH" ! rtph264depay ! h264parse ! omxh264dec ! nveglglessink window-x=800 window-y=500 window-width=640 window-height=360


  https://devtalk.nvidia.com/default/topic/1043622/jetson-agx-xavier/problems-with-gstreamer-video-decoding-pipeline/
  https://developer.download.nvidia.com/embedded/L4T/r32_Release_v1.0/Docs/Accelerated_GStreamer_User_Guide.pdf?dv2A0QketFFyriluW9VlC-MWvKz47EdjjzfAk-IbvlxfI0h-gzfdPigIlLBki-7obko6HNlF2ffVOvIEypa0Nm446gahCIzqSWD29sNvZ82qQuAkdttYwAAjAkTESp9Rgn6maGtlhsKPIbT0UPC-duLydchWKUbyer3cEWv8ZoL1svospLA


6.  Jetson AGX  Xavier 기반의 TensoRT  관련사항 

AGX Xavier 의 Object Detection 과  Lane Segmatation의 예제인데, TensorRTDALI를 사용하여 최적화한다고 한다.

AGX 기반의 TensorRT 부분
  https://devblogs.nvidia.com/drive-agx-accelerators-object-detection/


7. Yolo 관련 테스트 

EVM-Jetson TX2와 Jetson AGX Xavier에서 각각 Yolo를 Porting하여 돌려 테스트한 사이트

  https://jkjung-avt.github.io/yolov3/
  https://goodtogreate.tistory.com/entry/YOLOv3-on-Jetson-AGX-Xavier-%EC%84%B1%EB%8A%A5-%ED%8F%89%EA%B0%80?category=701595