DeepStream SDK 4.0 전체구조 파악
- Deepstream Sample 구조
$ cd ~/deepstream-4.0/samples // /opt/nvidia/deepstream/deepstream-4.0에서 복사해옴 (이전에)
$ tree
.
├── configs
│ └── deepstream-app // deepstream-app 만을 위한 설정
│ ├── config_infer_primary_nano.txt // Jetson Nano를 위한 version 인것 같음
│ ├── config_infer_primary.txt
│ ├── config_infer_secondary_carcolor.txt
│ ├── config_infer_secondary_carmake.txt
│ ├── config_infer_secondary_vehicletypes.txt
│ ├── iou_config.txt
│ ├── source12_1080p_dec_infer-resnet_tracker_tiled_display_fp16_tx2.txt // deepstream-app 의 다양한 설정제공 (CSI,USB 테스트 못함)
│ ├── source1_csi_dec_infer_resnet_int8.txt
│ ├── source1_usb_dec_infer_resnet_int8.txt
│ ├── source2_csi_usb_dec_infer_resnet_int8.txt
│ ├── source30_1080p_dec_infer-resnet_tiled_display_int8.txt
│ ├── source4_1080p_dec_infer-resnet_tracker_sgie_tiled_display_int8.txt
│ ├── source6_csi_dec_infer_resnet_int8.txt
│ ├── source8_1080p_dec_infer-resnet_tracker_tiled_display_fp16_nano.txt
│ ├── source8_1080p_dec_infer-resnet_tracker_tiled_display_fp16_tx1.txt
│ └── tracker_config.yml
├── models
│ ├── Primary_Detector // 1nd GIE Object Detection
│ │ ├── cal_trt.bin
│ │ ├── labels.txt
│ │ ├── resnet10.caffemodel
│ │ ├── resnet10.caffemodel_b1_int8.engine // TensorRT Engine
│ │ ├── resnet10.caffemodel_b4_int8.engine
│ │ └── resnet10.prototxt
│ ├── Primary_Detector_Nano
│ │ ├── labels.txt
│ │ ├── resnet10.caffemodel
│ │ ├── resnet10.caffemodel_b12_fp16.engine
│ │ └── resnet10.prototxt
│ ├── Secondary_CarColor // 2nd GIE Classfication
│ │ ├── cal_trt.bin
│ │ ├── labels.txt
│ │ ├── mean.ppm
│ │ ├── resnet18.caffemodel
│ │ ├── resnet18.caffemodel_b16_int8.engine
│ │ └── resnet18.prototxt
│ ├── Secondary_CarMake // 2nd GIE Classfication
│ │ ├── cal_trt.bin
│ │ ├── labels.txt
│ │ ├── mean.ppm
│ │ ├── resnet18.caffemodel
│ │ ├── resnet18.caffemodel_b16_int8.engine
│ │ └── resnet18.prototxt
│ ├── Secondary_VehicleTypes // 2nd GIE Classfication
│ │ ├── cal_trt.bin
│ │ ├── labels.txt
│ │ ├── mean.ppm
│ │ ├── resnet18.caffemodel
│ │ ├── resnet18.caffemodel_b16_int8.engine
│ │ └── resnet18.prototxt
│ └── Segmentation // 이전 Segmentation을 위한 UFF Format Model 2개
│ ├── industrial
│ │ ├── unet_output_graph.uff
│ │ ├── unet_output_graph.uff_b1_fp32.engine
│ │ └── unet_output_graph.uff_b2_fp32.engine
│ └── semantic
│ ├── unetres18_v4_pruned0.65_800_data.uff
│ └── unetres18_v4_pruned0.65_800_data.uff_b2_fp32.engine
├── streams //예제 동영상
│ ├── sample_1080p_h264.mp4
│ ├── sample_1080p_h265.mp4
│ ├── sample_720p.h264
│ ├── sample_720p.jpg
│ ├── sample_720p.mjpeg
│ ├── sample_720p.mp4
│ ├── sample_cam6.mp4
│ └── sample_industrial.jpg
└── streams2 // 내가 복사해서 만든 예제
└── sample_720p.h264
- Source 구조
$ cd ~/deepstream-4.0/sources
$ tree
.
├── apps
│ ├── apps-common
│ │ ├── includes
│ │ │ ├── deepstream_app_version.h
│ │ │ ├── deepstream_common.h
│ │ │ ├── deepstream_config_file_parser.h
│ │ │ ├── deepstream_config.h // DeepStream PLUGIN 확인
│ │ │ ├── deepstream_dewarper.h
│ │ │ ├── deepstream_dsexample.h
│ │ │ ├── deepstream_gie.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_dewarper_bin.c
│ │ ├── deepstream_dsexample.c
│ │ ├── deepstream_osd_bin.c
│ │ ├── deepstream_perf.c
│ │ ├── deepstream_primary_gie_bin.c
│ │ ├── deepstream_secondary_gie_bin.c
│ │ ├── deepstream_sink_bin.c
│ │ ├── deepstream_source_bin.c
│ │ ├── deepstream_streammux.c
│ │ ├── deepstream_tiled_display_bin.c
│ │ └── deepstream_tracker_bin.c
│ └── sample_apps
│ ├── deepstream-app
│ │ ├── deepstream_app.c
│ │ ├── deepstream_app_config_parser.c
│ │ ├── deepstream_app.h
│ │ ├── deepstream_app_main.c
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-dewarper-test
│ │ ├── config_dewarper.txt
│ │ ├── csv_files
│ │ │ ├── nvaisle_2M.csv
│ │ │ └── nvspot_2M.csv
│ │ ├── deepstream_dewarper_test.c
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-gst-metadata-test
│ │ ├── deepstream-gst-metadata-app
│ │ ├── deepstream_gst_metadata.c
│ │ ├── deepstream_gst_metadata.o
│ │ ├── dsmeta_pgie_config.txt
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-image-decode-test
│ │ ├── deepstream_image_decode_app.c
│ │ ├── dstest_image_decode_pgie_config.txt
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-infer-tensor-meta-test
│ │ ├── deepstream_infer_tensor_meta_test.cpp
│ │ ├── dstensor_pgie_config.txt
│ │ ├── dstensor_sgie1_config.txt
│ │ ├── dstensor_sgie2_config.txt
│ │ ├── dstensor_sgie3_config.txt
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-nvof-test
│ │ ├── deepstream_nvof_test.c
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-perf-demo
│ │ ├── deepstream-perf-demo
│ │ ├── deepstream_perf_demo.cpp
│ │ ├── deepstream_perf_demo.o
│ │ ├── Makefile
│ │ ├── perf_demo_pgie_config.txt
│ │ ├── perf_demo_sgie1_config.txt
│ │ ├── perf_demo_sgie2_config.txt
│ │ ├── perf_demo_sgie3_config.txt
│ │ └── README
│ ├── deepstream-segmentation-test
│ │ ├── deepstream-segmentation-app
│ │ ├── deepstream_segmentation_app.c
│ │ ├── deepstream_segmentation_app.o
│ │ ├── dstest_segmentation_config_industrial.txt
│ │ ├── dstest_segmentation_config_semantic.txt
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-test1
│ │ ├── deepstream-test1-app
│ │ ├── deepstream_test1_app.c
│ │ ├── deepstream_test1_app.o
│ │ ├── dstest1_pgie_config.txt
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-test2 // 가장 많이 사용할 예제 인것 같으며, TEST3와 같이 결합하면, RTSP지원
│ │ ├── deepstream-test2-app
│ │ ├── deepstream_test2_app.c
│ │ ├── deepstream_test2_app.o
│ │ ├── dstest2_pgie_config.txt
│ │ ├── dstest2_sgie1_config.txt
│ │ ├── dstest2_sgie2_config.txt
│ │ ├── dstest2_sgie3_config.txt
│ │ ├── dstest2_tracker_config.txt
│ │ ├── Makefile
│ │ ├── README
│ │ └── tracker_config.yml
│ ├── deepstream-test3
│ │ ├── deepstream-test3-app
│ │ ├── deepstream_test3_app.c
│ │ ├── deepstream_test3_app.o
│ │ ├── dstest3_pgie_config.txt
│ │ ├── Makefile
│ │ └── README
│ ├── deepstream-test4
│ │ ├── cfg_amqp.txt
│ │ ├── cfg_azure.txt
│ │ ├── cfg_kafka.txt
│ │ ├── deepstream-test4-app
│ │ ├── deepstream_test4_app.c
│ │ ├── deepstream_test4_app.o
│ │ ├── dstest4_msgconv_config.txt
│ │ ├── dstest4_pgie_config.txt
│ │ ├── Makefile
│ │ └── README
│ └── deepstream-user-metadata-test
│ ├── deepstream-user-metadata-app
│ ├── deepstream_user_metadata_app.c
│ ├── deepstream_user_metadata_app.o
│ ├── dsmeta_pgie_config.txt
│ ├── Makefile
│ └── README
├── gst-plugins
│ ├── gst-dsexample
│ │ ├── dsexample_lib
│ │ │ ├── dsexample_lib.c
│ │ │ ├── dsexample_lib.h
│ │ │ └── Makefile
│ │ ├── gstdsexample.cpp
│ │ ├── gstdsexample.h
│ │ ├── Makefile
│ │ └── README
│ ├── gst-nvinfer
│ │ ├── gstnvinfer_allocator.cpp
│ │ ├── gstnvinfer_allocator.h
│ │ ├── gstnvinfer.cpp
│ │ ├── gstnvinfer.h
│ │ ├── gstnvinfer_meta_utils.cpp
│ │ ├── gstnvinfer_meta_utils.h
│ │ ├── gstnvinfer_property_parser.cpp
│ │ ├── gstnvinfer_property_parser.h
│ │ ├── Makefile
│ │ └── README
│ ├── gst-nvmsgbroker
│ │ ├── gstnvmsgbroker.c
│ │ ├── gstnvmsgbroker.h
│ │ ├── Makefile
│ │ └── README
│ └── gst-nvmsgconv
│ ├── gstnvmsgconv.c
│ ├── gstnvmsgconv.h
│ ├── Makefile
│ └── README
├── includes
│ ├── gstnvdsinfer.h
│ ├── gstnvdsmeta.h
│ ├── gst-nvevent.h
│ ├── gst-nvmessage.h
│ ├── gst-nvquery.h
│ ├── nvbufsurface.h
│ ├── nvbufsurftransform.h
│ ├── nvds_dewarper_meta.h
│ ├── nvdsinfer_context.h
│ ├── nvdsinfer_custom_impl.h
│ ├── nvdsinfer_dbscan.h
│ ├── nvdsinfer.h
│ ├── nvdsinfer_tlt.h
│ ├── nvdsinfer_utils.h
│ ├── nvds_latency_meta.h
│ ├── nvds_logger.h
│ ├── nvdsmeta.h //NvDsFrameMeta , NvDsObjectMeta 구조를 파악 DeepStream SDK API에서도 확인가능
│ ├── nvdsmeta_schema.h
│ ├── nvds_msgapi.h
│ ├── nvds_opticalflow_meta.h
│ ├── nvdstracker.h
│ ├── nvds_version.h
│ ├── nvll_osd_api.h
│ └── nvll_osd_struct.h
├── libs
│ ├── amqp_protocol_adaptor
│ │ ├── cfg_amqp.txt
│ │ ├── Makefile.test
│ │ ├── README
│ │ ├── test_amqp_proto_async.c
│ │ └── test_amqp_proto_sync.c
│ ├── azure_protocol_adaptor
│ │ ├── device_client
│ │ │ ├── cfg_azure.txt
│ │ │ ├── Makefile.test
│ │ │ ├── README
│ │ │ ├── test_azure_proto_async.c
│ │ │ └── test_azure_proto_sync.c
│ │ └── module_client
│ │ ├── cfg_azure.txt
│ │ ├── Dockerfile
│ │ ├── Makefile.test
│ │ ├── README
│ │ ├── test_azure_iotedge_async.c
│ │ └── test_azure_iotedge_sync.c
│ ├── kafka_protocol_adaptor
│ │ ├── json_helper.cpp
│ │ ├── kafka_client.cpp
│ │ ├── kafka_client.h
│ │ ├── Makefile
│ │ ├── Makefile.test
│ │ ├── nvds_kafka_proto.cpp
│ │ ├── README
│ │ ├── test_kafka_proto_async
│ │ ├── test_kafka_proto_async.cpp
│ │ ├── test_kafka_proto_sync
│ │ └── test_kafka_proto_sync.cpp
│ ├── nvdsinfer
│ │ ├── Makefile
│ │ ├── nvdsinfer_context_impl_capi.cpp
│ │ ├── nvdsinfer_context_impl.cpp
│ │ ├── nvdsinfer_context_impl.h
│ │ ├── nvdsinfer_context_impl_output_parsing.cpp
│ │ ├── nvdsinfer_conversion.cu
│ │ ├── nvdsinfer_conversion.h
│ │ └── README
│ ├── nvdsinfer_customparser
│ │ ├── Makefile
│ │ ├── nvdsinfer_custombboxparser.cpp
│ │ ├── nvdsinfer_customclassifierparser.cpp
│ │ └── README
│ └── nvmsgconv
│ ├── Makefile
│ ├── nvmsgconv.cpp
│ ├── nvmsgconv.h
│ └── README
├── objectDetector_FasterRCNN
│ ├── config_infer_primary_fasterRCNN.txt // Custom Layer 설정확인
│ ├── deepstream_app_config_fasterRCNN.txt
│ ├── labels.txt
│ ├── nvdsinfer_custom_impl_fasterRCNN // IPluginFactory Custom Layer
│ │ ├── factoryFasterRCNN.h
│ │ ├── factoryFasterRCNNLegacy.h
│ │ ├── Makefile
│ │ ├── nvdsinitinputlayers_fasterRCNN.cpp
│ │ ├── nvdsiplugin_fasterRCNN.cpp
│ │ ├── nvdsparsebbox_fasterRCNN.cpp // OutLayer 이름 bbox_pred;cls_prob;rois 3개 사용하여 NvDsInferParseCustomFasterRCNN 생성
│ │ └── nvdssample_fasterRCNN_common.h
│ └── README
├── objectDetector_SSD
│ ├── config_infer_primary_ssd.txt
│ ├── deepstream_app_config_ssd.txt
│ ├── nvdsinfer_custom_impl_ssd
│ │ ├── Makefile
│ │ ├── nvdsiplugin_ssd.cpp //IPlugIn , 상위와 구조가 좀 다름
│ │ └── nvdsparsebbox_ssd.cpp // OutLayer (NMS,NMS_1) 2개를 사용하고 새 CustomLayer NvDsInferParseCustomSSD 생성
│ └── README
├── objectDetector_Yolo
│ ├── config_infer_primary_yoloV2_tiny.txt
│ ├── config_infer_primary_yoloV2.txt
│ ├── config_infer_primary_yoloV3_tiny.txt
│ ├── config_infer_primary_yoloV3.txt
│ ├── deepstream_app_config_yoloV2_tiny.txt
│ ├── deepstream_app_config_yoloV2.txt
│ ├── deepstream_app_config_yoloV3_tiny.txt
│ ├── deepstream_app_config_yoloV3.txt
│ ├── labels.txt
│ ├── nvdsinfer_custom_impl_Yolo // 기존과 다르게 완전히 구성
│ │ ├── kernels.cu
│ │ ├── Makefile
│ │ ├── nvdsinfer_yolo_engine.cpp // 기존과 다르게 Engine도 구성
│ │ ├── nvdsparsebbox_Yolo.cpp // Yolo version 마다 구성 NvDsInferParseCustomYoloV3 생성
│ │ ├── trt_utils.cpp // 필요하면, Layer를 직접 사용
│ │ ├── trt_utils.h
│ │ ├── yolo.cpp // Yolo Engine 생성과 Layer도 직접 추가
│ │ ├── yolo.h
│ │ ├── yoloPlugins.cpp
│ │ └── yoloPlugins.h
│ ├── prebuild.sh
│ ├── README
│ └── yolov3-calibration.table.trt5.1
└── tools
└── nvds_logger
├── README
└── setup_nvds_logger.sh
- DeepStream 봐야할 기본문서들
DeepStream 전체 문서
https://docs.nvidia.com/metropolis/index.html
DeepStream Quick Guide
설치부터 기본사용법을 쉽게 이해할수 있다.
https://docs.nvidia.com/metropolis/deepstream/4.0/dev-guide/index.html
DeepStream PlugIn Manual
DeepStream 의 개별 PlugIn 옵션과 기능의 변화들을 알아야한다.
https://docs.nvidia.com/metropolis/deepstream/4.0/DeepStream_Plugin_Manual.pdf
- DeepStream Source를 수정시 봐야할 문서
DeepStream SDK 4.0 API
소스 수정시 내부 관련 함수이해를 위해서 봐야함
https://docs.nvidia.com/metropolis/deepstream/4.0/dev-guide/DeepStream_Development_Guide/baggage/index.html
Jetson Multimedia Document
Multimedia 관련부분의 문서로 Buffer 관련부분
https://docs.nvidia.com/jetson/l4t-multimedia/index.html
2. Gst-Invfer 구조 변화 와 TensorRT의 IPlugIn 사용예제
이번의 DeepStream SDK 4.0으로 오면서 MetaData구조가 변경이 되었는데, 그 부분의 이전의 부분에서 확인하자.
변경된 특징을 정리해보면,
- Transfer-learning-Toolkit encoded Model 지원 ( Model을 재학습이 가능 , 추후 테스트)
- Tensor output as meta ( Gst Buffer로 meata data를 포함해서 보낸다고 하는데, Sample 예제 있는 것 같다)
- Segmentation Model 지원 ( 이부분 이전에 테스트한 Segmetation 부분같다)
- Gray input Model ( Gray input Model 이 별도로 존재이유를 아직 잘 모르겠음)
- Yolo 의 지원인데, 이전 DS3.0 도 Github를 통해서 지원이 가능했으므로, 별로
자세한 properties는 아래의 PlugIn Manual에서 참조하자
관련문서
https://docs.nvidia.com/metropolis/deepstream/4.0/DeepStream_Plugin_Manual.pdf
2.1 IPlugIn FastRCNN 기능확인 (Caffe기반 )
이전과 거의 동일하하기에 자세한 부분은 생략
$ cd ~/deepstream-4.0/sources/objectDetector_FasterRCNN
$ wget --no-check-certificate \
https://dl.dropboxusercontent.com/s/o6ii098bu51d139/faster_rcnn_models.tgz?dl=0 \
-O faster-rcnn.tgz
$ tar zxvf faster-rcnn.tgz -C . --strip-components=1 --exclude=ZF_*
faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
$ cp /usr/src/tensorrt/data/faster-rcnn/faster_rcnn_test_iplugin.prototxt .
$ ls
config_infer_primary_fasterRCNN.txt faster-rcnn.tgz README
deepstream_app_config_fasterRCNN.txt labels.txt VGG16_faster_rcnn_final.caffemodel
faster_rcnn_test_iplugin.prototxt nvdsinfer_custom_impl_fasterRCNN
$ make -C nvdsinfer_custom_impl_fasterRCNN
$ ls nvdsinfer_custom_impl_fasterRCNN/libnvdsinfer_custom_impl_fasterRCNN.so
libnvdsinfer_custom_impl_fasterRCNN.so // 생성확인
DS 3.0과 다르게 Gstreamer로 실행해도 Label이 실행됨
$ 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_fasterRCNN.txt ! \
nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink
$ deepstream-app -c deepstream_app_config_fasterRCNN.txt
기존보다 약간 좋게 8FPS 정도를 유지하는 것 같다.
2.2 IPlugIn SSD 기능확인 (UFF, Tensorlfow 기반)
이전에는 DS3.0에서는 x86에서 이를 변환(convert-uff)하여 만들어서 가져와서 테스트를 했으나, 이번에는 버전은 Jetson에 이미 존재하므로,쉽게 설치하고 실행가능하다
- Tensorflow 설치진행 (시간이 많이 걸림)
README에서 Tensorflow로 설치를 권장하여, Tensorflow로 설치진행
# install prerequisites $ sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev # install and upgrade pip3 $ sudo apt-get install python3-pip $ sudo pip3 install -U pip # install the following python packages $ sudo pip3 install -U numpy grpcio absl-py py-cpuinfo psutil portpicker six mock requests gast h5py astor termcolor protobuf keras-applications keras-preprocessing wrapt google-pasta setuptools testresources # install the latest version of TensorFlow $ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu
Tensorflow 설치관련문서 (NVIDIA 문서를 참조를 해야 에러가 없음)
https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform/index.html#prereqs
https://elinux.org/Jetson_Zoo#TensorFlow
- convert_to_uff.py 를 이용하여 PB->UFF 포맷으로 변경
처음 Tensorflow를 미설치하고 아래 같이 진행하며, 에러가 발생하는 것 같아 Tensorflow를 별도를 설치를 했는데, 아래의 에러발생
$ cd ~/deepstream-4.0/sources/objectDetector_SSD $ cp /usr/src/tensorrt/data/ssd/ssd_coco_labels.txt . $ wget http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2017_11_17.tar.gz $ tar zxvf ssd_inception_v2_coco_2017_11_17.tar.gz ssd_inception_v2_coco_2017_11_17/ ssd_inception_v2_coco_2017_11_17/model.ckpt.index ssd_inception_v2_coco_2017_11_17/model.ckpt.meta ssd_inception_v2_coco_2017_11_17/frozen_inference_graph.pb ssd_inception_v2_coco_2017_11_17/model.ckpt.data-00000-of-00001 ssd_inception_v2_coco_2017_11_17/saved_model/ ssd_inception_v2_coco_2017_11_17/saved_model/saved_model.pb ssd_inception_v2_coco_2017_11_17/saved_model/variables/ ssd_inception_v2_coco_2017_11_17/checkpoint $ 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 Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/uff/bin/convert_to_uff.py", line 15, inimport uff File "/usr/lib/python2.7/dist-packages/uff/__init__.py", line 1, in $ pip list | grep protobuf // Tensorflow-GPU 설치를 해도 동일해서 Package 검색 protobuf 3.9.1from uff import converters, model # noqa File "/usr/lib/python2.7/dist-packages/uff/model/__init__.py", line 1, in from . import uff_pb2 as uff_pb # noqa File "/usr/lib/python2.7/dist-packages/uff/model/uff_pb2.py", line 6, in from google.protobuf.internal import enum_type_wrapper ImportError: No module named google.protobuf.internal
- Python 3로 해결 ( Anaconda , 이문제인줄 알았는데, 아님)
$ python3 /usr/lib/python3.6/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 No. nodes: 563 UFF Output written to sample_ssd_relu6.uff $ cp sample_ssd_relu6.uff .. $ cd .. $ pwd /home/nvidia/deepstream-4.0/sources/objectDetector_SSD $ export CUDA_VER=10.0 $ make -C nvdsinfer_custom_impl_ssd $ ls nvdsinfer_custom_impl_ssd/libnvdsinfer_custom_impl_ssd.so nvdsinfer_custom_impl_ssd/libnvdsinfer_custom_impl_ssd.so
관련자료
https://www.cnblogs.com/sdu20112013/p/10702173.html
$ 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
//Gst-Tracker 도 동작됨
$ 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 ! \
nvtracker tracker-width=640 tracker-height=368 gpu-id=0 \
ll-lib-file=/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so \
ll-config-file=tracker_config.yml enable-batch-process=1 ! \
nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink
// dstest2_sgie1_config.txt 를 test2에서 가져와야하며 내부 PATH를 제대로 설정해주면, 동작은 되지만, Batch Size 문제로 Engine을 새로생성하느라고 시간이 걸림
//상위와 동일하게 동작 (2nd nvinfer는 미동작, Gst-Tracker 까지는 동작됨)
$ 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 ! \
nvtracker tracker-width=640 tracker-height=368 gpu-id=0 \
ll-lib-file=/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so \
ll-config-file=tracker_config.yml enable-batch-process=1 ! \
nvinfer config-file-path= dstest2_sgie1_config.txt ! \
nvinfer config-file-path= dstest2_sgie2_config.txt ! \
nvinfer config-file-path= dstest2_sgie3_config.txt ! \
nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink
$ deepstream-app -c deepstream_app_config_ssd.txt
기존과 동일하게 실시간 동작하며, Gstreamer로 해도 Label 표시 (30FPS로 동작)
- Config 설정부분
$ vi ./config_infer_primary_ssd.txt .... [property] gpu-id=0 net-scale-factor=0.0078431372 offsets=127.5;127.5;127.5 model-color-format=0 model-engine-file=sample_ssd_relu6.uff_b1_fp32.engine // TensorRT Engine labelfile-path=ssd_coco_labels.txt uff-file=sample_ssd_relu6.uff // Caffe Model 이 아니므로 UFF-File , Caffe는 model-file uff-input-dims=3;300;300;0 uff-input-blob-name=Input batch-size=1 ## 0=FP32, 1=INT8, 2=FP16 mode network-mode=0 num-detected-classes=91 interval=0 gie-unique-id=1 is-classifier=0 output-blob-names=MarkOutput_0 parse-bbox-func-name=NvDsInferParseCustomSSD // BBox 함수 custom-lib-path=nvdsinfer_custom_impl_ssd/libnvdsinfer_custom_impl_ssd.so // Custom Layer (IPlugIn [class-attrs-all] threshold=0.5 roi-top-offset=0 roi-bottom-offset=0 detected-min-w=0 detected-min-h=0 detected-max-w=0 detected-max-h=0 .......
- DeepStream SDK 3.0 IPlugIn 사용
https://ahyuo79.blogspot.com/2019/07/deepstream-gst-nvinfer-tensorrt-iplugin.html
2.3 IPlugIn Yolov3 (TensorRT Directly)
이전에 DeepStream SDK 3.0에서 Github를 통해 Download하여 Build하고 테스트한 부분이 이번 버전에 반영이 되었다.
DeepStream SDK 3.0 Yolo 사용
https://ahyuo79.blogspot.com/2019/07/deepstream-30-sdk-deepstream-referece.html
TensorRT Example(이전 DS3.0의 Yolo가 아니고, TensorRT 예제)에서는 Yolov3를 ONNX로 변경해서 사용했던것으로 기억하는데,
이번 것은 어떻게 동작이 되는지 사실 이해가 안된다, 이전의 DS 3.0에서도 구조가 비슷한 것 같은데, 지금 구조를 보면 Caffe Model로 설정사용을 하는데, 이부분은 좀 의아했다.
$ cd ~/deepstream-4.0/sources/objectDetector_Yolo // 원래 opt 지만, 본인은 소스보호를 위해 이쪽으로 복사했음 $ ./prebuild.sh // 이전과 유사하게 yolo에 관련된 weight 와 cfg download $ ls /usr/local/cuda-10.0 // CUDA Version 확인 $ export CUDA_VER=10.0 $ make -C nvdsinfer_custom_impl_Yolo
- Yolov3 와 Yolov2 실행 (Gstreamer 과 deepstream)
//Yolov3 TEST
$ 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_yoloV3.txt ! \
nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink
//YoloV2 TEST
$ 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_yoloV2.txt ! \
nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink
만약 아래처럼 Tracker 와 2차 Classification TensorRT를 삽입을 해도 되지만, 사람도 적용이 되어 문제발생 , 속도가 느리다면, model-engine을 반드시 정의 및 복사
$ 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_yoloV3.txt ! \
nvtracker tracker-width=640 tracker-height=368 gpu-id=0 \
ll-lib-file=/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_nvdcf.so \
ll-config-file=../objectDetector_SSD/tracker_config.yml enable-batch-process=1 ! \
nvinfer config-file-path= ../objectDetector_SSD/dstest2_sgie1_config.txt ! \
nvinfer config-file-path= ../objectDetector_SSD/dstest2_sgie2_config.txt ! \
nvinfer config-file-path= ../objectDetector_SSD/dstest2_sgie3_config.txt ! \
nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink
//실제 Yolo TEST 진행
$ deepstream-app -c deepstream_app_config_yoloV3.txt //26~27 FPS
$ deepstream-app -c deepstream_app_config_yoloV3_tiny.txt //60~61 FPS
$ deepstream-app -c deepstream_app_config_yoloV2.txt //18 FPS
$ deepstream-app -c deepstream_app_config_yoloV2_tiny.txt //60~61 FPS
yolov3
yolov3_tiny
- Yolo Config
$ vi ./config_infer_primary_yoloV3.txt //model-engine-file 을 선언해주면, 매번 TensorRT Engine을 생성할 필요없다. .... [property] gpu-id=0 net-scale-factor=1 #0=RGB, 1=BGR model-color-format=0 custom-network-config=yolov3.cfg model-file=yolov3.weights // modle-file 이 yolov3.weight 인데, Caffe Model이 아니여서 혼동 model-engine-file=model_b1_int8.engine // 처음 정의 되어 있지 않다면 반드시 정의 labelfile-path=labels.txt int8-calib-file=yolov3-calibration.table.trt5.1 // INT8로 사용시 별도로 필요한 Table (Jetson Xavier) ## 0=FP32, 1=INT8, 2=FP16 mode network-mode=1 num-detected-classes=80 gie-unique-id=1 is-classifier=0 maintain-aspect-ratio=1 parse-bbox-func-name=NvDsInferParseCustomYoloV3 custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so // Custom Layer로 연결 , 아래 설명 .......
- 설정부분 재확인 (model-file 은 Caffe Model만 지원)
- Custom Layer 부분
$ tree nvdsinfer_custom_impl_Yolo/ nvdsinfer_custom_impl_Yolo/ ├── kernels.cu //Implementation of cuda kernels for ├── kernels.o ├── libnvdsinfer_custom_impl_Yolo.so // 상위 config 설정 ├── Makefile ├── nvdsinfer_yolo_engine.cpp //Implementation of 'NvDsInferCudaEngineGet' for nvdsinfer to create cuda engine ├── nvdsinfer_yolo_engine.o ├── nvdsparsebbox_Yolo.cpp //Output layer , BBox Function 상위 NvDsInferParseCustomYoloV3 정의 이전 IPlugIn 구조와 유사 ├── nvdsparsebbox_Yolo.o ├── trt_utils.cpp //Implementation of Utilities to setup tensorRT networks ├── trt_utils.h //Utilities to setup tensorRT networks ├── trt_utils.o ├── yolo.cpp //Implementation to create Yolo Cuda-Engine ( IPluginV2) ├── yolo.h //Interface to create Yolo Cuda-Engine ├── yolo.o ├── yoloPlugins.cpp //Implementation of YoloLayerV3 and YoloLayerV3PluginCreator (IPluginV2) ├── yoloPlugins.h //Declaration of YoloLayerV3 and YoloLayerV3PluginCreator └── yoloPlugins.o
- NVIDIA에 Yolo 모델 관련질문
TensorRT의 예제와 구성이 다르니 이 부분을 알아두어야 겠다.
직접 TensorRT에 Network를 구성하여 구현을 했다고 한다.
https://devtalk.nvidia.com/default/topic/1061574/deepstream-sdk/objectdetector_yolo-in-ds-4-0-on-xavier-/post/5375710/#5375710
3. DeepStream-test4
3.1 Kafka 환경구성
- libnvds_kafka_proto.so 빌드 및 테스트 프로그램 빌드 (생략가능)
$ sudo apt-get update $ sudo apt-get install libglib2.0 libglib2.0-dev $ sudo apt-get install libjansson4 libjansson-dev $ sudo apt-get install librdkafka1=0.11.3-1build1 // rdkafka.h 파일이 없음 or // 직접설치로 변경 $ cd ~ $ git clone https://github.com/edenhill/librdkafka.git $ cd librdkafka $ git reset --hard 7101c2310341ab3f4675fc565f64f0967e135a6a $ ./configure $ make $ sudo make install $ sudo cp /usr/local/lib/librdkafka* /opt/nvidia/deepstream/deepstream-4.0/lib/ $ cd ~/deepstream-4.0/sources/libs/kafka_protocol_adaptor $ make // libnvds_kafka_proto.so (apt install 하면 , rdkafka.h: 문제발생) $ make -f Makefile.test // test_sample_proto_sync , test_sample_proto_async 생성 $ find / -name libnvds_kafka_proto.so 2> /dev/null /home/nvidia/deepstream-4.0/sources/libs/kafka_protocol_adaptor/libnvds_kafka_proto.so // 지금 설치한 것 /home/nvidia/deepstream-4.0/lib/libnvds_kafka_proto.so // lib 제공 /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_kafka_proto.so // lib 제공
- Zookeeper 및 Kafka 설치
//Zookeeper 설치 $ sudo apt-get install zookeeperd /etc/zookeeper/conf /etc/zookeeper/conf_example $ cat /etc/zookeeper/conf/zoo.cfg .... //설치후 Zookeeper 동작확인 $ netstat -nlp|grep 2181 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp6 0 0 :::2181 :::* LISTEN $ sudo /usr/share/zookeeper/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /etc/zookeeper/conf/zoo.cfg Mode: standalone //Kafka 설치 $ cd ~ $ wget http://www-us.apache.org/dist/kafka/2.2.1/kafka_2.12-2.2.1.tgz //download 가능 (다른version가능) $ tar zxvf kafka_2.12-2.2.1.tgz $ sudo mv kafka_2.12-2.2.1 /usr/local/kafka $ cd /usr/local/kafka $ vi config/server.properties // Log Data 설정된 장소확인 및 변경 log.dirs=/tmp/kafka-logs/ $ sudo vi /etc/systemd/system/kafka.service // 새로운 File 생성 [Unit] Description=kafka-server After=network.target [Service] Type=simple User=root Group=root SyslogIdentifier=kafka-server WorkingDirectory=/usr/local/kafka Restart=no RestartSec=0s ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh $ systemctl daemon-reload $ systemctl enable kafka.service $ systemctl start kafka.service $ systemctl status kafka.service 8월 01 11:21:32 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:32,939] INFO [GroupMetadataManager brokerId=0] Removed 0 expired offsets in 8 milliseconds. (kafka.coordinator.group.GroupMe 8월 01 11:21:32 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:32,968] INFO [ProducerId Manager 0]: Acquired new producerId block (brokerId:0,blockStartProducerId:0,blockEndProducerId:999 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,016] INFO [TransactionCoordinator id=0] Starting up. (kafka.coordinator.transaction.TransactionCoordinator) 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,022] INFO [Transaction Marker Channel Manager 0]: Starting (kafka.coordinator.transaction.TransactionMarkerChannelManager 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,022] INFO [TransactionCoordinator id=0] Startup complete. (kafka.coordinator.transaction.TransactionCoordinator) 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,141] INFO [/config/changes-event-process-thread]: Starting (kafka.common.ZkNodeChangeNotificationListener$ChangeEventProc 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,185] INFO [SocketServer brokerId=0] Started data-plane processors for 1 acceptors (kafka.network.SocketServer) 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,208] INFO Kafka version: 2.2.1 (org.apache.kafka.common.utils.AppInfoParser) 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,208] INFO Kafka commitId: 55783d3133a5a49a (org.apache.kafka.common.utils.AppInfoParser) 8월 01 11:21:33 nvidia-desktop kafka-server[6521]: [2019-08-01 11:21:33,212] INFO [KafkaServer id=0] started (kafka.server.KafkaServer) $ sudo apt install lsof $ sudo lsof -i :2181 //Zookeeper 만 동작될 때 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 18819 zookeeper 43u IPv6 759187 0t0 TCP *:2181 (LISTEN) $ sudo lsof -i :2181 //Zookeeper 와 Kafka 동작될 때 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 22350 nvidia 109u IPv6 767085 0t0 TCP *:2181 (LISTEN) java 22350 nvidia 110u IPv6 761679 0t0 TCP localhost:2181->localhost:46018 (ESTABLISHED) java 22675 nvidia 109u IPv6 766151 0t0 TCP localhost:46018->localhost:2181 (ESTABLISHED)
- Kafka Topic 생성 및 확인
$ /usr/local/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic dsapp Created topic dsapp. $ /usr/local/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testTopic Created topic testTopic. $ /usr/local/kafka/bin/kafka-topics.sh --list --zookeeper localhost:2181 // Topic list 확인 __consumer_offsets dsapp testTopic $ ls /tmp/kafka-logs/ cleaner-offset-checkpoint __consumer_offsets-17 __consumer_offsets-26 __consumer_offsets-35 __consumer_offsets-44 __consumer_offsets-9 __consumer_offsets-0 __consumer_offsets-18 __consumer_offsets-27 __consumer_offsets-36 __consumer_offsets-45 dsapp-0 __consumer_offsets-1 __consumer_offsets-19 __consumer_offsets-28 __consumer_offsets-37 __consumer_offsets-46 log-start-offset-checkpoint __consumer_offsets-10 __consumer_offsets-2 __consumer_offsets-29 __consumer_offsets-38 __consumer_offsets-47 meta.properties __consumer_offsets-11 __consumer_offsets-20 __consumer_offsets-3 __consumer_offsets-39 __consumer_offsets-48 recovery-point-offset-checkpoint __consumer_offsets-12 __consumer_offsets-21 __consumer_offsets-30 __consumer_offsets-4 __consumer_offsets-49 replication-offset-checkpoint __consumer_offsets-13 __consumer_offsets-22 __consumer_offsets-31 __consumer_offsets-40 __consumer_offsets-5 testTopic-0 __consumer_offsets-14 __consumer_offsets-23 __consumer_offsets-32 __consumer_offsets-41 __consumer_offsets-6 __consumer_offsets-15 __consumer_offsets-24 __consumer_offsets-33 __consumer_offsets-42 __consumer_offsets-7 __consumer_offsets-16 __consumer_offsets-25 __consumer_offsets-34 __consumer_offsets-43 __consumer_offsets-8
- How to send Messages to Topic
$ /usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic >Welcome to kafka >This is my first topic // Ctrol+c
- How to receive Messages from Topic
$ /usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning Welcome to kafka This is my first topic
- deepstream-test4-app
$ cd ~/deepstream-4.0/sources/apps/sample_apps/deepstream-test4 $ make $./deepstream-test4-app -i ../../../../samples/streams/sample_720p.h264 -p /home/nvidia/deepstream-4.0/lib/libnvds_kafka_proto.so --conn-str="127.0.0.1;9092;dsapp" -c cfg_kafka.txt -s 1 // $ cat /etc/ld.so.conf include /etc/ld.so.conf.d/*.conf $ ls /etc/ld.so.conf.d/ aarch64-linux-gnu.conf aarch64-linux-gnu_EGL.conf aarch64-linux-gnu_GL.conf cuda-10-0.conf deepstream.conf fakeroot-aarch64-linux-gnu.conf libc.conf nvidia-tegra.conf $ cat /etc/ld.so.conf.d/deepstream.conf //이곳밖에 못찾음 /opt/nvidia/deepstream/deepstream-4.0/lib $ sudo ldconfig // 상위 ld.so.conf 변화가 있거나, lib path를 추가 했을 경우 실행 $./deepstream-test4-app -i ../../../../samples/streams/sample_720p.h264 -p /opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_kafka_proto.so --conn-str="127.0.0.1;9092;dsapp" -c cfg_kafka.txt -s 1 //
- How to receive Messages from Topic
$ /usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic dsapp --from-beginning
{
"messageid" : "53724824-163f-43e5-bbf7-41c4cca4fc05",
"mdsversion" : "1.0",
"@timestamp" : "2019-08-05T05:42:27.060Z",
"place" : {
"id" : "1",
"name" : "XYZ",
"type" : "garage",
"location" : {
"lat" : 30.32,
"lon" : -40.549999999999997,
"alt" : 100.0
},
"aisle" : {
"id" : "walsh",
"name" : "lane1",
"level" : "P2",
"coordinate" : {
"x" : 1.0,
"y" : 2.0,
"z" : 3.0
}
}
},
..........
- Deepstream SDK 3.0 Kafka 구성
https://ahyuo79.blogspot.com/2019/07/deepstream-sdk-30-kafka.html?zx=944829aea867a266







