Real-time flame and smoke detection method based on YOLOv8
By adding ECA and CBAM attention mechanisms to the YOLOv8 model, using Wise-IoU loss function and data enhancement technology, the problem of insufficient accuracy of fire detection algorithm in small flames and dark environments is solved, and the accuracy and generalization of detection are improved. , capable of efficient and low false detection of flame and smoke detection.
Patent Information
- Application Number
- CN202411305330.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-01-07
AI Technical Summary
The existing fire detection algorithms lack the accuracy in detecting small flames and dark environments, and the generalization capability on embedded devices is insufficient, resulting in an increased risk of misjudgment and misjudgment, making it difficult to achieve lightweight and high-precision models.
Added ECA attention mechanism to the Backbone part of the YOLOv8 model, add CBAM attention mechanism to the Head, and use Wise-IoU loss function and accounting data enhancement to enhance the deep feature extraction and generalization capabilities of the model.
It improves the accuracy and speed of flame and smoke detection, reduces the risk of misidentification, enhances the robustness of the model, is suitable for different environments and equipment, and achieves high accuracy and low false detection rate fire detection.
Smart Images

Figure CN119274131A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of fire detection in computer vision in artificial intelligence, and in particular to a real-time flame and smoke detection method based on YOLOv8. Background Art
[0002] Traditional fire detection technology mainly relies on sensors to monitor the environment and determine whether a fire has occurred by detecting changes in characteristics when a fire occurs. These technologies generally include four types: light sensing, temperature sensing, smoke detection, and gas recognition. With the rise of artificial intelligence technology, fire detection technologies based on computer vision continue to emerge, which identify flames and smoke by analyzing image or video data.
[0003] However, existing fire detection algorithms face several challenges. Large models can provide high detection accuracy but tend to run slowly, while small models run quickly but may not be accurate enough. In addition, these algorithms often perform poorly when detecting small flames or in dark environments. Moreover, many algorithms are too complex when processing datasets, which in turn affects the final detection effect. On embedded devices, the generalization ability of the models is often insufficient.
[0004] In order to build an ideal fire detection model that is lightweight, highly accurate, and fast, it is necessary to improve the existing mainstream algorithms. Features such as flames and smoke that have no fixed form and are easily disturbed by the environment require the model to be able to extract deep information from the image, which inevitably increases the number of model parameters and is a challenge for embedded devices. If the model size is sacrificed for lightweight, the detection accuracy may decrease and the risk of misjudgment and missed judgment may increase. Summary of the invention
[0005] The present invention aims to at least solve the technical problems existing in the prior art, and in particular innovatively proposes a real-time flame and smoke detection method based on YOLOv8.
[0006] In order to achieve the above-mentioned object of the present invention, the present invention provides a real-time flame and smoke detection method based on YOLOv8, comprising the following steps:
[0007] S1, data acquisition: real-time acquisition of flame and smoke images;
[0008] S2, build the flame and smoke detection model: add the ECA attention mechanism to the Backbone part of the YOLOv8 model and the CBAM attention mechanism to the Head;
[0009] S3, obtaining flame and smoke detection results: inputting the pre-processed flame and / or smoke image to be detected into the flame and smoke detection model to obtain the detection result; the detection result includes the smoke value and the flame value.
[0010] Since a series of unpredictable situations such as human factors and weather may occur in a real video environment, the algorithm model itself needs to have good generalization. The present invention embeds the ECA and CBAM modules into the algorithm to enhance the attention mechanism, so that both small flames and large flames can be accurately and quickly identified during real-time detection. As far as fire detection is concerned, for features such as flames and smoke that have no fixed form and whose targets change greatly according to environmental changes and have too many environmental interference factors, it is necessary to extract deep information from the image, which inevitably increases the model parameters and is very unfriendly for embedded systems. However, if a smaller model is used for lightweighting, the consequence is that the image detection accuracy is not enough, and misjudgments and missed judgments are frequent. This is undesirable for fire detection. The reason for choosing ECA and CBAM modules for embedding is to reduce model parameters, effectively improve deep feature extraction, and increase model accuracy. It is the best choice for features such as flames and smoke.
[0011] Furthermore, the YOLOv8-based method adds an ECA attention mechanism to its Backbone part and a CBAM attention mechanism to its Head, including:
[0012] The output end of the first convolution module is connected to the input end of the second convolution module, the output end of the second convolution module is connected to the input end of the first C2f module, the output end of the first C2f module is connected to the input end of the third convolution module, the output end of the third convolution module is respectively connected to the input end of the second C2f module and the input end of the first concat module, the output end of the second C2f module is connected to the input end of the fourth convolution module, the output end of the fourth convolution module is connected to the input end of the third C2f module, the output end of the third C2f module is connected to the input end of the fifth convolution module and the input end of the second concat module, the output end of the fifth convolution module is connected to the input end of the fourth C2f module, the output end of the fourth C2f module is connected to the input end of the SPPF module, and the output end of the SPPF module is connected to the input end of the ECA module;
[0013] The output end of the ECA module is connected to the input end of the first upsampling module and the input end of the fourth concat module respectively; the output end of the first upsampling module is connected to the input end of the second concat module; the output end of the second concat module is connected to the input end of the fifth C2f module, the output end of the fifth C2f module is connected to the input end of the first CBAM module and the input end of the third concat module respectively, the output end of the first CBAM module is connected to the input end of the second upsampling module, the output end of the second upsampling module is connected to the input end of the first concat module, the output end of the first concat module is connected to the input end of the sixth C2f module, and the output end of the sixth C2f module is connected to the input end of the second CBAM module. The output end of the second CBAM module is connected to the input end of the third upsampling module; the output end of the third upsampling module is connected to the input end of the third concat module, and the output end of the third concat module is connected to the input end of the seventh C2f module; the output end of the seventh C2f module is connected to the input end of the third CBAM module, the output end of the third CBAM module is connected to the input end of the fourth upsampling module, the output end of the fourth upsampling module is connected to the input end of the fourth concat module, the output end of the fourth concat module is connected to the input end of the eighth C2f module, the output end of the eighth C2f module is connected to the input end of the fourth CBAM module, and the output end of the fourth CBAM module is connected to the input end of the second CBAM module;
[0014] Among them, the first concat module, the second concat module, the third concat module, and the fourth concat module are used to concatenate data of two modules.
[0015] In order to solve the problem of low accuracy in small flame recognition in the application model, the ECA attention mechanism is added to the Backbone module. The idea is that the weight learning process should correspond directly one to one. The ECA attention mechanism module directly uses a 1×1 convolution layer after the global average pooling layer and removes the fully connected layer. This module avoids dimensionality reduction and effectively captures cross-channel interactions. In addition, ECA only involves a few parameters to achieve good results.
[0016] In order to enhance the correlation between channels in the application model, the CBAM attention mechanism is added to the Head module. CBAM is used to enhance the representation ability of convolutional neural networks.
[0017] Furthermore, the flame and smoke detection model is a trained flame and smoke detection model, and the original loss function G-iou is replaced by the Wise-IoU loss function during training.
[0018] Since the algorithm of the present invention has a large number of deep feature extractions and the individual sizes of the data set are uneven, which leads to the convergence oscillation of the algorithm output results. In order to solve this problem, the present invention abandons the original loss function of YOLO (G-iou) and adds Wise-IoU as the loss function to reduce the harmful gradients generated by low-quality examples and accelerate the convergence of the model.
[0019] Furthermore, the Wise-IoU loss function is Wise-IoU v3.
[0020] In order to improve the overall performance of the detector and accelerate model convergence, Wise-IoU v3 is used in the application model. Wise-IoU v3 is an improved function based on Wise-IoU v1. This strategy reduces the competitiveness of high-quality anchor boxes while reducing the harmful gradients generated by low-quality examples and improving model accuracy.
[0021] Furthermore, the flame and smoke detection model is a trained flame and smoke detection model, and during training, the data set is enhanced using an albumentations module, including: blurring the original image, grayscale, strong exposure, and simulating foggy days.
[0022] Due to the uneven quality of fire detection cameras, the image quality obtained based on different regions and weather varies. The albumentations module is used to pre-process the enhanced data set online, which helps to enhance and improve the generalization ability and performance of the model, so that the model can be applied to cameras of different devices. The quality of the image in the traditional method directly affects the effect of subsequent foreground extraction and feature calculation. In order to obtain better detection performance, the present invention improves the model accuracy and generalization to a higher performance during training, so that when embedded, regardless of the quality of the input video or picture, it can achieve more accurate recognition. And it is suitable for video detection of flames and smoke in all environments.
[0023] Furthermore, the method further includes S4, determining the fire situation:
[0024] If the smoke value exceeds the first smoke threshold, it is determined that a fire situation exists;
[0025] If the flame value exceeds the first flame threshold, it is determined that a fire situation exists;
[0026] If the smoke value exceeds the second smoke threshold and the flame value exceeds the second flame threshold, it is determined that a fire situation exists;
[0027] Wherein, the first flame threshold is greater than the second flame threshold; the first smoke threshold is greater than the second smoke threshold;
[0028] When there is a fire, the alarm program is started and the alarm information is sent to the terminal.
[0029] Spontaneous combustion and forest fires usually follow the pattern of smoke before fire, because the combustible material will produce smoke before it is fully burned. However, not all fires follow this pattern. For example, the spontaneous combustion of electric vehicles often shows fire before smoke, because the chemical reaction inside the battery may directly cause the flame, and the smoke is produced later. Therefore, when designing a fire detection system, it is possible to flexibly set the detection parameters and trigger conditions.
[0030] In summary, due to the adoption of the above technical solution, the flame and smoke detection model constructed by the present invention effectively improves the ability to extract deep features while reducing model parameters, thereby enhancing the accuracy of the model. For dynamic and changeable features such as flames and smoke, the model provides an ideal solution. In addition, the model also shows excellent generalization ability.
[0031] The detection method proposed in the present invention can ensure high accuracy and low false detection rate in fire detection in various scenarios. Compared with the existing deep learning fire detection algorithm, the present invention can provide more reliable detection results when dealing with scenes with similar background colors to flames and smoke, as well as fires of different sizes. This not only significantly improves the accuracy of flame detection, but also reduces the risk of false identification, and at the same time has strong robustness, indicating its great potential in practical applications.
[0032] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0034] Figure 1 This is a flow chart of the real-time flame detection based on the detection algorithm of the present invention.
[0035] Figure 2 This is a structural diagram of the improved YOLOv8 model in the present invention.
[0036] Figure 3 This is a diagram showing the real-time flame detection effect based on the detection algorithm of the present invention.
[0037] Figure 4 This is a training parameter diagram based on the improved YOLOv8 model of the present invention; the last line is the algorithm parameter value, and the rest are the corresponding name, number of layers, and number of channels of the algorithm framework.
[0038] Figure 5 This is a diagram showing the classification and positioning effects of fire information in an image in this embodiment.
[0039] Figure 6 This is the result of some code training diagrams in this embodiment. Figure 6 (a), (b), and (c) are the positioning loss, classification loss, distribution focus loss, and Figure 6 (d) and (e) are the proportion of positive samples predicted correctly by the evaluation model and the proportion of all true positive samples that the evaluation model can find, respectively; Figure 6 (f), (g), and (h) are the localization loss, classification loss, and distribution focus loss of the validation set, respectively; Figure 6 (i) and (j) are mAP and mAP values in the lOU threshold range of 50-95%, respectively. DETAILED DESCRIPTION
[0040] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0041] The present invention is a flame and smoke detection method based on YOLOv8, the process is as follows Figure 1 As shown: First, the monitoring system inputs the real-time detection video into the computer, and the computer divides the video frame by frame and inputs it into the detection module. The detection module detects the image and outputs the result to the visual interface, reintegrates the single-frame image into a video, and displays the detection result in a visual box. The flame and smoke will be marked and labeled separately. If there is flame or smoke, the result of detecting the fire is output and an early warning is issued. The method of the present invention can be effectively used in commercial areas, factories, forests and other environments to improve the accuracy, generalization ability and detection rate of the flame detection algorithm.
[0042] The method of the present invention is implemented based on the improved YOLOv8 model: by adding the ECA attention mechanism to the Backbone part of YOLO, adding the CBAM attention mechanism to the Head, adding the Wise-IoU loss function to the indicator, adding the albumentations module to the online image preprocessing, making subtle parameter adjustments, and deploying it to the monitoring device for real-time monitoring after training. The structure after the improvement based on the YOLOv8 model is as follows Figure 2As shown. The 11 modules on the left are combined into the Backbone part: features are extracted through a series of convolutional layers and feature extraction modules, including feature maps of different scales. An ECA module is added to enhance information interaction between channels. The SPPF module is used for spatial pyramid pooling. The 12 modules on the right constitute the Head part: upsampling and feature fusion of the features extracted by the Backbone. The CBAM module is included for the channel attention mechanism. Finally, the target detection results are generated through a series of convolution operations and feature fusion. Starting from the upper left corner, two convolution modules (conv) extract features, and then three combinations of C2f and convolution modules are performed. Then the SPPF module is used for spatial pyramid pooling, followed by the added ECA module. Then enter the 4 modules on the right consisting of upsample, connection layer (concat), C2f and CBAM added by this algorithm for feature extraction. Finally, the required layer is output by the detect on the far right. 1, 2, 3, 4 processes are the connection layer part, which splices the upper part with the lower part to improve the model performance. 5, 6, 7 processes are the detection head part. The basic process is the YOLOv8 algorithm.
[0043] The specific embodiments are as follows:
[0044] Step 1: Collect data sets. Data sets come from github. The mainstream data platform data sets include cities, factories, homes, etc., totaling 30,000 images. Public data set source URL: GitHub-gaiasd / DFireDataset: D-Fire: an imagedata set for fire and smoke detection. These data sets are divided into training sets and test sets in an 8:2 ratio as the input of the model. Basic data set division, file name datasets.
[0045] Step 2: The YOLOv8 algorithm scales the image size of the dataset to 512×512, reduces the long side proportionally, fills the short side with gray edges, and then divides the image into N×N cells. The improved framework is an 11-layer Backbone and a 12-layer Head. The optimizer adaptively selects SGD. YOLOv8 is based on anchor-free free anchor frames, which means that the original fixed-size anchor frames are abandoned. Compared with the fixed anchor frame size, the free anchor frame has a higher degree of fit in detecting image targets. Add the ECA module and the CBAM module to the Backbone and Head modules in the YOLOv8 model, and modify the training parameters. The main body is still divided into two parts: Head and Backbone. Backbone is no longer CSP of v5, but Darknet-53 (C3 module is replaced by C2f module). ECA attention mechanism is added to the Backbone module. ECA is actually an improved version of SENET. It removes the fully connected layer in the original SENET and replaces it with a 1*1 convolution kernel for processing, making the model parameters smaller and more lightweight. Because ECA's convolution has good cross-channel information capture ability, it is unnecessary to capture information from all channels. Therefore, the fully connected layer is removed and replaced with a 1*1 convolution. ECA (ECA-Net) is a new convolutional neural network structure. Its advantages are as follows: (1) It can effectively capture long-distance dependencies. ECA-Net introduces a new channel attention mechanism that can weight the features of different channels, so that the network can better capture long-distance dependencies. (2) Small number of parameters and high computational efficiency. ECA-Net has smaller parameters than traditional convolutional neural networks, and can also greatly improve computational efficiency while ensuring accuracy. (3) It can adapt to different input sizes. ECA-Net can adapt to different input sizes and is therefore highly adaptable when processing images of different sizes. The core idea of the ECA module is to capture the dependencies between channels through one-dimensional convolution.
[0046] The core idea of the ECA module is to capture the dependencies between channels through one-dimensional convolution. Compared with the traditional attention mechanism, the ECA module avoids the complex dimensionality reduction and dimensionality increase process, thereby achieving high efficiency and lightweight characteristics. Specifically, the ECA module first adaptively calculates the kernel size k of the one-dimensional convolution according to the number of channels. The kernel size calculation formula is as follows:
[0047]
[0048] This formula is used to calculate the kernel size k for one-dimensional convolution. Where C is the number of channels of the input feature, and γ and b are hyperparameters. Taking the absolute value and rounding down to the nearest odd number is to ensure that the kernel size is an odd number. After obtaining the kernel size k, the ECA module applies a one-dimensional convolution to the input feature to learn the importance of each channel relative to other channels. This process can be expressed by the following formula:
[0049] out = Conv1D k (in)
[0050] This formula represents the conversion of input feature in to output feature out through a one-dimensional convolution operation (kernel size is k). k Represents a one-dimensional convolution operation with a kernel size of k.
[0051] Add the CBAM module to the Head. CBAM includes two submodules: Channel Attention Module and Spatial Attention Module. The Channel Attention Module is used to adjust the importance between channels, while the Spatial Attention Module is used to adjust the importance of spatial positions. This attention mechanism helps the network better capture the correlation between features and improve model performance. Assume that the input feature map is: F∈R C ×H×W ; Use CBAM to derive a one-dimensional channel attention map: M c ∈R C×1×1 and 2D spatial attention map: M s ∈R 1×H×W The overall attention process can be summarized as:
[0052]
[0053] Where F ′ is the feature map F generated after the channel attention module, and F″ is F ′ Generated after the spatial attention module. M c is the channel attention module, M s is a two-dimensional spatial attention module, Represents element-wise multiplication.
[0054] M c :Channel Attention Module
[0055] The channel relationship between features is used to generate a channel attention map. Since each channel of the feature map is considered as a feature detector, it makes sense that the channel's attention focuses on "what" in a given input image; in order to effectively calculate the channel attention, the method of compressing the spatial dimension of the input feature map is adopted; the AvgPool (average pooling) and MaxPool (maximum pooling) methods are used at the same time, and it is proved that this approach is more representative than using a single pooling method;
[0056]
[0057] Where, σ is the sigmoid function;
[0058] W0 and W1 both represent weights;
[0059] W0∈R C / r ×C , W1∈R C×C / r ;
[0060] MLP() stands for Multi-layer Perceptron;
[0061] F represents the feature map;
[0062] Indicates that the feature map is averagely pooled on the channel;
[0063] Indicates the maximum pooling of the feature map on the channel;
[0064] The weights W0 and W1 of MLP are shared, and the ReLU activation function is used before W0;
[0065] M s :Spatial Attention Module
[0066] The spatial attention map is generated by using the spatial relationship between features. Unlike the channel attention module, the spatial attention module focuses on the "where" part of the information as a complement to the channel attention module; to calculate the spatial attention, first apply the average pooling and maximum pooling operations along the channel axis and concatenate them to generate a valid feature descriptor; use two pooling operations to aggregate the channel information of a feature map and generate two 2Dmaps:
[0067] and
[0068] in, Indicates that the feature map is averagely pooled on the spatial features;
[0069] Indicates the maximum pooling of the feature map on the spatial features;
[0070] Each represents the average pooling characteristics and the maximum pooling characteristics of the channel, and then a standard convolutional layer is used to connect and convolve to obtain a two-dimensional spatial attention map;
[0071]
[0072] Where M s (F) represents a two-dimensional spatial attention map;
[0073] σ is the sigmoid function;
[0074] [;] indicates connection through convolutional layer;
[0075] f 7×7 () indicates the convolution operation using a 7×7 convolution kernel;
[0076] Abandon G-IoU in YOLOv8 and use Wise-IoU v3 as the loss function. Wise-IoU v1 constructs an attention-based bounding box loss, and Wise-IoU v2 and v3 add a focusing mechanism by constructing a gradient gain (focusing coefficient) calculation method on this basis. In other words, Wise-IoU v3 is an improvement on Wise-IoU v1.
[0077] x and y represent the coordinates of the original feature center point respectively;
[0078] x gt ,y gt Respectively represent the coordinates of the feature center point after adjustment;
[0079] Step 3: Add the Wise-IoU function to the metrics file and call it as the loss function. Use Wise-IoU v3, an improved function based on Wise-IoU v1. This strategy reduces the competitiveness of high-quality anchor boxes while reducing the harmful gradients generated by low-quality examples and improving model accuracy.
[0080] Wise-IoU v1 Since the training data inevitably contains low-quality examples, geometric factors such as distance and aspect ratio will aggravate the penalty for low-quality examples, thereby reducing the generalization performance of the model. A good loss function should weaken the penalty of geometric factors when the anchor box and the target box coincide well, and less training intervention will enable the model to obtain better generalization ability. The construction of Wise_IoU v1 is as follows:
[0081] L WIoUv1 =R WIoU L IoU
[0082]
[0083] Among them, L WIoUv1 Represents R WIoU With L IoU combination of;
[0084] R WIoU LioU represents the enlarged normal quality anchor box;
[0085] L IoU It is used to measure the overlap between the predicted box and the real box in the target detection task;
[0086] R WIoU ∈[1,e): significantly enlarge the L of the normal quality anchor box IoU ;
[0087] L IoU ∈[0,1]: significantly reduce the R of high-quality anchor boxes WIoU ,And when the anchor box and the target box overlap well, it pays more attention to the distance between the center points.
[0088] W g , H g is the size of the smallest enclosing box. WIoU Produces gradients that hinder convergence, W g , H g Separate from the computation graph (superscript * indicates this operation). gt ,y gt is the coordinate of the center of the anchor box after the move, and x and y represent the coordinates of the center point of the anchor box before the move. Because it effectively eliminates the factors that hinder convergence, no new metrics such as aspect ratio are introduced.
[0089] Wise-IoU v3: It is a dynamic non-monotonic loss function, that is, the condition of the bounding box with the highest gradient gain is in dynamic change, and its gradient gain changes non-monotonicly with the increase of loss value. The outlier degree of the anchor box is expressed as L Iou and The ratio represents:
[0090]
[0091] Among them, β represents the outlier degree;
[0092] It represents a monotonic focusing mechanism for cross entropy, which effectively reduces the contribution of simple examples to the loss value, which enables the model to focus on difficult examples and improve classification performance.
[0093] represents an exponential moving average with momentum;
[0094] A small outlier means that the anchor box is of high quality. We assign a small gradient gain to it so that BBR (bounding box regression) focuses on anchor boxes of normal quality. In addition, assigning a small gradient gain to anchor boxes with large outliers will effectively prevent low-quality examples from generating large harmful gradients. We use β to construct a non-monotonic focusing coefficient and apply it to Wise-loU v1 to obtain Wise-loU v3:
[0095]
[0096] Among them, L WIoUv1 Indicates Wise-loU v1, L WIoUv3 Indicates Wise-loU v3;
[0097] r represents the gradient gain;
[0098] a, δ represent hyper parameters;
[0099] The mapping between outlier degree β and gradient gain r is controlled by hyperparameters a and δ.
[0100] Step 4: Add albumentations module and apply it to online image preprocessing. In the application model, in order to make the algorithm have high accuracy and generalization in various real environments, the albumentations module is used to preprocess the enhanced data set online. Albumentations is a Python library for image enhancement, which provides a wealth of data enhancement techniques. This library can help data enhancement, thereby improving the generalization ability and performance of the model. The modules in albumentations used in the present invention are: Blur image blur function, the purpose is to simulate the image blur caused by weather reasons of the monitoring probe, the ksize blur level is set to 3-7 mild blur, and the probability of occurrence in the data set is 1%. MedianBlur detail blur processing, the purpose is to simulate the possible insufficient resolution of the monitoring probe equipment, resulting in the inability to clearly present the image details, the probability of occurrence in the data set is 1%, and the ksize blur level is set to 3-7 mild detail blur. ToGray is to randomly convert the image into a grayscale image, the purpose is to simulate the grayscale image of the night view of the night monitoring screen, and the probability of occurrence in the data set is 1%. CLAHE is to limit the brightness and darkness of the image, the purpose is to simulate the image under bright weather and strong exposure, the tilegridsize simulation intensity is set to 8-50, and the probability of occurrence in the data set is 1%. The RandomFog fog effect is used to simulate images in a foggy state. The coef fog intensity is set to 0.08 for light fog and the probability of occurrence in the data set is 1%. The parameters are optimized based on the data set used in the present invention.
[0101] Step 5: Input the data set into the model for training, adjust the parameters multiple times according to the training results, and keep the weight file with the highest detection speed and accuracy. Basic training parameters: data = data_yaml (data set and class name), epochs = 100 (number of training rounds), imgsz = 512 (input image size), batch = 4 (number of batches), workers = 2 (CUP and GPU operate together). Environment variable os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'. The optimizer automatically selects SGD; the training results are: FPS = 50, mAP = 0.796, weight file.
[0102] Step 6: Embed the detection program based on the best weight file into the monitoring device, monitor the input results in real time, and issue a warning in time when a flame is detected. Embed the monitoring device: best.pt uses the cv2 module to import the trained beat.pt weight file, and cap.read reads the camera input video frame by frame for detection, and outputs the detection video in real time. If a flame is detected, the video will be marked and the program will alarm.
[0103] At this point, real-time flame and smoke detection based on YOLOv8 has been completed.
[0104] Figure 3 This is a real-time flame detection effect diagram based on the detection algorithm of the present invention. The upper left side is the real-time detection picture after the camera is deployed, and the FPS is maintained between 45-55. The lower left side is the detection picture, and the scrolling code on the right is the real-time detection output of whether there is flame or smoke data. The entire detection example detects and outputs the detection results in real time after the camera is deployed.
[0105] Figure 4 This is the training parameter diagram of the improved YOLOv8 model in this invention; the last line is the algorithm parameter value, and the parameter value of 680,000 corresponds to 25 floating point values, which are all lightweight model parameter values. The rest are the corresponding names, number of layers, and number of channels of the algorithm framework.
[0106] Figure 5 This is a diagram showing the classification and positioning of fire information in an image in this embodiment. It can be seen intuitively that the flame and smoke are clearly marked, the detection effect is good, and there is no misjudgment or missed judgment.
[0107] Figure 6 This is the training result of some codes in this embodiment. The main information obtained from the figure is the training loss value, which reflects the degree of convergence of the model training. It can be clearly seen that the convergence is smooth; the prediction accuracy (precision) reflects the accuracy of the prediction result. It can be clearly seen that with the training of the model, the accuracy gradually increases until it stabilizes at 0.8; the recall rate (recall) reflects the curve that predicts the correct sample among all samples; the detection accuracy (mAP) reflects the curve that predicts the correct sample among all samples. It can be seen that it is basically stable at 0.8.
[0108] In order to prove the effectiveness of the method of the present invention, a control experiment was conducted. In the present invention, only the network structure is changed and the module of the present invention is added under the same basic environment and data set. The basic environment parameters are: Python = 3.8, CPU = i5-12600KF, GPU = NVIDIAGeForce RTX4060Ti, number of training rounds = 100, input size = 512, initial learning rate = 0.01. The control group YOLOv8s, YOLOv8m, YOLOv8l, and YOLOv8x do not add ECA and CBAM modules, do not modify the loss function, and do not add the Albumentations image enhancement module. The experimental results are shown in Table 1.
[0109] Table 1 Comparison of training results
[0110] Algorithm Name Parameter quantity Floating point values mAP50 FPS YOLOv8s 11166544 28.8GFLOPs 0.765 50 YOLOv8m 25902624 79.3GFLOPs 0.776 45 YOLOv8l 43691504 165.7GFLOPs 0.788 45 YOLOv8x 68229632 258.5GFLOPs 0.792 35 YOLOv8s Improvements 6938993 25.1GFLOPs 0.796 50
[0111] Table 1 is a comparison table of the training results of the present invention and the YOLOv8 model; it can be clearly seen that compared with the original YOLOv8 algorithm, the present invention has fewer parameters than YOLOv8s (lightweight model), which can save a lot of time in model training and reduce the pressure on the equipment in model deployment. The detection accuracy is the best compared to all YOLOv8 algorithms. The detection speed tends to a higher level, which is worthy of recognition for a fire detection algorithm with such high accuracy and low parameter volume on a public data set.
[0112] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. A real-time flame and smoke detection method based on YOLOv8, characterized in that: The following steps are involved: S1, data acquisition: real-time acquisition of flame and smoke images; S2, build the flame and smoke detection model: add the ECA attention mechanism to the Backbone part of the YOLOv8 model and the CBAM attention mechanism to the Head; S3, obtaining flame and smoke detection results: inputting the pre-processed flame and / or smoke image to be detected into the flame and smoke detection model to obtain the detection result; the detection result includes the smoke value and the flame value.
2. The real-time flame and smoke detection method based on YOLOv8 according to claim 1, characterized in that: The YOLOv8-based model adds the ECA attention mechanism to its Backbone part and the CBAM attention mechanism to the Head, including: The output end of the first convolution module is connected to the input end of the second convolution module, the output end of the second convolution module is connected to the input end of the first C2f module, the output end of the first C2f module is connected to the input end of the third convolution module, the output end of the third convolution module is respectively connected to the input end of the second C2f module and the input end of the first concat module, the output end of the second C2f module is connected to the input end of the fourth convolution module, the output end of the fourth convolution module is connected to the input end of the third C2f module, the output end of the third C2f module is connected to the input end of the fifth convolution module and the input end of the second concat module, the output end of the fifth convolution module is connected to the input end of the fourth C2f module, the output end of the fourth C2f module is connected to the input end of the SPPF module, and the output end of the SPPF module is connected to the input end of the ECA module; The output end of the ECA module is connected to the input end of the first upsampling module and the input end of the fourth concat module respectively; the output end of the first upsampling module is connected to the input end of the second concat module; the output end of the second concat module is connected to the input end of the fifth C2f module, the output end of the fifth C2f module is connected to the input end of the first CBAM module and the input end of the third concat module respectively, the output end of the first CBAM module is connected to the input end of the second upsampling module, the output end of the second upsampling module is connected to the input end of the first concat module, the output end of the first concat module is connected to the input end of the sixth C2f module, and the output end of the sixth C2f module is connected to the input end of the second CBAM module. The output end of the second CBAM module is connected to the input end of the third upsampling module; the output end of the third upsampling module is connected to the input end of the third concat module, and the output end of the third concat module is connected to the input end of the seventh C2f module; the output end of the seventh C2f module is connected to the input end of the third CBAM module, the output end of the third CBAM module is connected to the input end of the fourth upsampling module, the output end of the fourth upsampling module is connected to the input end of the fourth concat module, the output end of the fourth concat module is connected to the input end of the eighth C2f module, the output end of the eighth C2f module is connected to the input end of the fourth CBAM module, and the output end of the fourth CBAM module is connected to the input end of the second CBAM module; Among them, the first concat module, the second concat module, the third concat module, and the fourth concat module are used to concatenate data of two modules.
3. The real-time flame and smoke detection method based on YOLOv8 according to claim 1, characterized in that: The flame and smoke detection model is a trained flame and smoke detection model, and the original loss function is replaced by the Wise-IoU loss function during training.
4. The real-time flame and smoke detection method based on YOLOv8 according to claim 3, characterized in that: The Wise-IoU loss function is Wise-IoU v3.
5. The real-time flame and smoke detection method based on YOLOv8 according to claim 1, characterized in that: The flame and smoke detection model is a trained flame and smoke detection model. During training, the dataset is enhanced using the albumentations module, including blurring the original image, grayscale, strong exposure, and simulating foggy days.
6. The real-time flame and smoke detection method based on YOLOv8 according to claim 1, characterized in that: It also includes S4, judging the fire situation: If the smoke value exceeds the first smoke threshold, it is determined that a fire situation exists; If the flame value exceeds the first flame threshold, it is determined that a fire situation exists; If the smoke value exceeds the second smoke threshold and the flame value exceeds the second flame threshold, it is determined that a fire situation exists; Wherein, the first flame threshold is greater than the second flame threshold; The first smoke threshold is greater than the second smoke threshold; When there is a fire, the alarm program is started and the alarm information is sent to the terminal.
Citation Information
Cited By
Flame and smoke detection method based on RoseConv2d
CN120071247A