Fire detection method based on lightweight YOLO v5s
By optimizing the YOLOv5s model, the problems of traditional fire detection methods being difficult to deploy in the field and large resource occupancy are solved, and efficient fire detection on small embedded devices is realized, which reduces the computing resource requirements and improves detection accuracy and speed.
Patent Information
- Application Number
- CN202411255045.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2025-01-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional fire detection methods are difficult to deploy in large-scale outdoor areas, with high error detection and false alarm rates. The traditional YOLOv5s model occupies a large amount of memory and computing resources of embedded devices, and is not suitable for deployment on small embedded devices.
By replacing the convolution layer module with ODConv module and replacing the C3 network layer with ConvNextBlock, reducing the number of network layers, introducing the SE attention module, and using GIOU as the positioning loss function, optimizing the YOLOv5s model to reduce the calculation amount and parameter amount, adapting to small embeddings computing resources for the device.
It realizes efficient and fast fire detection on small embedded devices, maintains high accuracy and speed, reduces the parameter quantity and calculation quantity by 75%, improves the inference speed and improves the accuracy by 7%, and is suitable for fire detection in unmanned areas. .
Smart Images

Figure CN119296026A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision, and in particular to a fire detection method based on lightweight YOLO v5s. Background Art
[0002] Fire is one of the major disasters that cause loss of life and property. In order to effectively control and mitigate fires, it is particularly important to give early warning of the outbreak of fires.
[0003] At present, traditional fire warning mainly relies on detection methods such as smoke sensors. They cannot be deployed on a large scale in large-scale wild areas such as forests, grasslands, mountainous areas, and farmlands, and have high false detection and false alarm rates. Therefore, for large uninhabited areas such as forests, due to the lack of real-time monitoring and effective response mechanisms, forest fires are usually difficult to detect in the early stages of the fire. Such delays not only increase the risk of fire spread, but also increase the difficulty of extinguishing the fire, and cause greater property losses and environmental pollution. Such areas are usually large in size and lack infrastructure, so traditional fire detection methods are difficult to implement in these environments.
[0004] With the continuous development of computer vision technology in recent years, it has become possible to detect fires using camera equipment and image processing detection technology. This technology analyzes the images captured by the camera to determine whether there is smoke or flame. Once an abnormality is found, the system will immediately issue an alarm.
[0005] YOLOv5s is a target detection model and a variant of the YOLO v5 series. It has a fast detection speed while maintaining high detection accuracy. It can be used to handle fire detection in a variety of environments and scenarios. It is not limited by the physical characteristics of the sensor, and can record video data and detection results, handle complex backgrounds and multiple fire sources, and facilitate subsequent analysis. However, traditional YOLOv5s often requires a large amount of memory and computing resources on embedded devices, which is not conducive to deployment on embedded devices, especially small embedded devices. Summary of the invention
[0006] In order to overcome the shortcomings of the prior art, the present invention proposes a fire detection method based on lightweight YOLO v5s, which has a smaller model volume and a faster processing speed. It can efficiently and quickly perform target detection at different scales, especially in the case of limited computing resources of small embedded devices, and can still maintain high accuracy and speed.
[0007] In order to achieve the above object, the technical solution specifically adopted by the present invention is as follows:
[0008] A fire detection method based on lightweight YOLO v5s, comprising the following steps:
[0009] S1. Collect fire pictures in different scenes, time periods and sizes, and establish training sets, test sets and validation sets;
[0010] S2, select the YOLO v5s network model as the basic network model;
[0011] S3. Improved YOLO v5s network model:
[0012] Use ODConv module to replace the convolutional layer module in the backbone network;
[0013] Use the ConvNextBlock module to replace the C3 network module and reduce the number of C3 network layers in the network model;
[0014] The SE attention module is introduced into the small and medium-sized detection images of the Neck part of the network to improve the network's ability to extract small and medium-sized features;
[0015] S4. Train and optimize the improved YOLO v5s network model, and use the trained YOLO v5s network model to detect fire scenes.
[0016] Furthermore, in step S1, the collected fire pictures need to be annotated to generate a txt annotation file. Optionally, the collected pictures can be subjected to data enhancement processing, such as horizontal flipping, vertical flipping, and adding Gaussian noise and salt and pepper noise processing to enhance the robustness of the model.
[0017] Furthermore, in step S3, the ODConv module is used to replace the Conv module to enhance the feature learning capability of the backbone network.
[0018] Furthermore, in the step S3, the ConvNextBlock module is used to replace a layer of C3 network modules in the backbone network, a larger convolution kernel is used to expand the receptive field, and layer normalization is introduced to replace batch normalization to provide more stable training. Through point-by-point convolution, information fusion between channels is performed, so that ConvNeXt can significantly improve the model performance while maintaining high computational efficiency.
[0019] Furthermore, in step S3, two layers of SE attention mechanisms are added to the Neck input to the Head part of the network to improve the feature extraction capability of YOLO v5s for small and medium-sized targets.
[0020] Furthermore, in step S4, GIOU is used as the positioning loss function, and GIOU can better handle the gap between the predicted box and the real box, thereby improving the performance of the model in the fire detection task.
[0021] Furthermore, the step S4 comprises the following steps:
[0022] S41, use the YOLO v5 official open source pre-trained weight YOLO v5s as the initial weight of the model;
[0023] S42, using the labeled data set in the improved YOLO v5s model data set to perform multiple rounds of training on the improved YOLO v5s network;
[0024] S43, after adjustment and multiple training, the fire detection model based on YOLO v5s and its weight file are obtained;
[0025] S44. Select the optimal weight file after network training, use the YOLO v5s model to predict the fire scene images in the test set, and perform comparative analysis of the test results.
[0026] The present invention has the following characteristics and beneficial effects:
[0027] Aiming at the problems of insufficient embedded computing power and small memory, this paper proposes a lightweight YOLO v5 fire detection method. By replacing the ordinary convolution and C3 network layers, adding the attention mechanism, and selecting the appropriate loss function, the network model can maintain the performance while greatly reducing the amount of network calculation and parameter quantity, thereby meeting the computing power requirements of edge devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0029] Figure 1 The figure is an overall implementation flow chart of a fire detection method based on lightweight YOLO v5s according to an embodiment of the present invention.
[0030] Figure 2 This is the ODConv network structure diagram.
[0031] Figure 3 This is the network structure diagram of ConvNext Block.
[0032] Figure 4 This is the improved YOLO v5s network structure diagram.
[0033] Figure 5The effect diagram of the improved network model on detecting fire dataset. DETAILED DESCRIPTION
[0034] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other.
[0035] like Figure 1 As shown, a lightweight fire detection method of YOLO v5s specifically includes the following steps.
[0036] S1. Establish fire detection data set:
[0037] S11. Collect fire pictures in various scenarios, such as different scenes, different time periods, and different sizes, use annotation tools to label the pictures, and generate txt annotation files; for small data sets, you can use data enhancement methods such as horizontal flipping, vertical flipping, and Gaussian noise, salt and pepper noise processing, etc. to process pictures for data enhancement to improve the generalization ability of the model.
[0038] S12. Randomly divide the data set into training set, test set and validation set.
[0039] S2. Based on the criteria that the model has a smaller model, lower computing requirements, and higher detection accuracy, YOLO v5s is selected as the basic model.
[0040] S3, improve the YOLO v5s model, mainly including the following three steps:
[0041] S31, such as Figure 4 As shown in the figure, ODConv is used in the YOLO v5s network model to replace the Conv module in the original network.
[0042] ODCOnv introduces a multi-dimensional attention mechanism through a parallel strategy to learn more flexible attention to the four dimensions of the convolution kernel space. ODConv introduces a multi-dimensional attention mechanism in space, channel, depth and convolution kernel dimensions to improve the flexibility and accuracy of feature extraction. The network structure of ODConv is as follows: Figure 2 shown.
[0043] ODConv can be described as follows:
[0044] y=(a w1 ⊙a f1 ⊙a c1 ⊙a s1 ⊙w1+....+a wn ⊙afn ⊙a cn ⊙a sn ⊙w n )*x
[0045] Among them, a wi Represents the convolution kernel W i The attention scalar, a si ∈R k*k ,a ci ∈R cin ,a fi ∈R Cout Represents the three newly introduced attention mechanisms, along the spatial dimension, input channel dimension, and output channel dimension.
[0046] S32: Figure 4 As shown in the figure, a C3 network layer in the backbone network of the YOLO v5s network model is replaced with ConvNext. The ConvNext network is mainly constructed by stacking ConvNext Blocks. The structure of ConvNext Block is as follows Figure 3 As shown. It is mainly composed of depthwise convolution, two-dimensional convolution layer (Conv2d), normalization layer (Layer Normalization), and GELU activation function. The present invention uses a larger convolution kernel to expand the receptive field, introduces layer normalization (Layer Normalization) instead of batch normalization (Batch Normalization) to provide more stable training, and performs inter-channel information fusion through point-by-point convolution, so that ConvNeXt can significantly improve the model performance while maintaining high computational efficiency. The GELU activation function can not only maintain the advantages of the RELU function, but also better simulate the activation function of natural distribution characteristics.
[0047] Mathematical expression of GELU activation function:
[0048] GELU(x)=xφ(x)
[0049] Where: φ(x) is the cumulative distribution function of the standard normal distribution, and x represents the input value.
[0050] S33: Reduce the number of network layers of C3 in the YOLO v5s network model.
[0051] Table 1
[0052]
[0053] The C3 module can effectively fuse multi-level information by performing convolution operations on the input features. The number of network layers of C3 will increase the number of network parameters and the amount of computation. As shown in Table 1, the number of network layers of the YOLO v5s network model before the improvement is 213, and the number of network layers of the improved YOLO v5s is 205. Compared with before the improvement, the operation of S33 can greatly reduce the convolution operations, and greatly reduce the number of parameters and the amount of computation.
[0054] S34: Figure 4 As shown in the figure, the SE attention mechanism is added to the Neck network part after the small and medium feature detection graphs of the YOLO v5s network model. Adding the SE attention module to the small and medium feature graphs can play a more effective role and effectively enhance the network's feature extraction ability for small and medium targets, thereby improving the accuracy of the model.
[0055] The main operations of the SE module are compression and excitation.
[0056] In the Squeeze step, the feature map is globally averaged pooled to generate a 1*1*C vector, so that each channel is represented by a numerical value.
[0057]
[0058] Where: Uc(i,j) is the value of the input feature map at position (i, j) of channel c, and H and W are the spatial height and width of the feature map.
[0059] Excitation transforms the channel statistics into per-channel weight coefficients through a small fully connected network (usually consisting of two fully connected layers).
[0060] s=F ex (z,W)=σ(g(z,W))=σ(W2δ(W1z))
[0061] Where: W1, W2 are the weight matrices of the two fully connected layers, W is the weight parameter, vector z is the compressed output result, and σ is the Sigmoid activation function.
[0062] For the network structure model structure configuration file, YOLO officially provides 5 network structure configuration files, including yolov5n.yaml, yolov5s.yaml, yolov5m.yaml, yolov5l.yaml, and yolov5l.yamx, in the code. Select the structure configuration file yolo v5s.yaml file corresponding to the network model as the network structure configuration file, modify the corresponding network structure, and use the network structure configuration file for training.
[0063] S4. Use GIOU as the positioning loss function to train the improved YOLO v5s network model, obtain the trained weight file, and select the optimal weight file to verify the images in the verification set.
[0064] Use GIOU to replace the original loss function CIOU. The calculation formula of GIOU is:
[0065]
[0066] Where: IOU: calculates the overlap between the predicted box and the true box. A: predicted frame. B: true frame. C: is the minimum bounding frame of the predicted frame and the true frame. |C|: is the area of the minimum bounding frame. |C-(A∪B)| is the area of the minimum bounding frame that does not contain the predicted box and the true box.
[0067] The training process includes the following steps:
[0068] S41, use the YOLO v5 official open source pre-trained weight YOLO v5s as the initial weight of the model;
[0069] S42, using the labeled data set in the improved YOLO v5s model data set to perform multiple rounds of training on the improved YOLO v5s network;
[0070] S43, after adjustment and multiple training, the fire detection model based on YOLO v5s and its weight file are obtained;
[0071] S44. Select the optimal weight file after network training, use the YOLO v5s model to predict the fire scene images in the test set, and perform comparative analysis of the test results.
[0072] It should be noted that the selection of the most weighted files is based on specific application requirements and data set characteristics, and is obtained through a limited number of trainings.
[0073] result:
[0074] The reasoning speed of the present invention is 0.2ms in preprocessing time, 3.5ms in reasoning time, and 1.5ms in NMS stage time when the batch size is 16 and the input image size is 640x640 pixels, which is 1.2ms higher than the baseline model inference time per picture. The optimized model reduces the number of parameters and calculations by 75% compared to the official yolo v5s benchmark model, improves the accuracy by 7%, and the mAP value of the model when the IoU threshold is 0.5 is 1% higher than the baseline model. This improvement enables the model to reduce the demand for computing resources while maintaining high performance, thereby improving the detection efficiency of the model deployed on a hardware platform with limited computing resources in the field. This is extremely important for early detection of fire detection in unmanned areas, which can significantly reduce fire losses, quickly control the scope of fire, and protect the ecological environment and people's property safety.
[0075] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments. The above embodiments and descriptions are only preferred examples of the present invention and are not intended to limit the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention. The scope of protection of the present invention is defined by the attached claims and their equivalents.
Claims
1. A fire detection method based on lightweight YOLO v5s, characterized by: The steps include: S1. Collect fire pictures in different scenes, time periods and sizes, and establish training sets, test sets and validation sets; S2, select the YOLO v5s network model as the basic network model; S3. Improved YOLO v5s network model: Use ODConv module to replace the convolutional layer module in the backbone network; Use the ConvNextBlock module to replace the C3 network module and reduce the number of C3 network layers in the network model; The SE attention module is introduced into the small and medium-sized detection images of the Neck part of the network to improve the network's ability to extract small and medium-sized features; S4. Train and optimize the improved YOLO v5s network model, and use the trained YOLO v5s network model to detect fire scenes.
2. A fire detection method based on lightweight YOLO v5s as claimed in claim 1, characterized in that: In the step S1, the collected fire pictures need to be annotated to generate a txt annotation file.
3. A fire detection method based on lightweight YOLO v5s as claimed in claim 1, characterized in that: In step S3, the Conv module is replaced by the ODConv module.
4. A fire detection method based on lightweight YOLO v5s as claimed in claim 1, characterized in that: In the step S3, a C3 network module in the backbone network is replaced by a ConvNextBlock module, and layer normalization is introduced to replace batch normalization, and inter-channel information is fused through point-by-point convolution.
5. A fire detection method based on lightweight YOLO v5s as claimed in claim 1, characterized in that: In the step S3, two layers of SE attention mechanism are added to the Neck input to the Head part of the network.
6. A fire detection method based on lightweight YOLO v5s as claimed in claim 1, characterized in that: In the step S4, GIOU is used as the positioning loss function.
7. A fire detection method based on lightweight YOLO v5s as claimed in claim 1, characterized in that: The step S4 comprises the following steps: S41, use the YOLO v5 official open source pre-trained weight YOLO v5s as the initial weight of the model; S42, using the labeled data set in the improved YOLO v5s model data set to perform multiple rounds of training on the improved YOLO v5s network; S43, after adjustment and multiple training, the fire detection model based on YOLO v5s and its weight file are obtained; S44. Select the optimal weight file after network training, use the YOLO v5s model to predict the fire scene images in the test set, and perform comparative analysis of the test results.
Citation Information
Patent Citations
Lightweight fire detection method based on weighted bidirectional feature pyramid network
CN115063665A
Improved PCB defect detection method based on YOLO v5 algorithm
CN117274197A
Forest fire detection method based on improved YOLOv5 network
CN118537757A