Medium-wave infrared gas leakage detection method based on improved yolov11s
By improving the YOLOv11s network and combining the RepVGG backbone, BiFPN-PAN, CARAFE, CBAM, and Transformer-Encoder, the accuracy and real-time performance issues of gas leak detection in industrial scenarios were resolved, achieving efficient gas leak detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-02
- Publication Date
- 2026-03-13
AI Technical Summary
Existing technologies for gas leak detection in industrial scenarios suffer from problems such as difficulty in detecting small targets, low contrast and strong background interference, and limited model deployment, resulting in insufficient detection accuracy and real-time performance.
An improved YOLOv11s network is adopted, which introduces the RepVGG backbone network, BiFPN-PAN cross-layer bidirectional feature fusion structure, CARAFE upsampling operator, CBAM and SE modules, and combines a lightweight Transformer-Encoder to optimize the loss function and inference process, enhance global modeling capabilities and reduce computational overhead.
It significantly improves the detection capability of small-volume leaks, reduces computational overhead, enables real-time gas leak detection under complex operating conditions, and enhances detection accuracy and robustness.
Smart Images

Figure CN121661328A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision and target detection technology, specifically to a mid-wave infrared gas leak detection method based on an improved YOLOv11s. Background Technology
[0002] In industrial settings, oil and gas, chemical, coal chemical, and city gas plants all face the risk of gas leaks during production, storage, transportation, and pipeline operation. Methane (CH4) and volatile organic compounds (VOCs), as common leak media, not only pose explosive and toxic hazards but also have a significant greenhouse effect. Therefore, leak detection and rapid response have become crucial for the intrinsic safety and green, low-carbon operation of these plants. In regulatory practice, "Leak Detection and Repair (LDAR)" is widely used. The U.S. Environmental Protection Agency (EPA) uses optical gas imaging (OGI) as a compliant alternative to traditional portable detection (Method 21) to visualize and identify VOCs / methane leak locations and plume distribution.
[0003] Currently, commonly used leak detection technologies include point sensing, open-path optical measurement, and optical gas imaging (OGI). Among these, OGI offers the advantages of being intuitive and fast, and has become the mainstream method in oil refining, chemical, and storage and transportation processes. However, the image characteristics of OGI are affected by factors such as gas type, background temperature difference, plume turbulence, and wind speed, often resulting in low contrast, blurred edges, and unstable morphology. This characteristic makes it easy for manual observation to miss small leaks, and traditional image processing algorithms are difficult to adapt to complex scenarios.
[0004] In recent years, deep learning-based automatic detection methods have made progress in OGI image recognition, but three prominent problems still exist: Small targets are difficult to detect: gas plumes occupy a very small area in the image, and traditional convolutional models are not sensitive enough to weak texture features, making them prone to missed detection.
[0005] Low contrast and strong background interference: In complex industrial backgrounds, the brightness difference between the edge of the plume and the background is slight, and existing models often lack cross-scale fusion and attention mechanisms.
[0006] Deployment limitations: Existing high-precision models have a large number of parameters and high inference overhead, making it difficult to achieve real-time detection on edge devices in industrial settings.
[0007] Therefore, although existing technologies can achieve high detection accuracy in experimental environments, their performance is significantly insufficient under complex working conditions, real-time requirements, and hardware deployment constraints. Summary of the Invention
[0008] To overcome the shortcomings of the existing technologies, the present invention aims to provide a mid-wave infrared gas leak detection method based on an improved YOLOv11s. This method improves the network backbone and neck structure, introduces multi-scale feature fusion and attention mechanisms, enhances global modeling capabilities, and optimizes the bounding box loss function. While ensuring detection accuracy, it significantly reduces computational overhead, thereby effectively solving industry pain points such as difficulty in detecting small leaks, easy omission of low-contrast plumes, and difficulty in real-time model deployment. This provides a reliable and scalable technical solution for gas leak detection.
[0009] To achieve the above objectives, the technical solution adopted by the present invention is as follows: A mid-wave infrared gas leak detection method based on improved YOLOv11S includes the following steps; Step 1: Collect gas leak video data, filter out valid video frames, and then manually annotate them using the darklabel tool; Step 2: Preprocess the acquired video frames before training; preprocessing includes non-uniformity correction (NUC), quantile cropping and normalization, Gamma transformation, CLAHE adaptive histogram equalization, and construction of three-frame difference sequences; to ensure that the input sequence has a stable brightness distribution, sufficient local contrast, and feather dynamic features. Step 3: Improve the YOLO11s algorithm network structure, and then input the preprocessed dataset from Step 2 into the improved YOLO11s network for iterative training. Optimize using a joint loss function, and combine cosine annealing learning rate scheduling and exponential moving average (EMA) methods to improve convergence and obtain the optimal model parameters for subsequent leak detection inference. Step 4: After training, the image or video frame to be detected is input into the optimal model, and the detection box, category and confidence of the gas leak area are output. An enhanced box filtering mechanism is introduced in the inference stage. The candidate box is screened by combining confidence, IoU, target size, local contrast gating and time consistency constraints. Finally, the detection result is obtained by non-maximum suppression (NMS).
[0010] Step 1 involves acquiring mid-wave infrared images or video frames using a cooled infrared thermal imager, filtering out valid frames, and labeling them to construct a single-class dataset containing only gas leaks; and acquiring image or video sequences of gas leak scenes. This method aims to focus on detecting the "gas leak" type of abnormal phenomenon, therefore, category filtering is performed during the labeling stage, allowing subsequent models to focus on identifying the leak plume morphology.
[0011] Step 2 specifically involves... To eliminate fixed-pattern noise and pixel response differences in the infrared detector, NUC correction is performed on the input video frame pixel values I(x, y). The correction model is as follows: Where D(x, y) is the dark field response, F(x, y) is the flat field response, and M is the gain coefficient; To suppress the impact of extreme brightness values caused by clouds, ground reflections, or noise on the dynamic range, while ensuring consistent brightness scale in subsequent inputs, the corrected image undergoes quantization and normalization processing; assuming... These are the low and high quantile rates, with the corresponding upper and lower quantile points as follows: The pixels are cropped using this interval, limiting the pixel values to within this interval. The pixel values after the upper and lower quantile point limiting processing are denoted as... Its cutting formula is This formula is applied to pixels first. Raise all abnormal dark values below the lower quantile to this lower bound, and then... All abnormal brightness values exceeding the upper boundary are suppressed to the upper limit, achieving bidirectional amplitude limiting; thereby suppressing extreme noise while preserving effective structural information, making the image brightness distribution stable and suitable for subsequent enhancement processing; the amplitude-limited image is further processed according to... Mapped to the range [0, 1] to obtain a uniform brightness scale, denoted as Subsequently, to enhance the visibility of weak-contrast regions in the gas plume, a Gamma transformation was applied to the normalized image, ensuring the output satisfies: in For exponential adjustment parameters, This enhances shadow detail and improves the perceived contrast of feather boundaries. To further enhance local detail and texture, contrast-limited adaptive histogram equalization (CLAHE) is performed on the Gamma-transformed image, using local windows to accumulate histograms. Perform remapping to make the enhanced image satisfy: Where M and N are the local window sizes, and L is the number of gray levels. The minimum cumulative value is non-zero. To highlight the temporal variations of the plume, such as diffusion, drift, and turbulence, in the MWIR (Medium-Wave Infrared) sequence, a three-frame difference sequence is constructed based on the enhanced image: This enables the network to gain stronger motion sensitivity; finally, all preprocessed sequence data are divided into training, validation and test sets in an 8:1:1 ratio.
[0012] In step 3, the improved yolov11s algorithm network structure uses RepVGG as the backbone network; a BiFPN-PAN cross-layer bidirectional feature fusion structure is introduced in the neck, and the upsampling operator is replaced with CARAFE to achieve efficient aggregation and fine-grained reconstruction of features at different levels.
[0013] The specific operation of the detection algorithm includes the following steps: Step 3.1: The gas leak image after data preprocessing is first input into the backbone network for preliminary feature extraction; The reparameterized RepVGG backbone network outputs multi-scale feature maps at different depths simultaneously. This provides input for subsequent cross-level feature fusion in the neck layer. After the above processing, the final features not only contain richer semantic information and clearer spatial edge structures, but also maintain high consistency and stability during inference due to the reduced number of convolutional kernels and the contraction of the computation path. These reparameterized enhanced features will be further used in subsequent detection heads for target classification and bounding box prediction, through the aforementioned comprehensive scoring function. Improve candidate box sorting and filtering performance, and combine local contrast gating. The constraints suppress low-contrast false boxes, thereby achieving higher detection accuracy, lower false detection rate and stronger robustness. Through the synergistic effect of the above structural optimization and scoring constraints, the model of this invention significantly improves the gas leak detection capability while maintaining real-time performance, and is suitable for high-reliability leak monitoring tasks in industrial sites. Step 3.2: Introduce a BiFPN-PAN fusion structure in the neck layer and use the CARAFE operator as an upsampling method to achieve efficient aggregation and fine-grained enhancement of multi-scale features output by the backbone network; The multi-scale features output by the backbone network in step 3.1 are first input to the neck layer. Features from different levels interact through the bidirectional path of BiFPN, which includes both top-down high semantic transmission and bottom-up detail compensation. A BiFPN-PAN fusion structure was introduced into the neck layer, and the CARAFE operator was used as the upsampling method. The multi-scale features output from the backbone network are fed into the neck layer for fusion; this invention uses a BiFPN-PAN fusion structure to replace the traditional hollow spatial pyramid pooling (ASPP) module, and the fusion formula is as follows: Where A(·) represents the alignment operator, used to perform upsampling, downsampling, and channel alignment operations. For learnable weights, The numerically stable term; BiFPN's top-down and bottom-up bidirectional paths enable full interaction between features at different levels, and suppress invalid branches through learnable weight allocation, thereby achieving adaptive aggregation of multi-scale features to improve the discriminability of shallow targets and weakly textured feather regions; at the same time, the introduction of the PAN path structure further enhances the convergence of low-level detail information and high-level semantic information; in the upsampling stage, this invention uses the CARAFE (content-aware reassembly upsampling) operator, which uses content-related reassembly kernels to weight neighborhood features, thereby obtaining high-resolution feature maps with smoother edges and clearer contours: in The upsampling kernel is predicted at position (u, v), and N is the local neighborhood. With the help of this content-aware reorganization mechanism, the upsampling features are significantly better than traditional methods in terms of edge continuity, contour sharpness, and texture details. It is particularly suitable for challenging scenarios such as gas plume boundaries that are blurred, low contrast, and small target size. Through the above design, the feature map output by the neck layer maintains high expression quality at multiple scales, which is beneficial to improving the detection performance of small target gas plumes. Step 3.3: In shallow feature processing, this invention introduces the CBAM module, which consists of Channel Attention (CAM) and Spatial Attention (SAM), and can simultaneously weight and adjust features in both the channel and spatial dimensions. First, the shallow multi-scale features extracted from the backbone network described in step 3.1 are input into the CAM; channel description vectors are generated by max pooling and average pooling respectively, and channel weight vectors are obtained by multilayer perceptron and sigmoid activation. Then, these weight vectors are multiplied by the input features channel by channel to obtain the weighted features. Subsequently, the weighted features are input into SAM, where max pooling and average pooling operations are performed in the spatial dimension, and the data is concatenated in the channel dimension. After convolution and sigmoid activation, a spatial weight map is obtained, which is then multiplied with the weighted features to output the spatial attention-optimized features. The CBAM spatial attention formula: Wherein, the input feature map F represents a size of The three-dimensional tensor is given by H, where H is the feature map height, W is the width, and C is the number of channels; the global average pooling and global max pooling operations in the spatial domain are respectively expressed as: and The results obtained are processed in the CBAM module via a size of Convolution operator Further processing, and using the Sigmoid function. Mapped to the [0, 1] interval to generate a spatial attention weight map This process weights and modulates the input features in the spatial dimension, enabling the network to adaptively highlight key details of potential gas leak areas while suppressing background noise interference.
[0014] In deep feature processing, this invention introduces an SE module, which inputs the deep multi-scale features extracted from the backbone network described in step 3.1 into the SE module. First, the channel description vector is obtained by global average pooling; then it is input into two fully connected layers, first activated by ReLU and then by Sigmoid to obtain the channel weight vector; finally, the channel weight vector is multiplied by the original deep features channel by channel to generate the recalibrated output features. This process effectively distinguishes the importance of different channels, strengthens the response of target-related channels in deep features, and weakens redundant features, thereby further optimizing the expression of deep features. Through this improvement, the present invention can maintain high detection accuracy and robustness even under low contrast and complex background conditions.
[0015] Step 3.4: Introduce a lightweight Transformer-Encoder into the high-level feature output; the standard self-attention in the Transformer-Encoder is calculated as follows: Where Q, K, and V represent the query matrix, key matrix, and value matrix obtained by linear mapping of the input features, respectively. The dimension of the key vector is used to scale the similarity to avoid the problem of excessively small gradients or saturation in Softmax when the feature dimension is large. This is the activation function used to transform the similarity matrix into attention weights. The relevance calculation between the query and the key is represented, and the final output is a weighted value matrix V, whose weights are obtained by adaptive learning through the attention mechanism. Through the above self-attention mechanism, the Transformer-Encoder can build long-distance dependencies in the global scope, enabling features from different spatial regions to achieve cross-regional association. This is beneficial for extracting global information that is difficult to capture by local convolution in the overall diffusion trend and dynamic morphological changes of gas plumes, thereby improving the robustness and accuracy of subsequent detection. Step 3.5: Based on the improvements described in steps 3.1 to 3.4, replace the network structure in the model configuration file and adjust the code implementation accordingly. Specifically, in the model configuration file yolov11s.yaml, set the backbone network to RepVGG, configure the neck structure to BiFPN-PAN and replace the upsampling operator with CARAFE, insert CBAM and SE modules in the shallow and deep layers respectively, and add a lightweight Transformer Encoder to the high-level feature branches. At the same time, modify the inference and training call scripts accordingly to ensure that the improved yolov11s network structure remains consistent during the training and inference phases. Step 3.6: Perform iterative training based on the improved network structure to obtain the optimal detection model; After modifying the network structure, the preprocessed and partitioned gas leak dataset from step 2 is input into the improved YOLOv11s network for iterative training. During training, a joint loss function is used to optimize the network. The joint loss function is defined as follows: in , and These are the weight coefficients for classification loss, bounding box loss, and distributed focus loss, respectively, and their values are adaptively adjusted based on the characteristics of the training set and the performance of the validation set. Classification loss measures the difference between the predicted class probability and the true class probability, and is defined as: in, This is the true label for category c (value 0 or 1). The class probability predicted by the network; To ensure that the classification branch can balance class discrimination ability and foreground confidence estimation, this invention comprehensively considers classification accuracy, bounding box regression accuracy, and distributed focus loss in the classification loss term. Simultaneously, a Scylla-IoU (Sylla-IoU) loss function is specifically introduced in the bounding box regression part to more accurately describe the angle deviation, distance difference, and shape difference between the predicted bounding box and the ground truth bounding box. The bounding box regression loss is defined as: in, SIoU loss represents the overlap between the predicted bounding box and the ground truth bounding box. This represents the penalty for distance from the center point. The difference in aspect ratio between the constrained predicted bounding box and the ground truth bounding box. Used to penalize the angular offset between the predicted bounding box and the ground truth bounding box; Furthermore, to further improve the fine-grained quality of bounding box regression, this invention introduces Distributed Focal Loss (DFL) into the loss function to constrain the discrete distribution of bounding box positions, thereby improving the continuity and stability of the localization regression. Its definition is: in Represents the discrete probability of the true location distribution. This represents the probability distribution of the corresponding location predicted by the network. Step 3.7: After training is complete and the optimal model is obtained, the network is exported and optimized for inference. This includes compressing model parameters to reduce storage and computational overhead, and using the exponential moving average (EMA) method to smoothly update the weights to improve the model's stability during inference. The final generated model file can be directly deployed in industrial sites to achieve real-time detection and alarm for gas leaks.
[0016] In step 3.4, the SE module calculation formula is as follows: That is, the pixel value at position (i, j) under each channel C exist The channel expression is obtained by averaging within the range. Subsequently, the channel description vectors are sequentially input into two fully connected layers, and their weight matrices are denoted as follows: and And then passed through the ReLU activation function. With Sigmoid activation function To obtain the channel attention weight vector s, the weight vector is then multiplied channel by channel with the original feature map F to obtain the recalibrated feature map F'.
[0017] Step 4 specifically involves: To simultaneously measure the overall performance of the detection box in terms of confidence and localization quality, a comprehensive scoring function is introduced. The definition is as follows: Where b represents the candidate detection box; The confidence level of the category corresponding to the detection box; This is the intersection-union ratio (IoU) between the detected bounding box and the actual labeled bounding box. and The non-negative weighting coefficients are used to adjust the relative contributions of the confidence index and the positioning accuracy index to the overall score. This scoring function enables a quantitative evaluation of the candidate box quality, thereby increasing the retention probability of high-quality detection boxes and enhancing overall detection stability and reliability during subsequent box selection and ranking. Furthermore, to ensure that enhancement processing is triggered only in regions with significant structural differences, while remaining silent in low-contrast background regions, a local contrast gating function C is constructed in one step, defined as follows: in, This represents the average brightness value within the ROI region. This represents the average brightness value of the background area. A small constant introduced to avoid a zero denominator. The threshold for determining local contrast; when the local contrast satisfies When the system determines that the region has sufficient brightness difference, it can be allowed to enter the subsequent enhancement, weighting or gating calculation; if the condition is not met, its participation in enhancement is suppressed to avoid noise amplification or pseudo texture generation; through this gating strategy, the present invention can effectively suppress background disturbance while ensuring the saliency of the plume structure, and improve the robustness and reliability of the enhancement algorithm.
[0018] To facilitate an objective and quantitative evaluation of the detection performance of this invention, the performance of the algorithm in this paper is evaluated using average precision (AP) and frames per second (FPS) as evaluation metrics. Precision (P) reflects the proportion of true targets in all detection results of an algorithm, and is used to measure the accuracy of the model's prediction results. It is defined as: Wherein, TP represents the number of true positives and FP represents the number of false positives; Recall (R) is used to characterize the model's ability to detect target instances, and is defined as: FN represents the number of false negatives, and a higher R indicates a lower false negative rate. Average Precision (AP) is used to comprehensively measure the recognition stability of a model under different threshold conditions. It is defined as the area of the integral of the P-R curve over the interval [0, 1]. Where P(R) represents the precision value corresponding to a given recall R, and the larger the AP value, the better the detection performance; Frames Per Second (FPS) is used to measure the real-time processing capability of a model, and is defined as: in, The FPS value represents the number of image frames that complete inference within the time interval T. A higher FPS value indicates that the model runs faster.
[0019] The beneficial effects of this invention are: (1) By performing non-uniformity correction, Gamma transformation, CLAHE enhancement, and temporal difference on the input image, the detection challenges of low contrast and weak texture of gas plumes are significantly improved. Among them, non-uniformity correction can compensate for the brightness distortion caused by the inconsistent response of the detector during infrared imaging, Gamma transformation improves the visibility of weak gas plumes by nonlinearly stretching the dark area, and CLAHE adaptive histogram equalization enhances texture details in local areas without introducing excessive noise. At the same time, temporal difference can utilize the brightness changes between adjacent frames to highlight the dynamic characteristics of leaking plumes and suppress static background interference. The synergistic effect of the above preprocessing operations enhances the saliency of gas plumes in low contrast and weak texture scenes, providing clearer and more discriminative input features for subsequent detection networks. (2) The introduction of the RepVGG backbone network and the BiFPN-PAN+CARAFE fusion structure not only ensures the feature extraction capability, but also enhances the detection performance of small target plumes under multi-scale conditions. Among them, RepVGG maintains the expressive capability of multi-branch convolution during the training stage through structural reparameterization, and folds into a single-branch structure during the inference stage, thereby enhancing the nonlinear expressive capability of the backbone network without increasing the inference overhead. BiFPN-PAN, through a learnable bidirectional cross-layer feature fusion method, enables features of different scales to interact repeatedly between multiple levels, significantly improving the feature aggregation effect of the model under multi-scale gas plume targets. At the same time, CARAFE, as a lightweight upsampling operator, reconstructs the region to be upsampled in a content-aware manner, effectively improving the recovery capability of shallow details and edge textures. (3) CBAM and SE modules are embedded in the shallow and deep layers respectively, and Transformer Encoder is added in the high layer, which effectively improves the robustness and modeling ability of complex backgrounds and dynamic diffusion plumes. (4) By using the SIoU loss function combined with the EMA strategy, the training convergence speed and bounding box prediction accuracy are significantly improved while ensuring detection accuracy. Attached Figure Description
[0020] Figure 1 This is the overall flowchart of the gas leak detection model.
[0021] Figure 2 A schematic diagram of the improved YOLOv11s network structure.
[0022] Figure 3 This is a schematic diagram of the RepVGG module structure.
[0023] Figure 4 This is a schematic diagram of the CBAM module structure.
[0024] Figure 5 This is a schematic diagram of the SE module structure.
[0025] Figure 6 This is a schematic diagram of the lightweight Transformer Encoder structure.
[0026] Figure 7 The image shows the simulation results. Detailed Implementation
[0027] The present invention will now be described in further detail with reference to the accompanying drawings.
[0028] A gas leak detection method based on an improved YOLOv11s framework includes the following steps: Step 1: In a typical industrial scenario, video data of a gas leak was acquired using a cooled infrared thermal imager. The acquired video frame rate was 50 fps, and the resolution was 640×512. To facilitate supervised learning, valid frames were selected from the acquired videos, and the plume region was labeled using a manual annotation tool to construct a dataset containing gas leak categories. The dataset was divided into training, validation, and test sets in an 8:1:1 ratio.
[0029] Step 2: Perform systematic preprocessing on the collected data.
[0030] First, non-uniformity correction (NUC) is performed, followed by quantile cropping normalization to balance the image grayscale distribution. Gamma transformation is then used to enhance overall contrast, and CLAHE (contrast-limited adaptive histogram equalization) is employed to enhance local details. To highlight the dynamic characteristics of the gas plume, a three-frame difference is used to construct the input sequence for consecutive frames, strengthening temporal information and enabling the network to capture the plume's diffusion and flow processes. These steps effectively improve the quality and contrast of the input image, providing reliable input for subsequent detection.
[0031] Step 3: Improve the network structure of the YOLOv11s algorithm. This mainly includes using RepVGG as the backbone network, introducing a BiFPN-PAN cross-layer bidirectional fusion structure in the neck layer and combining it with the CARAFE upsampling operator to improve the multi-scale feature fusion capability, embedding the CBAM attention module in the shallow layer and the SE module in the deep layer, and introducing a lightweight Transformer Encoder in the high-level features to enhance the global modeling capability. At the same time, in the bounding box prediction part, the SIoU loss function is used to replace the original CIoU loss function to improve the regression accuracy and convergence speed. Then, the divided dataset is input into the improved YOLOv11s network for iterative training.
[0032] Step 2 specifically involves... To eliminate fixed-pattern noise and pixel response differences in the infrared detector, NUC correction is performed on the input video frame pixel values I(x, y). The correction model is as follows: Where D(x, y) is the dark field response, F(x, y) is the flat field response, and M is the gain coefficient; To suppress the impact of extreme brightness values caused by clouds, ground reflections, or noise on the dynamic range, while ensuring consistent brightness scale in subsequent inputs, the corrected image undergoes quantization and normalization processing; assuming... These are the low and high quantile rates, with the corresponding upper and lower quantile points as follows: The pixels are cropped using this interval, limiting the pixel values to within this interval. The pixel values after the upper and lower quantile point limiting processing are denoted as... Its cutting formula is This formula is applied to pixels first. Raise all abnormal dark values below the lower quantile to this lower bound, and then... All abnormal brightness values exceeding the upper boundary are suppressed to the upper limit, achieving bidirectional amplitude limiting; thereby suppressing extreme noise while preserving effective structural information, making the image brightness distribution stable and suitable for subsequent enhancement processing; the amplitude-limited image is further processed according to... Mapped to the range [0, 1] to obtain a uniform brightness scale, denoted as Subsequently, to enhance the visibility of weak-contrast regions in the gas plume, a Gamma transformation was applied to the normalized image, ensuring the output satisfies: in For exponential adjustment parameters, This enhances shadow detail and improves the perceived contrast of feather boundaries. To further enhance local detail and texture, contrast-limited adaptive histogram equalization (CLAHE) is performed on the Gamma-transformed image, using local windows to accumulate histograms. Perform remapping to make the enhanced image satisfy: Where M and N are the local window sizes, and L is the number of gray levels. The minimum cumulative value is non-zero; to highlight the temporal changes of the plume in the MWIR sequence, such as diffusion, drift, and turbulence, a three-frame difference sequence is constructed based on the enhanced image: This enables the network to gain stronger motion sensitivity; finally, all preprocessed sequence data are divided into training, validation and test sets in an 8:1:1 ratio.
[0033] Furthermore, in step 3, the specific operation of the detection algorithm includes the following steps: Step 3.1: In the detection method of the present invention, the gas leak image after data preprocessing is first input into the backbone network for preliminary feature extraction.
[0034] After replacing the backbone network from CSPDarkNet to RepVGG and adopting a multi-branch convolutional structure during the training phase to enhance feature representation capabilities, this invention folds the multi-branch convolution into a single 3×3 convolutional kernel through structural reparameterization, significantly simplifying the network structure during the inference phase. Simultaneously, because the RepVGG backbone introduces convolutional branches and attention structures with different receptive fields in the shallow, middle, and deep layers, the network can extract multi-scale feature maps containing detailed textures, mid-scale structures, and high semantic information at multiple scales during the training phase, providing a richer feature foundation for subsequent detection heads. Unlike the traditional CSPDarkNet backbone, this invention introduces a RepVGG structure. This structure employs multi-branch residual convolutions during training to extract richer semantic and spatial features, while in the inference phase, it achieves network lightweighting by folding multi-branch convolutions into single-branch convolutions through reparameterization. Its advantage lies in significantly reducing computational overhead and inference latency without compromising detection accuracy, thus ensuring the real-time performance of gas leak detection tasks.
[0035] Step 3.2: Introduce a BiFPN-PAN fusion structure in the neck layer and use the CARAFE operator as the upsampling method to achieve efficient aggregation and fine-grained enhancement of multi-scale features output by the backbone network; unlike the commonly used Spatial Pyramid Pooling with Hollows (ASPP) or Fast Spatial Pyramid Pooling (SPPF) in the traditional YOLO series, this invention replaces them with a BiFPN-PAN fusion structure to achieve more efficient multi-scale feature aggregation; The multi-scale features output by the backbone network in step 3.1 are first input to the neck layer. Features from different levels interact through the bidirectional path of BiFPN, which includes both top-down high semantic transmission and bottom-up detail compensation. In the detection method of this invention, the multi-scale features output by the backbone network are fed into the neck layer for fusion. This invention introduces a BiFPN-PAN fusion structure in the neck layer and uses the CARAFE upsampling operator instead of conventional nearest-neighbor interpolation or deconvolution to improve the accuracy and fine-grained expression of feature aggregation. Specifically, feature maps from deeper layers are channel-aligned and then upsampled using the CARAFE operator to generate smooth and sharp-edged high-resolution feature maps, which are then weighted and fused with mid-layer features. Subsequently, the mid-layer features are upsampled again using CARAFE and fused with shallow features, achieving top-down information transfer. Simultaneously, the bottom-up path of BiFPN progressively transfers shallow detail information to higher-level semantic features, enabling bidirectional interaction with deep features. In this way, the network can adaptively emphasize effective branches and suppress redundant information, thereby obtaining higher-quality feature maps under multi-scale conditions. Finally, the fused features output by the neck layer retain both shallow details and deep semantics, exhibiting better robustness in feather edge and small target detection.
[0036] Step 3.3: In shallow feature processing, this invention introduces the CBAM module, which consists of Channel Attention (CAM) and Spatial Attention (SAM). This module can simultaneously weight and adjust features in both channel and spatial dimensions. First, the feature map of the future autonomous backpropagation network's shallow layers is input into CAM. Channel description vectors are generated through max pooling and average pooling, respectively, and then channel weight vectors are obtained through a multilayer perceptron and sigmoid activation. These weight vectors are then multiplied channel-by-channel with the input features to obtain the weighted features. Subsequently, the weighted features are input into SAM, where max pooling and average pooling operations are performed in the spatial dimension, and the vectors are concatenated in the channel dimension. After convolution and sigmoid activation, a spatial weight map is obtained, which is then multiplied with the weighted features to output the spatially attention-optimized features. This process enables the network to adaptively highlight key details in potential gas leak areas and suppress background noise interference. In deep feature processing, this invention introduces the SE module. In the future, the feature maps of the deep layers of the autonomous backbone network are input to the SE module. First, channel description vectors are obtained through global average pooling. Then, they are input to two fully connected layers, first activated by ReLU and then by Sigmoid, to obtain channel weight vectors. Finally, the channel weight vectors are multiplied channel by channel with the original deep features to generate recalibrated output features. This process can effectively distinguish the importance of different channels, strengthen the channel responses related to the target in the deep features, and weaken redundant features, thereby further optimizing the expression of deep features. Through this improvement, the present invention can maintain high detection accuracy and robustness under low contrast and complex background conditions.
[0037] Step 3.4: Traditional convolutional neural networks often lack the ability to model global dependencies when dealing with targets with diffusion characteristics, such as gas plumes, due to the limitation of local receptive fields.
[0038] To this end, in order to inherit the multi-scale semantic features generated by the backbone network in step 3.1 and further enhance the global expressive power of the high-level features obtained after BiFPN-PAN fusion in step 3.2, this invention introduces a lightweight Transformer-Encoder in the high-level feature output. This module uses a multi-head self-attention mechanism to capture long-distance dependencies between features in different spatial regions globally, making up for the limitations of convolutional structures in modeling global correlations. This enables the high-level features to not only have the multi-scale semantic fusion capability provided by BiFPN-PAN, but also the global contextual understanding capability across regions. Combined with the support of the aforementioned RepVGG backbone, BiFPN-PAN fusion structure and attention mechanism, the Transformer-Encoder further enhances the model's ability to represent the overall diffusion trend, dynamic morphological changes and weak boundaries of gas plumes, ensuring that the model can still maintain high detection accuracy and stability in industrial scenarios with large scale and complex backgrounds. The standard self-attention calculation in the Transformer-Encoder is as follows: Where Q, K, and V represent the query matrix, key matrix, and value matrix obtained by linear mapping of the input features, respectively. The dimension of the key vector is used to scale the similarity to avoid the problem of excessively small gradients or saturation in Softmax when the feature dimension is large. This is the activation function used to transform the similarity matrix into attention weights. The relevance calculation between the query and the key is represented, and the final output is a weighted value matrix V, whose weights are obtained by adaptive learning through the attention mechanism. Through the above self-attention mechanism, the Transformer-Encoder can build long-distance dependencies in the global scope, enabling features from different spatial regions to achieve cross-regional association. This is beneficial for extracting global information that is difficult to capture by local convolution in the overall diffusion trend and dynamic morphological changes of gas plumes, thereby improving the robustness and accuracy of subsequent detection. Step 3.5: Based on the improvements described in steps 3.1 to 3.4, replace the network structure in the model configuration file and adjust the code implementation accordingly. Specifically, in the model configuration file yolov11s.yaml, set the backbone network to RepVGG, configure the neck structure to BiFPN-PAN and replace the upsampling operator with CARAFE, insert CBAM and SE modules in the shallow and deep layers respectively, and add a lightweight Transformer Encoder to the high-level feature branches. At the same time, modify the inference and training call scripts accordingly to ensure that the improved yolov11s network structure remains consistent during the training and inference phases.
[0039] Step 3.6: After modifying the network structure, the preprocessed and segmented gas leak dataset from Step 2 is input into the improved YOLOv11s network for iterative training. During training, a joint loss function is used to optimize the network, comprehensively considering classification accuracy, bounding box regression accuracy, and distributed focus loss. Specifically, the SIoU loss function is introduced in the bounding box regression part. Compared to traditional CIoU, SIoU additionally introduces angle and shape losses, which can more comprehensively characterize the difference between the predicted and ground truth boxes. Through continuous iteration and parameter tuning, the optimal model weights that can stably identify gas leak areas and accurately output detection boxes and categories are finally obtained.
[0040] Step 3.7: After training is complete and the optimal model is obtained, the network is exported and optimized for inference. This includes compressing model parameters to reduce storage and computational overhead, and using the exponential moving average (EMA) method to smoothly update the weights to improve the model's stability during inference. The final generated model file can be directly deployed in industrial sites to achieve real-time detection and alarm for gas leaks.
[0041] Step 4: Input the image or video frame to be detected into the optimal model. The network outputs the detection box, category, and confidence score. An augmented box filtering mechanism is introduced during the inference stage. The candidate boxes are screened by comprehensively considering confidence score, IoU, target size, local contrast gating, and temporal consistency constraints. Redundant or erroneous predictions are eliminated to obtain the final stable detection result.
[0042] Step 5: Evaluate the performance of the proposed algorithm using Average Precision (AP) and Frames Per Second (FPS) as evaluation metrics. A PR curve is constructed with Recall (R) on the horizontal axis and Precision (P) on the vertical axis. AP, the area under the PR curve, represents the average precision of all detection results within the same category. FPS is an important metric for evaluating model performance; a higher FPS value indicates a faster model execution speed.
[0043] like Figure 1 As shown, this workflow demonstrates the entire process from preprocessing steps such as acquiring raw gas leak images, NUC correction, Gamma correction, CLAHE enhancement, and temporal difference, to building an improved YOLOv11 model based on the RepVGG backbone network, BiFPN-PAN fusion structure, CARAFE upsampling, attention mechanism, and lightweight Transformer; and combining SIoU loss, EMA, and other strategies to complete training and optimization, ultimately obtaining a robust gas leak detection model.
[0044] like Figure 2 As shown, the model of this invention consists of a RepVGG backbone, a BiFPN feature fusion layer, and a PAN downsampling structure. It introduces DSASPP to capture multi-scale information, uses CARAFE to improve upsampling reconstruction capability, and integrates CBAM, SE, and a lightweight Transformer to enhance the interaction between global and local features. Finally, a three-scale detection head is formed to improve the detection performance of weak texture and low-contrast gas plumes.
[0045] like Figure 3As shown, the RepVGG module has a multi-branch structure during the training phase, including a 3×3 convolution branch, a 1×1 convolution branch, and an identity mapping branch. Each branch uses the non-linear activation function ReLU, enabling the network to learn richer and more diverse feature representations during the training phase.
[0046] like Figure 4 As shown, this module consists of two sub-modules: Channel Attention and Spatial Attention. The input features first pass through the Channel Attention module, where global average pooling and max pooling extract cross-channel response weights, and channel-wise weighting enhances important features. Subsequently, the features pass through the Spatial Attention module, where max pooling and average pooling in the spatial dimension jointly extract spatial saliency information, enhancing the saliency of local regions in the feature map. The final Refined Feature output integrates saliency attention from both channel and spatial dimensions, significantly improving the discriminability of gas plume structural details and weakly textured regions.
[0047] like Figure 5 As shown, this module first performs global average pooling on the input features in the spatial dimension to obtain a 1×1×C channel description vector. Then, it extracts channel weights sequentially through two fully connected layers (FC), ReLU activation, and Sigmoid activation. Finally, the generated channel weight vector is multiplied by the input features channel by channel, thereby strengthening key channels and suppressing redundant channels. This structure effectively improves the network's sensitivity to differences in bright and dark regions of the gas plume, enhancing detection contrast and stability.
[0048] like Figure 6 As shown, the lightweight Transformer Encoder structure first flattens and linearly projects the input features, then sequentially passes them through LayerNorm, a lightweight multi-head self-attention mechanism, and residual connections to capture long-distance dependencies across regions. It then passes through a second LayerNorm and a feedforward network with residual connections to achieve global modeling of multi-scale features. This module effectively improves the structural consistency and detectability of weak target plumes in large-scene backgrounds.
[0049] Figure 7The simulation results of this invention are shown in the figure. This invention relates to the field of computer vision and industrial safety detection technology, and proposes a gas leak detection method based on an improved YOLOv11s framework. This method first performs non-uniformity correction, Gamma transformation, and CLAHE enhancement on mid-wave infrared acquired images, and combines three-frame difference to construct temporal features to improve the visibility of gas plumes against low-contrast backgrounds. In terms of network structure, RepVGG is used as the backbone network, and BiFPN-PAN fusion and CARAFE upsampling are introduced to achieve efficient interaction of multi-scale features. CBAM and SE attention mechanisms are embedded in the shallow and deep layers respectively, and a lightweight Transformer Encoder is added in the high-level layers to enhance global feature modeling capabilities. Regarding the loss function, this invention uses joint optimization of classification loss and SIoU to improve the precision and convergence speed of bounding box prediction; during the inference stage, an enhanced box filtering mechanism effectively reduces false detections and false negatives. This method balances detection accuracy, speed, and model lightweighting, meeting the real-time and stability requirements of gas leak detection in industrial settings, and providing technical support for its deployment in hardware devices.
Claims
1. A mid-wave infrared gas leak detection method based on an improved YOLOv11s, characterized in that, Includes the following steps; Step 1: Collect gas leak video data, filter out valid video frames, and then manually annotate them using the darklabel tool; Step 2: Preprocess the acquired video frames before training; Step 3: Improve the YOLO11s algorithm network structure, and then input the preprocessed dataset from Step 2 into the improved YOLO11s network for iterative training. Optimize using a joint loss function, and combine cosine annealing learning rate scheduling and exponential moving average (EMA) method to improve convergence performance and obtain the optimal model parameters for subsequent leak detection inference. Step 4: After training, input the image or video frame to be detected into the optimal model and output the detection box, category and confidence of the gas leak area; introduce an enhanced box filtering mechanism in the inference stage, and screen candidate boxes by combining confidence, IoU, target size, local contrast gating and time consistency constraints, and finally obtain the detection result by non-maximum suppression (NMS).
2. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 1, characterized in that, Step 1 involves acquiring mid-wave infrared images or video frames using a cooled infrared thermal imager, filtering out valid frames, labeling them, and constructing a single-class dataset containing only gas leaks; and obtaining image or video sequences of gas leak scenarios.
3. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 1, characterized in that, Step 2 specifically involves... The NUC correction is performed on the input video frame pixel value I(x,y), and the correction model is as follows: Where D(x, y) is the dark field response, F(x, y) is the flat field response, and M is the gain coefficient; Perform quantization and normalization on the corrected image; set up These are the low and high quantile rates, with the corresponding upper and lower quantile points as follows: The pixels are cropped using this interval, limiting the pixel values to within this interval. The pixel values after the upper and lower quantile point limiting processing are denoted as... Its cutting formula is: This formula is applied to pixels first. This raises all abnormal dark values below the lower quantile to that lower bound, and then... All abnormal brightness values exceeding the upper boundary are suppressed to the upper limit to achieve bidirectional amplitude limiting; the amplitude-limited image is further processed according to... Mapped to the range [0, 1] to obtain a uniform brightness scale, denoted as Apply a Gamma transform to the normalized image so that the output satisfies: in As the exponential adjustment parameter, contrast-limited adaptive histogram equalization is performed on the Gamma-transformed image, using a local window to accumulate the histogram. Perform remapping to make the enhanced image satisfy: Where M and N are the local window sizes, and L is the number of gray levels. The minimum non-zero cumulative value; construct a three-frame difference sequence based on the enhanced image: This enables the network to gain stronger motion sensitivity; finally, all preprocessed sequence data are divided into training set, validation set and test set.
4. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 3, characterized in that, In step 3, the improved yolov11s algorithm network structure uses RepVGG as the backbone network; a BiFPN-PAN cross-layer bidirectional feature fusion structure is introduced in the neck, and upsampling is CARAFE, so as to achieve efficient aggregation and fine-grained reconstruction of features at different levels.
5. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 4, characterized in that, The specific operation of the detection algorithm includes the following steps: Step 3.1: The gas leak image after data preprocessing is first input into the backbone network for preliminary feature extraction; The reparameterized RepVGG backbone network outputs multi-scale feature maps at different depths simultaneously. Step 3.2: Introduce a BiFPN-PAN fusion structure into the neck layer and use the CARAFE operator as the upsampling method; the multi-scale features output by the backbone network are fed into the neck layer for fusion; using the BiFPN-PAN fusion structure, the fusion formula is: Where A(·) represents the alignment operator, used to perform upsampling, downsampling, and channel alignment operations. For learnable weights, It is a numerically stable term; Step 3.3: In shallow feature processing, the CBAM module is introduced. First, the shallow multi-scale features extracted from the backbone network in Step 3.1 are input into CAM. Channel description vectors are generated by max pooling and average pooling respectively, and channel weight vectors are obtained by multilayer perceptron and sigmoid activation. Then, these weight vectors are multiplied with the input features channel by channel to obtain the weighted features. Subsequently, the weighted features are input into SAM, where max pooling and average pooling operations are performed in the spatial dimension, and the data is concatenated in the channel dimension. After convolution and sigmoid activation, a spatial weight map is obtained, which is then multiplied with the weighted features to output the spatial attention-optimized features. In deep feature processing, an SE module is introduced. The deep multi-scale features extracted from the backbone network in step 3.1 are input into the SE module. First, the channel description vector is obtained by global average pooling. Then, it is input into two fully connected layers, which are activated by ReLU and then by Sigmoid to obtain the channel weight vector. Finally, the channel weight vector is multiplied with the original deep features channel by channel to generate the recalibrated output features. Step 3.4: Introduce a lightweight Transformer-Encoder into the high-level feature output; The standard self-attention calculation in the Transformer-Encoder is as follows: Where Q, K, and V represent the query matrix, key matrix, and value matrix obtained by linear mapping of the input features, respectively. is the dimension of the key vector, used to scale the similarity. This is the activation function used to transform the similarity matrix into attention weights. This represents the calculation of the relevance between the query and the key, and the final output is a weighted value matrix V, whose weights are obtained through adaptive learning by an attention mechanism. Step 3.5: Based on the improvements described in steps 3.1 to 3.4, in the model configuration file yolov11s.yaml, the backbone network is set to RepVGG, the neck structure is configured as BiFPN-PAN and the upsampling operator is selected as CARAFE, CBAM and SE modules are inserted into the shallow and deep layers respectively, and a lightweight Transformer Encoder is added to the high-level feature branches; at the same time, the inference and training call scripts are modified accordingly to ensure that the improved yolov11s network structure remains consistent during the training and inference stages. Step 3.6: Perform iterative training based on the improved network structure to obtain the optimal detection model; Step 3.7: After training is completed and the optimal model is obtained, the network is exported and optimized for inference. This includes compressing the model parameters to reduce storage and computational overhead, and using the exponential moving average (EMA) method to smoothly update the weights. The final generated model file is directly deployed to the industrial site to achieve real-time detection and alarm of gas leaks.
6. The method for detecting gas leaks using mid-wave infrared based on an improved YOLOv11s according to claim 5, characterized in that, In step 3.2, during the upsampling stage, the CARAFE operator is used to weight the neighborhood features using a content-related recombination kernel, thereby obtaining a high-resolution feature map. in Let N be the upsampling kernel predicted at position (u, v), and let N be the local neighborhood.
7. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 5, characterized in that, In step 3.3, the CBAM spatial attention formula is as follows: Wherein, the input feature map F represents a size of The three-dimensional tensor is given by H, where H is the feature map height, W is the width, and C is the number of channels; the global average pooling and global max pooling operations in the spatial domain are respectively expressed as: and The results obtained are processed in the CBAM module via a size of Convolution operator Further processing, and using the Sigmoid function. Mapped to the [0, 1] interval to generate a spatial attention weight map .
8. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 5, characterized in that, In step 3.4, the SE module calculation formula is as follows: That is, the pixel value at position (i, j) under each channel C exist The channel expression is obtained by averaging within the range. ; Subsequently, the channel description vectors are sequentially input into two fully connected layers, and their weight matrices are denoted as follows: and And then passed through the ReLU activation function. With Sigmoid activation function To obtain the channel attention weight vector s, the weight vector is then multiplied channel by channel with the original feature map F to obtain the recalibrated feature map F'.
9. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 5, characterized in that, Step 3.6 specifically involves: After modifying the network structure, the preprocessed and partitioned gas leak dataset from step 2 is input into the improved YOLOv11s network for iterative training. During training, a joint loss function is used to optimize the network. The joint loss function is defined as follows: in , and These are the weight coefficients for classification loss, bounding box loss, and distributed focus loss, respectively, and their values are adaptively adjusted based on the characteristics of the training set and the performance of the validation set. Classification loss measures the difference between the predicted class probability and the true class probability, and is defined as: in, This is the true label for category c (value 0 or 1). The class probability predicted by the network; The classification loss term comprehensively considers classification accuracy, bounding box regression accuracy, and distributed focus loss; simultaneously, a SIoU (Scylla-IoU) loss function is specifically introduced in the bounding box regression part, and the bounding box regression loss is defined as: in, SIoU loss represents the overlap between the predicted bounding box and the ground truth bounding box. This represents the penalty for distance from the center point. The difference in aspect ratio between the constrained predicted bounding box and the ground truth bounding box. Used to penalize the angular offset between the predicted bounding box and the ground truth bounding box; The Distributed Focus Loss (DFL) is introduced into the loss function to constrain the discrete distribution of the bounding box locations, thereby improving the continuity and stability of the localization regression. Its definition is: in Represents the discrete probability of the true location distribution. This represents the probability distribution of the corresponding location predicted by the network.
10. The method for detecting gas leaks using mid-wave infrared radiation based on an improved YOLOv11s according to claim 5, characterized in that, Step 4 specifically involves: Introducing a comprehensive scoring function Simultaneously, it measures the overall performance of the detection box in terms of confidence and localization quality, defined as follows: Where b represents the candidate detection box; The confidence level of the category corresponding to the detection box; This is the intersection-union ratio (IoU) between the detected bounding box and the actual labeled bounding box. and The non-negative weighting coefficients are used to adjust the relative contributions of the confidence index and the positioning accuracy index to the overall score; a local contrast gating function C is constructed, defined as follows: in, This represents the average brightness value within the ROI region. This represents the average brightness value of the background area. A small constant introduced to avoid a zero denominator. This is the threshold for determining local contrast. When the local contrast satisfies When the system determines that the region has sufficient brightness difference, it allows it to proceed to subsequent enhancement, weighting, or gating calculations; if the condition is not met, it suppresses the region from participating in enhancement to avoid noise amplification or pseudo-texture generation.