編輯:OAK中國
來源:oakchina.cn
版權說明:轉載請注明出處
前言
Hello,大家好,這裡是OAK中國,我是助手君。
本期内容将介紹如何在 DepthAI 上實作火焰檢測,超級簡單,快來試試吧🔥🔥🔥。
你可以在示範中使用以下一組預先訓練的模型:
● fire_detection 檢測火焰和煙霧
其他示範目标包括:
● 視訊 / 攝像頭作為輸入(通過 OpenCV )
● 使用火焰和煙霧檢測功能來監控視訊中的火災
1.項目分析
項目位址:
StephanXu / FireDetector
主要代碼:
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://gitee.com/oakchina/depthai-experiments/tree/master/gen2-fire-detection
https://docs.oakchina.cn/en/latest/
https://www.oakchina.cn/selection-guide/
OAK中國
| OpenCV AI Kit在中國區的官方代理商和技術服務商
| 追蹤AI技術和産品新動态
戳「+關注」擷取最新資訊↗↗