從 0 到 1 學(xué)習(xí)使用 DepthAI-煙火檢測

這篇文章將介紹如何在 DepthAI 上實現(xiàn)火焰檢測
你可以在演示中使用以下一組預(yù)先訓(xùn)練的模型:
● fire_detection 檢測火焰和煙霧
其他演示目標(biāo)包括:
● 視頻 / 攝像頭作為輸入(通過 OpenCV )
● 使用火焰和煙霧檢測功能來監(jiān)控視頻中的火災(zāi)
1.項目分析
?項目地址:
StephanXu:https://github.com/StephanXu/FireDetector/tree/python
?FireDetector:https://github.com/StephanXu/FireDetector/tree/python
?主要代碼:
1)模型標(biāo)簽
#?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 查看模型文件
開頭 可以看到 輸入層的形狀和名稱

結(jié)尾 可以看到輸出層的名字

4.模型轉(zhuǎn)換為 IR 文件
openvino支持直接轉(zhuǎn)換 tensorflow 的模型:
https://docs.openvinotoolkit.org/cn/latest/openvino_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_TensorFlow.html
轉(zhuǎn)換TensorFlow *模型:
? ?轉(zhuǎn)到<OPENVINO_INSTALL_DIR>/deployment_tools/model_optimizer目錄
? ?使用mo_tf.py腳本可以簡單地將具有權(quán)重的.pb模型轉(zhuǎn)換為.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.查看轉(zhuǎn)換的 IR 文件
使用 Netron 查看 xml 文件
與之前比對

這時可以看到 輸出的形狀

6.IR 轉(zhuǎn)換為 blob文件
將IR文件轉(zhuǎn)換為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
國內(nèi)在哪里能買到DepthAI?
目前國內(nèi)唯一的購買渠道是派馳的淘寶店:
??OAK-D -派馳電子 淘寶:https://sourl.cn/9YEFE5
??OAK-1 -派馳電子 淘寶:https://sourl.cn/4CpZUZ
參考鏈接:
OAK 中國:https://sourl.cn/6wt8sm
OAK 中文文檔:https://sourl.cn/rawPZD