A fire detection method based on lightweight model
By combining depthwise separable convolution with lightweight attention mechanism, the fire detection model is optimized for running on hardware resource-constrained devices, solving the problems of small target flame recognition and confusion between smoke and fire-like targets, and achieving high-accuracy fire detection.
Patent Information
- Application Number
- CN202410616191.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-17
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2044-05-17
AI Technical Summary
Existing fire detection models are computationally intensive and cannot run on edge devices with limited hardware resources. They also fail to extract features of small flames, making it difficult to accurately identify flames when there is less smoke. Furthermore, the detection accuracy is low when smoke-like and fire-like targets are confused.
The model adopts depthwise separable convolution and lightweight attention mechanism, performs feature extraction and weighted bidirectional feature fusion through alternating lightweight attention modules, combines with the MobileViTv3 network, uses a self-built fire dataset for training and weight freezing, and optimizes the model's feature processing capabilities in fire scenarios.
It reduces model calculation requirements, improves the ability to identify small target flames, reduces false alarms, and enhances fire detection accuracy and response speed in complex scenarios.
Smart Images

Figure CN118429664B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of fire monitoring, and in particular to a fire detection method based on a lightweight model and a lightweight fire detection model with high accuracy. Background Art
[0002] Fire, a major natural disaster, poses a significant threat to human life and the natural environment. To detect fires promptly and minimize their damage, modern society relies on advanced fire detection systems. These systems monitor environmental changes, quickly sound alarms, and assist fire departments in efficient dispatch, effectively controlling fire damage.
[0003] In traditional fire detection systems, digital image processing technology is usually used to detect and identify the static characteristics of flames (such as color, shape and texture). However, static characteristics are easily affected by combustion conditions, combustion type and environmental factors, resulting in great differences in the static characteristics of fires, which in turn leads to poor detection results.
[0004] Based on this, existing technologies introduce the dynamic characteristics of fire (the temporal changes of flames) for analysis, and combine multi-scale convolution and attention mechanisms to perform deep fusion processing on images through feature pyramids to enhance the recognition ability and accuracy of small or distant flames.
[0005] However, although existing technologies have improved the sensitivity and speed of fire detection, the large weight of the attention mechanism leads to excessively high computational complexity and parameter count of the overall model. Fire detection models are generally installed on monitoring equipment in various fire-prone scenarios. These edge devices or mobile devices are limited by their hardware configuration, resulting in low computing power and the inability to directly run large models to identify and detect fires.
[0006] While existing technologies improve the sensitivity and speed of fire detection by combining dynamic and static fire characteristics, their high demand for computing resources makes them unsuitable for edge devices with larger hardware constraints. Furthermore, existing lightweight models fail to adequately extract and fuse the features of small flames in the early stages of a fire, making it difficult to accurately identify small flames when smoke is low. Furthermore, when smoke-like and fire-like targets appear in the same scene, model detection is prone to target confusion. Furthermore, in strong winds, the dynamic characteristics of flames and smoke change dramatically, making it difficult for existing models to effectively detect these changes based on time series. Summary of the Invention
[0007] Based on this, an object of the present invention is to provide a fire detection method based on a lightweight model.
[0008] A fire detection method based on a lightweight model includes the following steps:
[0009] S1: Downsampling and feature extraction are performed on the image to be detected several times in sequence by alternately setting the second version lightweight attention module and the third version lightweight attention module to obtain the first, second, third, fourth and fifth feature maps respectively; wherein the second version lightweight attention module and the third version lightweight attention module include sequentially connected depthwise separable convolution and lightweight attention mechanism, and the third version lightweight attention module also includes residual connection;
[0010] S2: Perform several weighted bidirectional feature fusions on the first, second, third, fourth and fifth feature maps to obtain the first, second, third, fourth and fifth fused feature maps respectively;
[0011] S3: All fused feature maps are sequentially integrated and upsampled through convolution to obtain the fire information in the image to be detected;
[0012] The trainable parameters in the downsampling operation, feature extraction operation, and weighted bidirectional feature fusion operation in the above steps are trained through the following steps:
[0013] ST1: Perform label detection on the source domain dataset and calculate the training loss parameter between the detection label and the true label. Update the weight of the trainable parameters according to the training loss parameter to obtain the trainable parameters for preliminary training.
[0014] Wherein, the tag detection is performed through steps S1 to S3;
[0015] ST2: Freeze the weights of the trainable parameters of the initial training of the second version of the lightweight attention module to obtain the frozen trainable parameters;
[0016] ST3: Use the frozen trainable parameters to detect a self-built fire training set, calculate the fire training loss parameter between the fire detection results and the true fire label, and update the weights of the frozen trainable parameters based on the fire training loss parameter.
[0017] The lightweight model-based fire detection method described in this paper significantly reduces its parameter count and computational requirements by employing depthwise separable convolution and a lightweight attention mechanism, improving real-time performance and making it suitable for edge devices with limited hardware resources. Furthermore, the method significantly enhances the ability to capture small target features by using weighted bidirectional feature fusion, addressing the issue of insufficient feature extraction for small flames (small targets) in the early stages of a fire.
[0018] In addition, the present invention can better adapt to fire scenarios by training on different data sets and freezing the weights of specific layers, thereby reducing false alarms while improving the accuracy of identifying actual fire situations.
[0019] Furthermore, the specific execution process of the alternating second version lightweight attention module and the third version lightweight attention module is as follows:
[0020] After convolution downsampling the image to be detected, feature extraction is performed through the second version of the lightweight attention module to obtain the first feature map;
[0021] The first feature map is then downsampled and feature extracted in sequence using the second version of the lightweight attention module to obtain a second feature map.
[0022] The second feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the third feature map;
[0023] The third feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the fourth feature map;
[0024] The fourth feature map is then downsampled using the second version of the lightweight attention module, and then feature extraction is performed using the third version of the lightweight attention module to obtain the fifth feature map.
[0025] Furthermore, the second version lightweight attention module includes a first local representation module and a first global representation module;
[0026] The first local representation module sequentially performs separable convolution and convolution on the input image or feature map to obtain a first local feature map;
[0027] The first global representation module flattens the first local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism, and converts the flattened first local feature map into a back tensor by folding to obtain a first global feature map;
[0028] The third version of the lightweight attention module includes a second local representation module, a second global representation module and a fusion module;
[0029] The second local representation module sequentially performs separable convolution and convolution on the input first global feature map to obtain a second local feature map;
[0030] The second global representation module flattens the second local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism, and converts it into a tensor by folding to obtain a second global feature map;
[0031] The fusion module is used to combine the second local feature map and the second global feature map to perform convolution to obtain a preliminary fusion feature map, and to perform weighted addition fusion on the first global feature map and the preliminary fusion feature map to obtain a feature map;
[0032] Among them, the scaling factor of the second version lightweight attention module and the third version lightweight attention module is 1.25.
[0033] The present invention uses the MobileViTv3 network to integrate local and global information in the image to be detected, thereby enhancing the ability to capture fire characteristics.
[0034] Furthermore, the step ST3 includes the following steps:
[0035] ST31: Test the self-built fire training set using frozen trainable parameters to obtain a fire detection map.
[0036] ST32: Calculate the classification loss and regression loss between the label detection map and the true label corresponding to the training data through cross entropy loss and mean square error loss, and use the training loss and regression loss as training loss parameters;
[0037] ST33: Update the weights of the frozen lightweight fire detection model according to the fire training loss parameter;
[0038] ST34: Determine whether the current loss rate or training rounds reaches a threshold. If yes, complete the training of the trainable parameters from step S1 to step S3; if no, execute step ST31.
[0039] Among them, since fire scenes may appear anywhere in daily life, the source domain dataset with diversity and a large number of category coverage can enable the fire detection model to be trained to better distinguish the content in the background and the feature extraction ability after training.
[0040] At the same time, because the second-version lightweight attention module does not incorporate residual connections, it focuses more on local information than the third-version lightweight attention module. Therefore, it is more sensitive to the quality of the input data. To prevent low-quality data from affecting the stability of the model, the second-version lightweight attention module is frozen after initial training to preserve the effective features learned on high-quality datasets.
[0041] Furthermore, step S2 includes the following steps:
[0042] S21: Perform preliminary feature fusion on the first, second, third, fourth and fifth feature maps through an intermediate feature weight distribution convolution to obtain the second, third and fourth intermediate feature maps;
[0043] Among them, for the second and third intermediate feature maps , It can be expressed as:
[0044]
[0045] For the fourth intermediate feature map :
[0046]
[0047] in, is the nth feature map, ; Learnable fusion weights assigned to intermediate feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assign convolution operations as intermediate feature weights;
[0048] S22: performing feature fusion on all intermediate feature maps and all feature maps through a final feature weight distribution convolution to obtain first, second, third, fourth and fifth fused feature maps;
[0049] Among them, for the second, third and fourth fusion feature maps , , which can be expressed as:
[0050]
[0051] For the first fusion feature map :
[0052]
[0053] For the fifth fusion feature map :
[0054]
[0055] in, is the nth feature map, ; For the Intermediate feature map, ; Learnable fusion weights assigned to the final feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assign convolution operation as the final feature weight;
[0056] After all fused feature maps are obtained, all current fused feature maps are used as feature maps, and steps S21 to S22 are performed, and repeated N times; ;
[0057] Among them, during the fusion process of each feature, the scaling factor of its feature map is 1.25.
[0058] A highly accurate and lightweight fire detection model, consisting of a backbone network, a neck network, and a prediction network;
[0059] The backbone network is used to sequentially perform several downsampling and feature extraction on the image to be detected through the alternately arranged second version lightweight attention module and the third version lightweight attention module to obtain the first, second, third, fourth and fifth feature maps respectively; wherein the second version lightweight attention module and the third version lightweight attention module include sequentially connected depthwise separable convolution and lightweight attention mechanism, and the third version lightweight attention module also includes residual connection;
[0060] The neck network is used to perform several weighted bidirectional feature fusions on the first, second, third, fourth and fifth feature maps to obtain the first, second, third, fourth and fifth fused feature maps;
[0061] The prediction network is used to sequentially integrate and upsample all fused feature maps through convolution to obtain fire information in the image to be detected;
[0062] The lightweight fire detection model is used as the lightweight fire detection model to be trained, and the trainable parameters in the model are trained through the following steps:
[0063] ST1: Use the to-be-trained lightweight fire detection model to perform label detection on the source domain dataset and calculate the training loss parameter between the detection label and the true label. Based on the training loss parameter, the weight of the to-be-trained lightweight fire detection model is updated to obtain a preliminarily trained lightweight fire model.
[0064] ST2: Freeze the weights of the trainable parameters of the initial training of the second version of the lightweight attention module to obtain the frozen trainable parameters;
[0065] ST3: Use the frozen lightweight fire detection model to test the self-built fire training set, calculate the fire training loss parameter between the fire detection results and the true fire label, and update the weight of the frozen lightweight fire detection model based on the fire training loss parameter to obtain a highly accurate lightweight fire detection model.
[0066] Furthermore, the specific execution process of the alternating second version lightweight attention module and the third version lightweight attention module is as follows:
[0067] After convolution downsampling the image to be detected, feature extraction is performed through the second version of the lightweight attention module to obtain the first feature map;
[0068] The first feature map is then downsampled and feature extracted in sequence using the second version of the lightweight attention module to obtain a second feature map.
[0069] The second feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the third feature map;
[0070] The third feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the fourth feature map;
[0071] The fourth feature map is then downsampled using the second version of the lightweight attention module, and then feature extraction is performed using the third version of the lightweight attention module to obtain the fifth feature map.
[0072] Furthermore, the second version lightweight attention module includes a first local representation module and a first global representation module;
[0073] The first local representation module sequentially performs separable convolution and convolution on the input image or feature map to obtain a first local feature map;
[0074] The first global representation module flattens the first local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism, and converts the flattened first local feature map into a back tensor by folding to obtain a first global feature map;
[0075] The third version of the lightweight attention module includes a second local representation module, a second global representation module and a fusion module;
[0076] The second local representation module sequentially performs separable convolution and convolution on the input first global feature map to obtain a second local feature map;
[0077] The second global representation module flattens the second local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism, and converts it into a tensor by folding to obtain a second global feature map;
[0078] The fusion module is used to combine the second local feature map and the second global feature map to perform convolution to obtain a preliminary fusion feature map, and to perform weighted addition fusion on the first global feature map and the preliminary fusion feature map to obtain a feature map;
[0079] Among them, the scaling factor of the second version lightweight attention module and the third version lightweight attention module is 1.25.
[0080] Furthermore, the step ST3 includes the following steps:
[0081] ST31: Test the self-built fire training set using frozen trainable parameters to obtain a fire detection map.
[0082] ST32: Calculate the classification loss and regression loss between the label detection map and the true label corresponding to the training data through cross entropy loss and mean square error loss, and use the training loss and regression loss as training loss parameters;
[0083] ST33: Update the weights of the frozen lightweight fire detection model according to the fire training loss parameter;
[0084] ST34: Determine whether the current loss rate or training rounds reaches a threshold. If yes, complete the training of the trainable parameters from step S1 to step S3; if no, execute step ST31.
[0085] Furthermore, the neck network includes an intermediate feature fusion module and a fusion feature module;
[0086] The intermediate feature fusion module is used to perform preliminary feature fusion on the first, second, third, fourth and fifth feature maps through an intermediate feature weight distribution convolution to obtain the second, third and fourth intermediate feature maps;
[0087] Among them, for the second and third intermediate feature maps , It can be expressed as:
[0088]
[0089] For the fourth intermediate feature map :
[0090]
[0091] in, is the nth feature map, ; Learnable fusion weights assigned to intermediate feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assign convolution operations as intermediate feature weights;
[0092] The fusion feature module is used to fuse all intermediate feature maps and all feature maps through a final feature weight distribution convolution to obtain the first, second, third, fourth and fifth fused feature maps;
[0093] Among them, for the second, third and fourth fusion feature maps , , which can be expressed as:
[0094]
[0095] For the first fusion feature map :
[0096]
[0097] For the fifth fusion feature map :
[0098]
[0099] in, is the nth feature map, ; For the Intermediate feature map, ; Learnable fusion weights assigned to the final feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assign convolution operation as the final feature weight;
[0100] After all fused feature maps are obtained, all current fused feature maps are used as feature maps, and the intermediate feature fusion module is called, and repeated N times; ;
[0101] Among them, during the fusion process of each feature, the scaling factor of its feature map is 1.25.
[0102] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0103] Figure 1 This is a structural diagram of the lightweight fire detection model described in the present invention;
[0104] Figure 2This is a flow chart of the fire detection method based on the lightweight model according to the present invention;
[0105] Figure 3 Schematic diagram of the reference structure of the lightweight fire model of the present invention;
[0106] Figure 4 This is a reference structure diagram of the backbone network of the present invention being MobileViTv3;
[0107] Figure 5 This is a simplified diagram of the second version of the lightweight attention module;
[0108] Figure 6 This is a simplified diagram of the third version of the lightweight attention module;
[0109] Figure 7 A simple schematic diagram of weighted bidirectional feature fusion;
[0110] Figure 8 This is an overall flow chart of the training method for the lightweight fire detection model described in the present invention. DETAILED DESCRIPTION
[0111] In order to simultaneously solve the technical problems that existing lightweight models cannot accurately identify small target flames in the early stage of a fire, and cannot accurately distinguish between smoke-like and fire-like targets when smoke-like and fire-like targets appear in the same scene at the same time, affecting the accuracy and real-time performance of the model in fire detection, the present invention strengthens the feature extraction capability of the detection target through deep separable convolution and lightweight attention mechanism, so that the model can fully extract the global and local information of the flame in the detection target under low computing power and obtain multi-scale feature maps; and through the weighted bidirectional feature pyramid (BiFPN) deep feature fusion of the multi-scale feature maps, thereby enhancing the model's recognition ability of flame, smoke-like and fire-like targets, so that the model can effectively distinguish small targets and improve the accuracy and response speed of fire detection.
[0112] The small number, low quality and high noise of existing public fire datasets affect the accuracy of the model during actual deployment and application.
[0113] To this end, the present invention adopts a pre-training strategy and uses a large dataset to optimize the learning and training of depthwise separable convolution and lightweight attention mechanism. After the training is completed, the weights of the local feature extraction operation are frozen, and the model is further fine-tuned using a self-built fire dataset to integrate the lightweight attention mechanism's global information processing capabilities in fire scenarios, thereby significantly improving the fire detection accuracy of the final model.
[0114] Based on the above research and design, the present invention proposes a fire detection method based on a lightweight model, and proposes a lightweight fire detection model based on the method.
[0115] Please also see Figure 1 、 Figure 2 and Figure 3 , Figure 1 This is a structural diagram of the lightweight fire detection model described in the present invention. Figure 2 This is a flow chart of the lightweight fire detection model described in the present invention. Figure 3 This is a schematic diagram of the reference structure of the lightweight fire model described in the present invention.
[0116] The lightweight fire detection model includes a backbone network 1, a neck network 2 and a prediction network 3.
[0117] The backbone network is used to execute step S1: downsampling and feature extraction are performed on the image to be detected several times in sequence through the alternately set second version lightweight attention module and the third version lightweight attention module to obtain the first, second, third, fourth and fifth feature maps respectively.
[0118] Specifically, the backbone network is a MobileViTv3 network. The specific structure of MobileViTv3 can be found in Figure 4 , including the second version lightweight attention module (MobileViTv2 Block, MV2) and the third version lightweight attention module (MobileViTv3 Block, MV3), the two are set alternately. The specific execution process is as follows:
[0119] After convolution downsampling the image to be detected, feature extraction is performed through the second version of the lightweight attention module to obtain the first feature map;
[0120] The first feature map is then downsampled and feature extracted in sequence using the second version of the lightweight attention module to obtain a second feature map.
[0121] The second feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the third feature map;
[0122] The third feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the fourth feature map;
[0123] The fourth feature map is then downsampled using the second version of the lightweight attention module, and then feature extraction is performed using the third version of the lightweight attention module to obtain the fifth feature map.
[0124] See also Figure 5 , Figure 5 A simplified diagram of the second version of the lightweight attention module.
[0125] The second version of the lightweight attention module includes a first local representation module (Local Representation Block) and a first global representation module (Global Representation Block).
[0126] The first local representation module performs separable convolution and convolution on the input image or feature map in sequence to obtain a first local feature map.
[0127] The first global representation module flattens (UnFold) the first local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism (Linear Transformer), and converts it into a tensor through folding (fold) to obtain the first global feature map.
[0128] Flattening involves setting a sliding window on the input tensor (feature map) and expanding the data within the sliding window into a column to obtain a flattened tensor for processing by the linear attention mechanism. Folding is the inverse of flattening, folding the flattened tensor to match the input tensor. For details on flattening and folding, refer to the torch.nn.unfold() and torch.nn.fold() functions in the Pytorch library. This document will not go into detail here.
[0129] See also Figure 6 , Figure 6 A simplified diagram of the third version of the lightweight attention module.
[0130] The third version of the lightweight attention module includes a second local representation module, a second global representation module and a fusion module (Fusion Block).
[0131] The second local representation module sequentially performs separable convolution and convolution on the input first global feature map to obtain a second local feature map.
[0132] The second global representation module flattens the second local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism, and converts it into a tensor by folding to obtain a second global feature map.
[0133] The fusion module is used to combine the second local feature map and the second global feature map for convolution to obtain a preliminary fusion feature map, and to perform weighted addition fusion on the first global feature map and the preliminary fusion feature map to obtain a feature map.
[0134] Among them, through alternating local representation modules and global representation modules, local and global information in the image can be effectively extracted and integrated. In particular, the global representation module further combines the idea of residual connection and fully integrates the global feature information, so that the model can effectively capture the key features of the fire, thereby improving the response speed and detection accuracy of the overall model.
[0135] In addition, each lightweight representation module is optimized specifically for the needs of fire detection, such as adjusting the scaling factor (exponential growth and scaling of the number of channels) to 1.25.
[0136] The neck network 2 is used to execute step S2: performing several weighted bidirectional feature fusions on the first, second, third, fourth and fifth feature maps to obtain the first, second, third, fourth and fifth fused feature maps.
[0137] Specifically, the neck network 2 is a weighted bidirectional feature pyramid (BiFPN) which includes an intermediate feature fusion module 21 and a fusion feature module 22 .
[0138] See also Figure 7 , Figure 7 A simple diagram of weighted bidirectional feature fusion.
[0139] The intermediate feature fusion module 21 is used to execute step S21: performing preliminary feature fusion on the first, second, third, fourth and fifth feature maps through an intermediate feature weight distribution convolution to obtain the second, third and fourth intermediate feature maps.
[0140] Specifically, for the second and third intermediate feature maps , It can be expressed as:
[0141]
[0142] For the fourth intermediate feature map :
[0143]
[0144] in, is the nth feature map, ; Learnable fusion weights assigned to intermediate feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assign convolution operations as intermediate feature weights;
[0145] The fusion feature module 22 is used to execute step S22: fusing all intermediate feature maps and all feature maps through a final feature weight distribution convolution to obtain first, second, third, fourth and fifth fused feature maps.
[0146] Specifically, for the second, third and fourth fusion feature maps , , which can be expressed as:
[0147]
[0148] For the first fusion feature map :
[0149]
[0150] For the fifth fusion feature map :
[0151]
[0152] in, is the nth feature map, ; For the Intermediate feature map, ; Learnable fusion weights assigned to the final feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assigning a convolution operation to the final feature weights;
[0153] In addition, during the fusion of each feature, the scaling factor (exponential scaling of the number of channels) of its feature map is 1.25.
[0154] After all fused feature maps are obtained, all current fused feature maps are used as feature maps, and step S21 is executed and repeated N times; wherein, , in order to reduce overfitting while maintaining full integration.
[0155] The prediction network 3 is used to execute step S3: performing feature integration and upsampling on all fused feature maps in sequence through convolution to obtain fire information in the image to be detected.
[0156] Specifically, all fused feature maps are integrated through convolution to obtain an integrated feature map, which has all the characteristic information about the fire.
[0157] The integrated feature map is upsampled by convolution to adjust its size to the size of the image to be detected. Figure 1 To obtain the fire information in the image to be detected.
[0158] See also Figure 8 , Figure 8 This is the training method of the lightweight fire detection model described in the present invention.
[0159] In order to obtain a lightweight fire detection model with high accuracy, the present invention trains the lightweight fire detection model to be trained through the following steps, the specific steps of which are:
[0160] ST1: Use the to-be-trained lightweight fire detection model to perform label detection on the source domain dataset, and calculate the training loss parameter between the detection label and the true label. Based on the training loss parameter, the weight of the to-be-trained lightweight fire detection model is updated to obtain a preliminarily trained lightweight fire model.
[0161] Specifically, step ST1 includes the following steps:
[0162] ST11: Use the lightweight fire detection model to be trained to detect the training data in the source domain dataset and obtain a label detection map.
[0163] Specifically, the source domain dataset adopts ImageNet, which is a large-scale public visual dataset containing multiple categories. The images in the dataset are equipped with detailed real labels. The images are used as training data for feature extraction and label detection to obtain label detection maps.
[0164] Among them, since fire scenes may appear anywhere in daily life, the diversity and large category coverage of ImageNet can enable the fire detection model to be trained to better distinguish the content in the background after training and improve the feature extraction capability.
[0165] The parameter weights of the fire detection model to be trained are in a relatively primitive state, so the detection effect is poor. In addition, since the detection process is a specific implementation step of the aforementioned fire detection, the present invention will not repeat the detection process here.
[0166] ST12: Calculate the loss between the label detection graph and the true label corresponding to the training data to obtain the training loss parameter.
[0167] Specifically, the classification loss and regression loss between the label detection map and the true label corresponding to the training data are calculated by cross entropy loss and mean square error loss, and the training loss and regression loss are used as training loss parameters.
[0168] The cross-entropy loss is used to optimize the performance of classification tasks, and the mean squared error loss is used to improve the accuracy of the model in regression tasks. Both are common knowledge in the field. Furthermore, the present invention can also be combined with loss functions of other object detection algorithms for training, such as GIOU (Generalized Intersection over Union), CIoU (Complete-IoU), SIoU (Smoothed-IoU), and WIoU (Wise-IoU). Accordingly, the present invention does not specifically limit the choice of loss function.
[0169] ST13: Update the weights of the lightweight fire detection model to be trained according to the training loss parameters.
[0170] Specifically, the weights of the lightweight fire model to be trained are updated through the back-propagation algorithm and combined with the training loss parameters, so that the lightweight fire detection model to be trained can further learn the core content of the training data according to the training loss parameters.
[0171] The back propagation algorithm is a gradient descent algorithm (SGD) used to find the weight to minimize the error.
[0172] ST14: Determine whether the current loss rate or training rounds reaches a threshold. If yes, obtain a preliminarily trained lightweight fire model and execute step ST2; if no, execute step ST11.
[0173] The threshold can be set by empirically analyzing the loss rate and the number of training rounds to determine the effectiveness of the model training. Accordingly, the present invention does not specifically limit the conditions of the threshold.
[0174] ST2: Freeze the weights of the second version of the lightweight attention module of the initially trained lightweight fire model to obtain the frozen lightweight fire detection model.
[0175] Specifically, the weights of the second version of the lightweight attention module in the lightweight fire model that has been preliminarily trained on the source domain dataset are frozen to obtain a frozen lightweight fire detection model.
[0176] Among them, see Figure 5 Because the second-version lightweight attention module does not incorporate residual connections and focuses more on local information than the third-version lightweight attention module, it is more sensitive to the quality of the input data. To prevent low-quality data from affecting the stability of the model, the second-version lightweight attention module is frozen after initial training to preserve the effective features learned on high-quality datasets.
[0177] In addition, since the third version of the lightweight attention module has the characteristic of residual connection to integrate local information and global information, the module does not learn the fire characteristics sufficiently and is not frozen.
[0178] ST3: Use the frozen lightweight fire detection model to test the self-built fire training set, calculate the fire training loss parameter between the fire detection results and the true fire label, and update the weight of the frozen lightweight fire detection model based on the fire training loss parameter to obtain a highly accurate lightweight fire detection model.
[0179] Specifically, step ST3 includes the following steps:
[0180] T31: Use the frozen lightweight fire detection model to detect the self-built fire training set and obtain the fire detection map.
[0181] Specifically, the self-built fire dataset is image data collected online or shot by self-simulated fires, and the corresponding fires in the images are manually annotated in detail and used as training data for feature extraction and fire detection to obtain fire detection maps.
[0182] Among them, the fire scene collection based on the self-built fire dataset and the self-built fire dataset based on different users will affect the efficiency of model learning.
[0183] T32: Calculate the loss between the fire detection image and the corresponding fire true label to obtain the fire training loss parameter.
[0184] Specifically, the classification loss and regression loss between the label detection map and the true label corresponding to the training data are calculated by cross entropy loss and mean square error loss, and the training loss and regression loss are used as training loss parameters.
[0185] The calculation here is the same as the aforementioned loss calculation, and the present invention will not elaborate on it here.
[0186] ST33: Update the weights of the frozen lightweight fire detection model according to the fire training loss parameter.
[0187] Specifically, the unfrozen portion of the frozen lightweight fire detection model is fine-tuned by an optimizer.
[0188] Among them, the optimizer can be selected as the Adam optimizer, which can ensure that the model achieves relatively better learning effects in complex fire scenarios.
[0189] ST34: Determine whether the current loss rate or training rounds reaches a threshold. If so, obtain a lightweight fire detection model with high accuracy; if not, execute step ST31.
[0190] Specifically, by monitoring whether the number of rounds or loss rate of the current training cycle reaches a custom threshold, if yes, the training is completed, otherwise the training continues.
[0191] Among them, setting a suitable threshold through experience can ensure that the model does not overfit while maintaining training efficiency, reducing invalid training, and saving computing resources.
[0192] Compared to existing technologies, this invention combines MobileViTv3 with BiFPN to reduce the computational complexity of the lightweight fire detection model while maintaining a certain level of accuracy, enabling the model to operate effectively even in resource-constrained environments. Furthermore, a phased training approach is employed, freezing the weights of the second-version lightweight attention module in the initial stages of training while focusing fine-tuning training on the third-version lightweight attention module, which contributes more significantly to fire detection tasks. This effectively improves training efficiency, maintains the stability of pre-trained (initial training) features, and reduces the risk of overfitting.
[0193] Furthermore, by using a weighted bidirectional feature pyramid (BiFPN), the model enhances its ability to recognize small objects and complex fire scenes, effectively addressing issues such as insufficient small object detection and confusion between smoke-like and fire-like objects. Furthermore, by fine-tuning the model using a self-built fire dataset, the model can adapt to a wider range of fire scenarios, improving detection performance in real-world fire scenarios.
[0194] Based on the same inventive concept, the present application also provides an electronic device, which can be a terminal device such as a server, a desktop computing device, or a mobile computing device (e.g., a laptop computing device, a handheld computing device, a tablet computer, a netbook, etc.). The device includes one or more processors and a memory, wherein the processor is configured to execute a program to implement the lightweight model-based fire detection method according to an embodiment of the present invention; and the memory is configured to store a computer program executable by the processor.
[0195] Based on the same inventive concept, the present application also provides a computer-readable storage medium, corresponding to the aforementioned embodiment of a fire detection method based on a lightweight model, wherein the computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the steps of the fire detection method based on a lightweight model described in any of the aforementioned embodiments.
[0196] The present application may take the form of a computer program product implemented on one or more storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing program code. Computer-usable storage media include permanent and non-permanent, removable and non-removable media, and information storage can be achieved by any method or technology. The information can be computer-readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include but are not limited to: phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission medium that can be used to store information that can be accessed by a computing device.
[0197] The above-described embodiments merely represent several implementations of the present invention. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art would be able to make numerous modifications and improvements without departing from the spirit of the present invention, and the present invention is intended to encompass such modifications and variations.
Claims
1. A fire detection method based on a lightweight model, characterized in that: The following steps are involved: S1: The second version lightweight attention module and the third version lightweight attention module are alternately set to perform downsampling and feature extraction on the image to be detected several times in sequence, and the first, second, third, fourth and fifth feature maps are obtained respectively; The second version of the lightweight attention module includes a first local representation module and a first global representation module; The first local representation module sequentially performs separable convolution and convolution on the input image or feature map to obtain a first local feature map; The first global representation module flattens the first local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism, and converts the flattened first local feature map into a back tensor by folding to obtain a first global feature map; The third version of the lightweight attention module includes a second local representation module, a second global representation module and a fusion module; The second local representation module sequentially performs separable convolution and convolution on the input first global feature map to obtain a second local feature map; The second global representation module flattens the second local feature map, then performs attention calculation on the flattened first local feature map through a linear attention mechanism, and converts it into a tensor by folding to obtain a second global feature map; The fusion module is used to combine the second local feature map and the second global feature map to perform convolution to obtain a preliminary fusion feature map, and to perform weighted addition fusion on the first global feature map and the preliminary fusion feature map to obtain a feature map; Among them, the scaling factor of the second version of the lightweight attention module and the third version of the lightweight attention module is 1.25; S2: Perform several weighted bidirectional feature fusions on the first, second, third, fourth and fifth feature maps to obtain the first, second, third, fourth and fifth fused feature maps respectively; S3: All fused feature maps are sequentially integrated and upsampled through convolution to obtain the fire information in the image to be detected; The trainable parameters in the downsampling operation, feature extraction operation, and weighted bidirectional feature fusion operation in the above steps are trained through the following steps: ST1: Perform label detection on the source domain dataset and calculate the training loss parameter between the detection label and the true label. Update the weight of the trainable parameters according to the training loss parameter to obtain the trainable parameters for preliminary training. Wherein, the tag detection is performed through steps S1 to S3; ST2: Freeze the weights of the trainable parameters of the initial training of the second version of the lightweight attention module to obtain the frozen trainable parameters; ST3: Use the frozen trainable parameters to detect a self-built fire training set, calculate the fire training loss parameter between the fire detection results and the true fire label, and update the weights of the frozen trainable parameters based on the fire training loss parameter.
2. The fire detection method based on a lightweight model according to claim 1, characterized in that: The specific execution process of the alternating second version lightweight attention module and the third version lightweight attention module is as follows: After convolution downsampling the image to be detected, feature extraction is performed through the second version of the lightweight attention module to obtain the first feature map; The first feature map is then downsampled and feature extracted in sequence using the second version of the lightweight attention module to obtain a second feature map. The second feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the third feature map; The third feature map is downsampled by the second version lightweight attention module, and then feature extracted by the third version lightweight attention module to obtain the fourth feature map; The fourth feature map is then downsampled using the second version of the lightweight attention module, and then feature extraction is performed using the third version of the lightweight attention module to obtain the fifth feature map.
3. The fire detection method based on a lightweight model according to claim 2, characterized in that: The step ST3 comprises the following steps: ST31: Test the self-built fire training set using frozen trainable parameters to obtain a fire detection map. ST32: Calculate the classification loss and regression loss between the label detection map and the true label corresponding to the training data through cross entropy loss and mean square error loss, and use the training loss and regression loss as training loss parameters; ST33: Update the weights of the frozen lightweight fire detection model according to the fire training loss parameter; ST34: Determine whether the current loss rate or training rounds reaches a threshold. If yes, complete the training of the trainable parameters from step S1 to step S3; if no, execute step ST31.
4. The fire detection method based on a lightweight model according to claim 3, characterized in that: The step S2 comprises the following steps: S21: Perform preliminary feature fusion on the first, second, third, fourth and fifth feature maps through an intermediate feature weight distribution convolution to obtain the second, third and fourth intermediate feature maps; Among them, for the second and third intermediate feature maps , It can be expressed as: For the fourth intermediate feature map : in, is the nth feature map, ; Learnable fusion weights assigned to intermediate feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assign convolution operations as intermediate feature weights; S22: performing feature fusion on all intermediate feature maps and all feature maps through a final feature weight distribution convolution to obtain first, second, third, fourth and fifth fused feature maps; Among them, for the second, third and fourth fusion feature maps , , which can be expressed as: For the first fusion feature map : For the fifth fusion feature map : in, is the nth feature map, ; For the Intermediate feature map, ; Learnable fusion weights assigned to the final feature weights; is a constant to prevent the weight from being zero; The function converts the input Resize feature map size into the same size as the feature map calculated by addition; Assign convolution operation as the final feature weight; After all fused feature maps are obtained, all current fused feature maps are used as feature maps, and steps S21 to S22 are performed, and repeated N times; ; Among them, during the fusion process of each feature, the scaling factor of its feature map is 1.25.
Citation Information
Patent Citations
Transform-based lightweight early fire detection method
CN114882430A
Fire early-stage smoke detection method and system based on YOLOv5
CN115601696A