Jetson Nano( 十一)Deepstream6.0 + yolov3/v5多路推理配置流程

Jetson Nano下Deepstream6.0 + yolov3/v5多路推理配置流程;并简单记录下deepstream的配置文件。

Jetson Nano 系列文章:
https://blog.csdn.net/djj199301111/category_11383635.html?spm=1001.2014.3001.5482
Deepstream 6.0.1安装参考上篇文章:
https://blog.csdn.net/djj199301111/article/details/123592402?spm=1001.2014.3001.5501

一.环境

JP 4.6.1
Deepstream 6.0.1
Darknet yolov3-tiny
ultralytics yolov5n/s 6.0

deepstream yolov5项目地址:
https://github.com/marcoslucianops/DeepStream-Yolo

二.大体流程

——1.Deepstream yolov3-tiny:

  • 1.1.准备模型

拷贝weights和cfg文件至下目录:

cd /opt/nvidia/deepstream/deepstream/sources/objectDetector_Yolo
CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo
  • 1.2.运行
 #运行deepstream案例
deepstream-app -c deepstream_app_config_yoloV3_tiny.txt
  • 1.3.自训练模型

1.修改config_infer_primary_yoloV3_tiny.txt 下 的num-detected-classes;
2.修改 labels.txt;
3.修改nvdsparsebbox_Yolo.cpp 下 static const int NUM_CLASSES_YOLO = 80与 anchor;
4.从新编译 :CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo

——2.Deepstream yolov5:

  • 2.1.模型转换(这里建议在电脑上操作,也可在Jeston上操作;需要配置pytorch环境)
git clone https://github.com/marcoslucianops/DeepStream-Yolo.git
cd DeepStream-Yolo/utils
#主要拷贝转换脚本到yolov5项目下即可
cp gen_wts_yoloV5.py ../../yolov5
cd ../../yolov5
python gen_wts_yoloV5.py -w  ./yolov5n.pt -c ./models/yolov5n.yaml
  • 2.2.模型拷贝至Jetson

1.上一步骤运行成功会生成yolov5n.wts 与 yolov5n.cfg 。
2.将2个文件拷贝至Jetson下DeepStream-Yolo 项目下。

  • 2.3.部署模型
git clone https://github.com/marcoslucianops/DeepStream-Yolo.git
#将项目拷贝至deepstream/source下
cp -r DeepStream-Yolo /opt/nvidia/deepstream/deepstream/source
cd /opt/nvidia/deepstream/deepstream/source/DeepStream-Yolo
#这里使用的默认模型
CUDA_VER=10.2 make -C nvdsinfer_custom_impl_Yolo
  • 2.4.自训练模型:

修改 config_infer_primary_yoloV5.txt中的num-detected-classes;
修改 labels.txt;

  • 2.5.运行

修改deepstream_app_config.txt 中 config-file=config_infer_primary_yoloV5.txt

#运行deepstream案例
deepstream-app -c deepstream_app_config.txt

首次运行 Build Engine 会比较久,会根据config_infer_primary_yoloV5.txt构建模型;后续可以注释掉:
custom-network-config=yolov5n.cfg
model-file=yolov5n.wts

三.配置文件说明

  • config_infer_primary_yoloV5.txt
    1.主要用于模型转换配置,是属于模型层面的配置。

[property]
gpu-id=0
net-scale-factor=0.0039215697906911373
##0=RGB, 1=BGR
model-color-format=0
#custom-network-config=yolov3-tiny.cfg
#model-file=yolov3-tiny.weights
model-engine-file=model_b4_gpu0_fp16.engine
labelfile-path=labels.txt
batch-size=4
##0=FP32, 1=INT8, 2=FP16 mode
network-mode=2
##检测类别数
num-detected-classes=80
gie-unique-id=1
network-type=0
is-classifier=0
##1=DBSCAN, 2=NMS, 3= DBSCAN+NMS Hybrid, 4 = None(No clustering)
cluster-mode=2
maintain-aspect-ratio=1
parse-bbox-func-name=NvDsInferParseCustomYoloV3Tiny
custom-lib-path=nvdsinfer_custom_impl_Yolo/libnvdsinfer_custom_impl_Yolo.so
engine-create-func-name=NvDsInferYoloCudaEngineGet
#scaling-filter=0
#scaling-compute-hw=0
[class-attrs-all]
##几项阈值
nms-iou-threshold=0.4
threshold=0.4

  • deepstream_app_config.txt
    1.主要用于deepstream相关视频和显示的配置,是属于应用层的配置。

