# Fire detection **Repository Path**: c259567268/Fire-detection ## Basic Information - **Project Name**: Fire detection - **Description**: 火灾检测系统:基于yolov5进行目标检测 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 0 - **Created**: 2024-05-15 - **Last Updated**: 2025-07-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Fire detection ## 配置环境 创建python3.8的虚拟环境 ```bash conda create -n yolo5 python==3.8.5 conda activate yolo5 ``` ### pytorch安装(gpu版本和cpu版本的安装) ```cmd conda install pytorch==1.8.0 torchvision torchaudio cudatoolkit=10.2 # 注意这条命令指定Pytorch的版本和cuda的版本 conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cpuonly # CPU的小伙伴直接执行这条命令即可 ``` ### pycocotools的安装 ``` pip install pycocotools-windows ``` ### 其他包的安装 ```bash pip install -r requirements.txt pip install pyqt5 pip install labelme ``` ## 数据处理 yolo格式的数据是一张图片对应一个txt格式的标注文件 标注文件中记载了目标的类别 中心点坐标 和宽高信息 ## 配置文件准备 * 数据配置文件的准备 配置文件是data目录下的`fire_data.yaml` * 模型配置文件的准备 模型的配置文件分别是`mask_yolov5s.yaml`、`mask_yolov5m.yaml`、`mask_yolov5l.yaml`,分别对应着yolo大中小三个模型 ## 模型训练 模型训练的主文件是`triain.py`,三条指令分别对应着小中大三个模型的训练 ```bash python train.py --data fire_data.yaml --cfg mask_yolov5s.yaml --weights pretrained/yolov5s.pt --epoch 100 --batch-size 2 --device cpu python train.py --data fire_data.yaml --cfg mask_yolov5l.yaml --weights pretrained/yolov5l.pt --epoch 100 --batch-size 2 python train.py --data fire_data.yaml --cfg mask_yolov5m.yaml --weights pretrained/yolov5m.pt --epoch 100 --batch-size 2 ``` 训练结果保存在`runs/train`目录下 ## 模型使用 模型的使用全部集成在了`detect.py`目录 ```bash # 检测摄像头 python detect.py --weights runs/train/exp_yolov5s/weights/best.pt --source 0 # webcam # 检测图片文件 python detect.py --weights runs/train/exp_yolov5s/weights/best.pt --source file.jpg # image # 检测视频文件 python detect.py --weights runs/train/exp_yolov5s/weights/best.pt --source file.mp4 # video # 检测一个目录下的文件 python detect.py --weights runs/train/exp_yolov5s/weights/best.pt path/ # directory # 检测网络视频 python detect.py --weights runs/train/exp_yolov5s/weights/best.pt 'https://youtu.be/NUsoVlDFqZg' # YouTube video # 检测流媒体 python detect.py --weights runs/train/exp_yolov5s/weights/best.pt 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream ``` 执行`python detect.py --weights runs/train/exp_yolov5s/weights/best.pt --source images/1_67.jpg`的命令便可以得到一张检测结果。