对于烟火检测,传统的图像处理算法有静态检测和动态检测两种。静态检测对单帧图片进行颜色、形状、纹理方面的检测。动态检测对多帧图像采用高斯混合模型或者光流法进行检测。但这些方法对火焰检测效果好,但对于烟雾检测效果差。原因是烟雾颜色、形状种类很多,运动速度缓慢。所以采用深度学习的方法进行检测。本文是在如下github地址基础上进行的测试。
1、下载代码:
git clone https://github.com/gengyanlei/fire-detect-yolov4.git
环境:
python: 3.8.6
ubuntu16.04 or 18.04
darknet (cuda10.1) **
2、执行命令
python3 detect.py --source ../image/fire.png --weights ./best.pt
pip3 install opencv-python --default-timeout=100
报错信息1:
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
import _tkinter
ImportError: No module named '_tkinter'
通过如下命令解决,注意python版本要对应好。
sudo apt-get install python3.5-tk
报错信息2:
ImportError: No module named 'torch'
通过如下命令安装pytorch解决,注意pip版本要对应好。
pip3 install torch --default-timeout=100
pip3 install tqdm
pip3 install torchvision
pip3 install scipy
还是报错:
AssertionError: CUDA unavailable, invalid device 0 requested
由于torch是1.7.1的,不支持低版本的cuda 10.1 所以检测不到gpu,安装兼容10.1低版本cuda的对应torch版本1.6.0+cu101
pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
终于成功,大功告成!!!
ljgk@vision-dev:~/firesmoke/fire-detect-yolov4/yolov5$ python3 detect.py --source ../image/fire.png --weights ./best.pt
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='0', img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='../image/fire.png', update=False, view_img=False, weights=['./best.pt'])
device: 0
Fusing layers... image 1/1 /home/ljgk/firesmoke/fire-detect-yolov4/image/fire.png: 640x576 2 fires, Done. (0.021s)
Results saved to inference/output
Done. (0.253s)