#这是总的显示UI控制;rows和columns控制画布,这里2*2就是4路;width和height是分辨率
[tiled-display]
enable=1
rows=2
columns=2
width=1280
height=720
gpu-id=0
#(0): nvbuf-mem-default - Default memory allocated, specific to particular platform
#(1): nvbuf-mem-cuda-pinned - Allocate Pinned/Host cuda memory, applicable for Tesla
#(2): nvbuf-mem-cuda-device - Allocate Device cuda memory, applicable for Tesla
#(3): nvbuf-mem-cuda-unified - Allocate Unified cuda memory, applicable for Tesla
#(4): nvbuf-mem-surface-array - Allocate Surface Array memory, applicable for Jetson
nvbuf-memory-type=0

#source和sink是一一对应的关系;这里1组是USB相机的显示

[source1]
#是否开启
enable=1
#Type - 1=CameraV4L2 2=URI 3=MultiURI
type=1
#相机相关参数
camera-width=640
camera-height=480
camera-fps-n=30
camera-fps-d=1
#相机对应dev的节点
camera-v4l2-dev-node=0
————————————————————————
[sink1]
#是否开启
enable=1
#Type - 1=FakeSink 2=EglSink 3=File 4=RTSPStreaming 5=Overlay
type=5
sync=0
display-id=0
offset-x=0
offset-y=0
width=0
height=0
overlay-id=1
source-id=1

[source0]
#是否开启
enable=1
#1:相机(V4L2)2:URI 3:MultiURI(复用URI)4:RTSP 5:相机(CSI)(只针对Jetson)
#Type - 1=CameraV4L2 2=URI 3=MultiURI 4=RTSP
type=3
#编码流的URI。可以是文件,HTTP URI, RTSP.只有type=2和3的时候有效。
uri=file://…/…/samples/streams/2.mp4
#资源数,只有当type=3时有效
num-sources=2
#丢帧的间隔; 2帧输出一次,0表示没有丢帧。
drop-frame-interval=2
#使用的gpu-id gpu-id=0
#(0): memtype_device - Memory type Device
#(1): memtype_pinned - Memory type Host Pinned
#(2): memtype_unified - Memory type Unified cudadec-memtype=0
————————————————————————————————
[sink0]
#是否开启
enable=1
#1:Fakesink 2:基于EGL的窗口接收器(nveglglessink) 3:编码+文件保存(编码器+混合器+ filesink)4:编码+ RTSP流 5:叠加层(仅适用于Jetson) 6:消息转换器+消息代理;
#Type - 1=FakeSink 2=EglSink 3=File ;
type=2
#渲染流速度。0:尽可能快 1:同步 ;
sync=1
source-id=0
gpu-id=0
#0:平台默认类型 1:pinned/主机CUDA内存 2:device CUDA memory 3: unified CUDA memory 4:nvbuf-memory-type=0

#OSD主要控制页面上的文本和框体,这里不是很理解未来再补
[osd]
#是否开启
enable=1
gpu-id=0
border-width=1
text-size=15
text-color=1;1;1;1;
text-bg-color=0.3;0.3;0.3;1
font=Serif
show-clock=0
clock-x-offset=800
clock-y-offset=820
clock-text-size=12
clock-color=1;0;0;0
nvbuf-memory-type=0

#跟踪
[tracker]

#视频流组件
[streammux]

四.性能记录

模型batchsize精度输入尺寸路数FPS(avg)
yolov5n 6.04fp3264045.6
yolov3-tiny1fp32416414.9
yolov3-tiny4fp32416417.2
yolov3-tiny4fp16416419.0
  • 避免误差4路视频为同一个mp4。

五.参考

https://blog.csdn.net/u010414589/article/details/115338399
https://blog.csdn.net/lk007cx/article/details/110228243
https://blog.csdn.net/W1995S/article/details/119858078
https://zhuanlan.zhihu.com/p/296314513
https://github.com/marcoslucianops/DeepStream-Yolo
https://blog.csdn.net/qq122716072/article/details/114156647

  • 6
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 27
    评论
评论 27
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值