公共场所火焰烟雾检测

这一期继续讲解视觉在现实场景中的应用,PP-YOLOv2算法在火焰烟雾识别。

.下载操作模板与数据集(必看)
请提前准备好!
链接:https://aistudio.baidu.com/aistudio/datasetdetail/117915

opencv识别烟雾 opencv烟雾检测识别_paddlepaddle

1.进入BML主页,点击立即使用:https://ai.baidu.com/bml/

opencv识别烟雾 opencv烟雾检测识别_paddlepaddle_02

2.点击左侧“模型训练”下的“Notebook”

opencv识别烟雾 opencv烟雾检测识别_paddlepaddle_03

3.选择物体检测类型,点击立即创建

opencv识别烟雾 opencv烟雾检测识别_paddlepaddle_04

4.配置Notebook,Python3.7,PaddlePaddle2.0.0,GPUV100

opencv识别烟雾 opencv烟雾检测识别_opencv识别烟雾_05

5.启动并打开Notebook

opencv识别烟雾 opencv烟雾检测识别_paddlepaddle_06

第二步:导入“火灾烟雾检测操作模板“

1.点击图中按钮进行上传

opencv识别烟雾 opencv烟雾检测识别_百度_07

2.打开模板,接下来的操作将在此模板中进行

opencv识别烟雾 opencv烟雾检测识别_数据集_08

第三步:安装环境

安装paddlepaddle-gpu

!python -m pip install paddlepaddle-gpu==2.1.3.post101 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html

opencv识别烟雾 opencv烟雾检测识别_数据集_09

第四步:安装PaddleDetection

1.下载并安装PaddleDetection

!git clone https://gitee.com/PaddlePaddle/PaddleDetection.git -b develop

opencv识别烟雾 opencv烟雾检测识别_paddlepaddle_10

2.安装PaddleDetection相关依赖

! pip install -r PaddleDetection/requirements.txt

(红色报错不影响后续操作)

opencv识别烟雾 opencv烟雾检测识别_数据集_11

第五步:上传数据集并解压

1.上传“fire_smoke“数据集(耐心等待上传)

opencv识别烟雾 opencv烟雾检测识别_百度_12

2.解压数据集至根目录

操作前可执行pwd查看当前路径,若路径没在根目录,可执行

cd /home/work

解压命令

! unzip -oq ./fire_smoke.zip

opencv识别烟雾 opencv烟雾检测识别_百度_13

第二步:配置模型训练的yml文件

opencv识别烟雾 opencv烟雾检测识别_百度_14

PP-YOLOv2:相较20年发布的PP-YOLO,PP-YOLOv2版本在COCO 2017 test-dev上的精度提升了3.6个百分点,由45.9%提升到了49.5%;在640*640的输入尺寸下,FPS达到68.9FPS。主要改进点:
Path Aggregation Network
Mish Activation Function
Larger Input Size
IoU Aware Branch

1.配置ppyolov2_r50vd_dcn_voc.yml文件

路径:/home/work/PaddleDetection/configs/ppyolo/ppyolov2_r50vd_dcn_voc.yml

opencv识别烟雾 opencv烟雾检测识别_opencv识别烟雾_15

参考:若batch_size=12,总epoch=10,则训练时长预估3小时

2.配置voc.yml文件

路径 :/home/work/PaddleDetection/configs/datasets/voc.yml

修改数据集路径

修改txt文件名,与数据集中的txt文件名一致

opencv识别烟雾 opencv烟雾检测识别_opencv识别烟雾_16

第三步:模型训练

1.进入训练路径

cd/home/work/PaddleDetection/tools

opencv识别烟雾 opencv烟雾检测识别_数据集_17

2.启动单卡训练

!export CUDA_VISIBLE_DEVICES=0

opencv识别烟雾 opencv烟雾检测识别_百度_18

3.设置训练yml文件路径

config_path = ‘/home/work/PaddleDetection/configs/ppyolo/ppyolov2_r50vd_dcn_voc.yml’

opencv识别烟雾 opencv烟雾检测识别_算法_19

4.开始训练

!python train.py -c $config_path

opencv识别烟雾 opencv烟雾检测识别_数据集_20

第四步:模型评估
1.设置模型评估的模型路径
weight_path = ‘/home/work/PaddleDetection/tools/output/ppyolov2_r50vd_dcn_voc/model_final.pdparams’

2.进行模型评估

!python eval.py -c opencv识别烟雾 opencv烟雾检测识别_opencv识别烟雾_21weight_path

opencv识别烟雾 opencv烟雾检测识别_opencv识别烟雾_22


opencv识别烟雾 opencv烟雾检测识别_数据集_23

第二步:进入相应路径

cd/home/work/PaddleDetection/tools

opencv识别烟雾 opencv烟雾检测识别_百度_24

第三步:设置预测图片路径

img_path = ‘/home/work/fire_smoke/images/fire_000002.jpg’

thresh = 0.1

opencv识别烟雾 opencv烟雾检测识别_算法_25

第四步:模型预测

!python infer.py -cKaTeX parse error: Undefined control sequence: \ at position 29: …o use_gpu=True \̲ ̲-o weight=weight_path --draw_threshold=KaTeX parse error: Undefined control sequence: \ at position 8: thresh \̲ ̲--infer_img=img_path

opencv识别烟雾 opencv烟雾检测识别_百度_26

opencv识别烟雾 opencv烟雾检测识别_数据集_27

第五步:查看预测结果

路径:home/work/PaddleDetection/tools/output

opencv识别烟雾 opencv烟雾检测识别_算法_28

opencv识别烟雾 opencv烟雾检测识别_算法_29