dnn+yolo+flask推理(树莓派实时推流—内含YOLO全家桶系列)

YOLO-Streaming

这个资源库记录了在一些超轻量级网络上推送视频流的过程。一般的步骤是,opencv调用板子(比如树莓派)的摄像头,将检测到的实时视频传输到yolo-fastest、nanodet、ghostnet等超轻量级网络上,然后讲使用flask轻量级框架将处理后的视频帧推送到网络上,基本上可以保证实时性能。并且,这个仓库也记录一些侧端推理框架的性能,感兴趣的网友可以交流。

在这里插入图片描述
仓库链接:https://github.com/pengtougu/DNN-Lightweight-Streaming

欢迎Star和PR!
欢迎加qq群交流:696654483

Requirements

请先安装依赖(for dnn→调用dnn的环境)

  • Linux & MacOS & window
  • python>= 3.6.0
  • opencv-python>= 4.2.X
  • flask>= 1.0.0

请先安装依赖(for ncnn→调用ncnn的环境)

  • Linux & MacOS & window
  • Visual Studio 2019
  • cmake-3.16.5
  • protobuf-3.4.0
  • opencv-3.4.0
  • vulkan-1.14.8

inference

EquipmentComputing backendSystemFrameworkinput_sizeRun time
Raspberrypi 3B4xCortex-A53Linux(arm64)dnn32089ms
IntelCore i5-4210window10(x64)dnn32021ms
EquipmentComputing backendSystemFrameworkinput_sizeRun time
Raspberrypi 3B4xCortex-A53Linux(arm64)dnn320315ms
IntelCore i5-4210window10(x64)dnn32041ms
EquipmentComputing backendSystemFrameworkinput_sizeRun time
Raspberrypi 3B4xCortex-A53Linux(arm64)dnn320673ms
IntelCore i5-4210window10(x64)dnn320131ms
Raspberrypi 3B4xCortex-A53Linux(arm64)ncnn160716ms
IntelCore i5-4210window10(x64)ncnn160197ms
EquipmentComputing backendSystemFrameworkinput_sizeRun time
Raspberrypi 3B4xCortex-A53Linux(arm64)dnn320113ms
IntelCore i5-4210window10(x64)dnn32023ms

updating. . .

Demo

首先,我已经在window、Mac和Linux环境下测试了这个演示,它在以上三种平台上都能工作,且不需要修改代码,即下即用。

下载后一共包含以下文件(红线为主运行文件):
在这里插入图片描述

Run v3_fastest.py

  • Inference images use python yolov3_fastest.py --image dog.jpg
  • Inference video use python yolov3_fastest.py --video test.mp4
  • Inference webcam use python yolov3_fastest.py --fourcc 0

Run v4_tiny.py

  • Inference images use python v4_tiny.py --image person.jpg
  • Inference video use python v4_tiny.py --video test.mp4
  • Inference webcam use python v4_tiny.py --fourcc 0

Run v5_dnn.py

  • Inference images use python v5_dnn.py --image person.jpg
  • Inference video use python v5_dnn.py --video test.mp4
  • Inference webcam use python v5_dnn.py --fourcc 0

Run NanoDet.py

  • Inference images use python NanoDet.py --image person.jpg
  • Inference video use python NanoDet.py --video test.mp4
  • Inference webcam use python NanoDet.py --fourcc 0

Run app.py -(Push-Streaming online)

  • Inference with v3-fastest python app.py --model v3_fastest
  • Inference with v4-tiny python app.py --model v4_tiny
  • Inference with v5-dnn python app.py --model v5_dnn
  • Inference with NanoDet python app.py --model NanoDet

Please note! Be sure to be on the same LAN!

Demo Effects

Run v3_fastest.py

  • image→video→capture→push stream
    在这里插入图片描述

Run v4_tiny.py

  • image→video→capture→push stream
    任需优化,后续补充量化版本,待更新…

Run v5_dnn.py

在这里插入图片描述

  • image(473 ms / Inference Image / Core i5-4210)→video→capture(213 ms / Inference Image / Core i5-4210)→push stream

2021-04-26 记:有趣的是,用onnx+dnn的方式调用v5s的模型,推理图片要比摄像头处理帧多花一倍的时间,看了很久,还是找不出问题所在,希望看到的大佬可以帮看看代码,点破问题所在,感谢!

2021-05-01 更:今天找到了问题所在,因为v5_dnn.py文件中有个推理时间画在帧图上的功能(cv2.putText(frame, "TIME: " + str(localtime), (8, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)),而这个功能居然花费了每帧推理后处理时间的2/3(大约一帧是50-80ms),后续的版本全部去掉,改成终端显示,每帧推理时间由190ms→130ms,也是恐怖额。

Supplement

This is a DNN repository that integrates the current detection algorithms. You may ask why call the model with DNN, not just git clone the whole framework down? In fact, when we are working with models, it is more advisable to separate training and inference. More, when you deploy models on a customer’s production line, if you package up the training code and the training-dependent environment for each set of models (yet the customer’s platform only needs you to infer, no training required for you), you will be dead after a few sets of models. As an example, here is the docker for the same version of yolov5 (complete code and dependencies & inference code and dependencies). The entire docker has enough memory to support about four sets of inference dockers.

这是一个整合了当前检测算法的DNN资源库。你可能会问,为什么用DNN调用模型,而不是直接用git克隆整个框架下来?事实上,当我们在处理模型的时候,把训练和推理分开是比较明智的。更多的是,当你在客户的生产线上部署模型的时候,如果你把每套模型的训练代码和依赖训练的环境打包起来(然而客户的平台只需要你推理,不需要你训练),那么你在几套模型之后就凉了呀。作为一个例子,这里是同一版本的yolov5的docker(完整的代码和依赖性→6.06G &推理代码和依赖性→0.4G)。整个docker有足够的内存来支持大约15套推理docker。

在这里插入图片描述
在这里插入图片描述

Thanks

other

欢迎加入深度学习交流群:696654483
里面有很多的研究生大佬和各行各业的大咖~

  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值