欢送关注我的公众号 [极智视界],回复001获取Google编程标准
O_o
>_<
o_O
O_o
~_~
o_O
大家好,我是极智视界,本文介绍了应用 deepstream6.0 部署 yolov3 和 yolov4 的办法。
Yolo 系列是工程中利用非常宽泛的指标检测算法,特地是从 yolov3 开始,逐渐的进化,到 yolov4、yolov5 等,工程的接受度越来越高。而 deepstream 是英伟达提出的一套减速深度学习落地的 pipeline 利用,那么当 deepstream 遇到 yolo,会擦出什么样的火花呢,让咱们来看。
对于 deepstream 的装置教程,能够查阅我之前写的几篇:《【教训分享】ubuntu 装置 deepstream6.0》、《【教训分享】ubuntu 装置 deepstream5.1》。
先来看下 deepstream6.0 source 的目录构造:
apps
- apps-common
- audio_apps
- sample_apps:例程,如 deepstream-app、deepstream-test1...
- gst-plugins:gstreamer 插件
- include:头
- libs:库
- objectDetector_FasterRCNN:FasterRCNN 示例
- objectDetector_SSD:SSD 示例
- objectDetector_Yolo:YOLO 示例
- tools: 日志相干
1、deepstream6.0 部署 yolov3
通过上述的 objectDetector_Yolo 工程来跑 yolov3,在 objectDetector_Yolo 工程里次要关注以下几个模块:
nvdsinfer_custom_impl_Yolo:yolov3 工程实现代码;
- nvdsinfer_yolo_engine.cpp:解析模型、生成引擎
- nvdsparsebbox_Yolo.cpp:输入层的解析函数,解析指标检测框
- trt_utils.cpp 和 trt_utils.h:结构 TensorRT网络的工具类的接口和实现
- yolo.cpp 和 yolo.h:生成 yolo 引擎的接口和实现
- yoloPlugins.cpp 和 yoloPlugins.h:YoloLayerV3 and YoloLayerV3PluginCreator 的接口和实现
- kernels.cu:cuda核底层实现
- config_infer_xxx_.txt:模型的配置;
- deepstream_app_config_xxx.txt:Gstreamer nvinfer 插件的配置文件;
- xxx.cfg、xxx.weights:模型文件;
有以上这些就够了,上面开始。
1.1 下载模型文件
deepstream6.0 SDK 中是没有 yolov3 的模型文件的,须要自行下载,给出传送。
yolov3.cfg:https://github.com/pjreddie/d...;
yolov3.weights:https://link.zhihu.com/?targe...;
这里多说一句,如果你有 TensorRT 的 yolov3.engine 的话,就不须要原始模型文件了,如果没有 .engine 的话,其实会依据原始文件学生成 .engine。
1.2 配置 config_infer_primary_yolov3.txt
[property]gpu-id=0net-scale-factor=0.0039215697906911373#0=RGB, 1=BGRmodel-color-format=0custom-network-config=yolov3.cfgmodel-file=yolov3.weightslabelfile-path=labels.txtint8-calib-file=yolov3-calibration.table.trt7.0## 0=FP32, 1=INT8, 2=FP16 modenetwork-mode=1num-detected-classes=80gie-unique-id=1network-type=0is-classifier=0cluster-mode=2maintain-aspect-ratio=1parse-bbox-func-name=NvDsInferParseCustomYoloV3custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.soengine-create-func-name=NvDsInferYoloCudaEngineGet[class-attrs-all]nms-iou-threshold=0.3threshold=0.7
1.3 配置 deepstream_app_config_yolov3.txt
[application]enable-perf-measurement=1perf-measurement-interval-sec=5[tiled-display]enable=1rows=1columns=1width=1280height=720gpu-id=0nvbuf-memory-type=0[source0]enable=1type=3uri=file://../../samples/streams/sample_1080p_h264.mp4num-sources=1gpu-id=0cudadec-memtype=0[sink0]enable=1#Type - 1=FakeSink 2=EglSink 3=Filetype=2sync=0source-id=0gpu-id=0nvbuf-memory-type=0[osd]enable=1gpu-id=0border-width=1text-size=15text-color=1;1;1;1;text-bg-color=0.3;0.3;0.3;1font=Serifshow-clock=0clock-x-offset=800clock-y-offset=820clock-text-size=12clock-color=1;0;0;0nvbuf-memory-type=0[streammux]gpu-id=0live-source=0batch-size=1batched-push-timeout=40000width=1920height=1080enable-padding=0nvbuf-memory-type=0[primary-gie]enable=1gpu-id=0#model-engine-file=model_b1_gpu0_int8.enginelabelfile-path=labels.txtbatch-size=1bbox-border-color0=1;0;0;1bbox-border-color1=0;1;1;1bbox-border-color2=0;0;1;1bbox-border-color3=0;1;0;1interval=2gie-unique-id=1nvbuf-memory-type=0config-file=config_infer_primary_yoloV3.txt[tracker]enable=1tracker-width=640tracker-height=384ll-lib-file=/opt/nvidia/deepstream/deepstream-6.0/lib/libnvds_nvmultiobjecttracker.soll-config-file=../../samples/configs/deepstream-app/config_tracker_NvDCF_perf.ymlgpu-id=0enable-batch-process=1enable-past-frame=1display-tracking-id=1[tests]file-loop=0
1.4 工程编译
进入到 /opt/nvidia/deepstream/deepstream-6.0/sources/objectDetector_Yolo
:
cd /opt/nvidia/deepstream/deepstream-6.0/sources/objectDetector_Yolo
顺次执行上面两条命令,编译生成 .so 文件:
export CUDA_VER=11.4 # 设置与设施雷同的CUDA版本
或者在 /opt/nvidia/deepstream/deepstream-6.0/sources/objectDetector_Yolo/nvdsinfer_custom_impl_Yolo/Makefile
中批改:
而后执行编译
make -C nvdsinfer_custom_impl_Yolo
编译后会生产动静库文件,生成了 libnvdsinfer_custom_impl_Yolo.so
动静库文件。
1.5 执行
deepstream-app -c deepstream_app_config_yoloV3.txt
这里实现了 deepstream6.0 Yolov3 的部署。
2、deepstream6.0 部署 yolov4
这里以不同的形式来部署一下 yolov4,即间接调用 TensorRT Engine,而不是从原始模型导入。
2.1 应用 darknet2onnx2TRT 生成 yolov4.engine
下载 yolov4 darknet 原始权重,给出百度网盘传送:
https://pan.baidu.com/s/1dAGEW8cm-dqK14TbhhVetA Extraction code:dm5b
clone 模型转换工程:
git clone https://github.com/Tianxiaomo/pytorch-YOLOv4.git Yolov42TRT
开始模型转换:
cd Yolov42TRT# darknet2onnxpython demo_darknet2onnx.py ./cfg/yolov4.cfg ./cfg/yolov4.weights ./data/dog.jpg 1# onnx2trttrtexec --onnx=./yolov4_1_3_608_608_static.onnx --fp16 --saveEngine=./yolov4.engine --device=0
这样就会生成 yolov4.engine。
2.2 deepstream yolov4 推理工程配置
clone deepstream yolov4 推理工程:
git clone https://github.com/NVIDIA-AI-IOT/yolov4_deepstream.gitcd yolov4_deepstream/deepstream_yolov4
配置 config_infer_primary_yoloV4.txt:
[property]gpu-id=0net-scale-factor=0.0039215697906911373#0=RGB, 1=BGRmodel-color-format=0model-engine-file=yolov4.enginelabelfile-path=labels.txtbatch-size=1## 0=FP32, 1=INT8, 2=FP16 modenetwork-mode=2num-detected-classes=80gie-unique-id=1network-type=0is-classifier=0## 0=Group Rectangles, 1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering)cluster-mode=2maintain-aspect-ratio=1parse-bbox-func-name=NvDsInferParseCustomYoloV4custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so[class-attrs-all]nms-iou-threshold=0.6pre-cluster-threshold=0.4
配置 deepstream_app_config_yoloV4.txt:
[application]enable-perf-measurement=1perf-measurement-interval-sec=5[tiled-display]enable=0rows=1columns=1width=1280height=720gpu-id=0nvbuf-memory-type=0[source0]enable=1type=3uri=file:/opt/nvidia/deepstream/deepstream-6.0/samples/streams/sample_1080p_h264.mp4num-sources=1gpu-id=0cudadec-memtype=0[sink0]enable=1#Type - 1=FakeSink 2=EglSink 3=Filetype=3sync=0source-id=0gpu-id=0nvbuf-memory-type=0container=1codec=1output-file=yolov4.mp4[osd]enable=1gpu-id=0border-width=1text-size=12text-color=1;1;1;1;text-bg-color=0.3;0.3;0.3;1font=Serifshow-clock=0clock-x-offset=800clock-y-offset=820clock-text-size=12clock-color=1;0;0;0nvbuf-memory-type=0[streammux]gpu-id=0live-source=0batch-size=1batched-push-timeout=40000width=1280height=720enable-padding=0nvbuf-memory-type=0[primary-gie]enable=1gpu-id=0model-engine-file=yolov4.enginelabelfile-path=labels.txtbatch-size=1bbox-border-color0=1;0;0;1bbox-border-color1=0;1;1;1bbox-border-color2=0;0;1;1bbox-border-color3=0;1;0;1interval=0gie-unique-id=1nvbuf-memory-type=0config-file=config_infer_primary_yoloV4.txt[tracker]enable=0tracker-width=512tracker-height=320ll-lib-file=/opt/nvidia/deepstream/deepstream-5.0/lib/libnvds_mot_klt.so[tests]file-loop=0
把 2.1 转换生成的 yolov4.engine 拷贝到 /opt/nvidia/deepstream/deepstream-6.0/sources/yolov4_deepstream
。
2.3 工程编译
进入到 /opt/nvidia/deepstream/deepstream-6.0/sources/yolov4_deepstream
:
cd /opt/nvidia/deepstream/deepstream-6.0/sources/yolov4_deepstream
顺次执行上面两条命令,编译生成 .so 文件:
export CUDA_VER=11.4 # 设置与设施雷同的CUDA版本
或者在 /opt/nvidia/deepstream/deepstream-6.0/sources/yolov4_deepstream/nvdsinfer_custom_impl_Yolo/Makefile
中批改:
而后执行编译
make -C nvdsinfer_custom_impl_Yolo
编译后会生产动静库文件,生成了 libnvdsinfer_custom_impl_Yolo.so
动静库文件。
2.4 执行
deepstream-app -c deepstream_app_config_yoloV4.txt
这里实现了 deepstream6.0 Yolov4 的部署。
以上分享了 deepstream6.0 部署 yolov3 和 yolov4 的办法,心愿我的分享会对你的学习有一点帮忙。
【公众号传送】
《【模型推理】deepstream6.0 部署 yolov3 和 yolov4 教程》