欢迎光临散文网 会员登陆 & 注册

从 0 到 1 学习使用 DepthAI-烟火检测

2021-01-29 16:23 作者:OAK中国  | 我要投稿

这篇文章将介绍如何在 DepthAI 上实现火焰检测

你可以在演示中使用以下一组预先训练的模型:
● fire_detection 检测火焰和烟雾

其他演示目标包括:
● 视频 / 摄像头作为输入(通过 OpenCV )
● 使用火焰和烟雾检测功能来监控视频中的火灾

1.项目分析

⬛项目地址:
StephanXu:https://github.com/StephanXu/FireDetector/tree/python

 FireDetector:https://github.com/StephanXu/FireDetector/tree/python

⬛主要代码:
1)模型标签

# https://github.com/StephanXu/FireDetector/blob/python/main.py 

# line 10 

labels = ['fire', 'normal', 'smoke'] 

2)模型输入形状

# https://github.com/StephanXu/FireDetector/blob/python/main.py 

# line 15-16 

model_input_width = 224 

model_input_height = 224

3)输入输出层

# # https://github.com/StephanXu/FireDetector/blob/python/main.py # line 41-42 

input_layer='Placeholder', 

output_layer='final_result'

4)均值与缩放值

# https://github.com/StephanXu/FireDetector/blob/python/classifier.py # line 11-12 

_input_mean = 0 

_input_std = 255 # https://github.com/StephanXu/FireDetector/blob/python/classifier.py # line 58 

np_data = np.divide(np_data.astype('float'), self._input_std)

2.模型获取

原始模型从 FireDetector 获取, 其原始框架是 tensorflow
FireDetector: https://github.com/StephanXu/FireDetector/tree/python/example

3.模型查看

使用 Netron 查看模型文件
开头 可以看到 输入层的形状和名称

结尾 可以看到输出层的名字

4.模型转换为 IR 文件

openvino支持直接转换 tensorflow 的模型:
https://docs.openvinotoolkit.org/cn/latest/openvino_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_TensorFlow.html

转换TensorFlow *模型:

◼  转到<OPENVINO_INSTALL_DIR>/deployment_tools/model_optimizer目录

◼  使用mo_tf.py脚本可以简单地将具有权重的.pb模型转换为.xml和.bin 文件:

mo.py  --input_model output_graph_mobilenet_v2_100_224.pb \  

  --model_name fire-detection \  

  --input Placeholder \  

  --output final_result \  

  --input_shape [1,224,224,3] \  

  --data_type FP16 \  

  --scale 255

5.查看转换的 IR 文件

使用 Netron 查看 xml 文件
与之前比对


这时可以看到 输出的形状

6.IR 转换为 blob文件

将IR文件转换为blob文件:

$MYRIAD_COMPILE -m fire-detection.xml \  

 -ip U8 \  

 -VPU_MYRIAD_PLATFORM VPU_MYRIAD_2480 \  

 -VPU_NUMBER_OF_SHAVES 4 \  

 -VPU_NUMBER_OF_CMX_SLICES 4

7.编写解析代码

烟火检测演示:https://github.com/OAKChina/depthai-examples/tree/master/fire_detection

国内在哪里能买到DepthAI?

目前国内唯一的购买渠道是派驰的淘宝店:
🔴OAK-D -派驰电子 淘宝:https://sourl.cn/9YEFE5
🔴OAK-1 -派驰电子 淘宝:https://sourl.cn/4CpZUZ

参考链接:
OAK 中国:https://sourl.cn/6wt8sm
OAK 中文文档:https://sourl.cn/rawPZD


从 0 到 1 学习使用 DepthAI-烟火检测的评论 (共 条)

分享到微博请遵守国家法律