Oil and gas pipeline infrared small target night patrol method based on cross fusion attention
By optimizing the YOLOv8 network through cross-fusion attention, the problem of poor small target detection in UAV infrared detection is solved, achieving high-precision and efficient detection in complex backgrounds, which is suitable for nighttime inspection of oil and gas pipelines.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-18
- Publication Date
- 2026-04-03
AI Technical Summary
Existing UAV infrared detection algorithms suffer from problems such as weak small target feature information, background noise masking, image defocusing and blurring, high computational cost, and difficulty in balancing detection accuracy and efficiency in nighttime inspections of oil and gas pipelines. In particular, the detection effect of small targets is poor in complex backgrounds.
We adopt a cross-fusion attention-based approach, which optimizes the YOLOv8 network through cross-layer scale verification, dynamic weight calculation, CBAM attention mechanism and multi-scale feature fusion, enhances the robustness of small target feature extraction and detection, and builds an end-to-end efficient detection network.
It significantly reduces the false negative and false positive rates for small targets, improves detection accuracy and robustness in complex environments, and meets the high efficiency and reliability requirements for nighttime inspections of oil and gas pipelines.
Smart Images

Figure CN121789083A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of UAV visual inspection, and specifically relates to a night inspection method for small infrared targets in oil and gas pipelines based on cross-fusion attention. Background Technology
[0002] Currently, my country's oil and gas pipeline network continues to expand. As a core hub for energy transportation, its safe operation is directly related to the stability of the national economy and the guarantee of public safety. However, frequent safety threats such as nighttime unauthorized drilling for oil theft and accidental contact during mechanical construction have created an urgent need for real-time, high-precision detection of suspicious targets along the pipeline route, making it crucial for solidifying hidden danger investigation and strengthening risk management. With the deep integration of drone technology and infrared imaging technology, infrared target detection based on drone aerial photography has become the mainstream solution for nighttime inspection of oil and gas pipelines. This technology relies on the night vision characteristics of infrared cameras to overcome the limitations of low-light environments and achieve large-scale, rapid monitoring along the pipeline. However, in actual high-altitude night patrol scenarios, traditional infrared detection algorithms face multiple technical bottlenecks: First, infrared images themselves have a narrow dynamic range and blurred target outline details; the feature information of small targets (such as personnel and small machinery) is weak and easily masked by background noise. Second, when drones fly at high altitudes, airflow disturbances easily cause image defocusing and motion blur, and the complex terrain along the pipeline (such as vegetation obstruction and undulating terrain) results in severe background interference, further weakening the distinction between small targets and the background. Third, existing algorithms struggle to balance detection accuracy and computational efficiency—pursuing high accuracy results in a large number of model parameters and high computational costs, making it difficult to adapt to the computing power limitations of embedded drone devices; using lightweight models leads to increased positioning deviations and higher false negative rates, failing to meet real-time inspection requirements. Furthermore, traditional spatial pyramid pooling modules lack scale adaptability for small infrared targets when performing multi-scale feature fusion; the application of attention mechanisms often suffers from problems such as fragmented extraction of channel and spatial features and computational redundancy, further restricting the effective capture of small target features. These technical pain points result in poor adaptability of existing algorithms in UAV high-altitude night patrol scenarios, making it difficult to meet the high-precision detection requirements at night, in low light, or under complex backgrounds. There is an urgent need to overcome these bottlenecks through technological innovation to provide a more efficient and reliable solution for nighttime inspection of oil and gas pipelines. Summary of the Invention
[0003] This application provides a night inspection method for small infrared targets in oil and gas pipelines based on cross-fusion attention. Using YOLOv8 as a baseline, through multi-module collaborative optimization, it significantly enhances the feature extraction capability and detection robustness of UAVs for small infrared targets in harsh environments such as low light and complex terrain at night, and significantly reduces the false detection rate and false detection rate of small targets, providing high-precision and high-reliability technical support for night inspection of oil and gas pipelines.
[0004] To achieve the above objectives, this application provides a night patrol method for small infrared targets in oil and gas pipelines based on cross-fusion attention, comprising the following steps: S1. Dynamically select the optimal feature layer for each target through the cross-layer scale verification unit, and calculate the mismatch compensation coefficient of the feature layer; S2. Extract target background features, flatten the background features into channel-dimensional feature vectors, calculate the probability distribution and background entropy of the channel dimensions, normalize the background entropy using the Sigmoid function, map it into context weights, and output background adaptation weights. S3. Calculate the basic weight and scale weight, and obtain the dynamic weight by fusing the mismatch compensation coefficient and background adaptation weight in multiple dimensions. Calculate the final loss value based on the basic positioning loss CIoU combined with the dynamic weight. The total positioning loss is obtained by combining the final loss value with the DFL loss and the dynamic weight. S4. The feature map is segmented using the CBAM attention mechanism to obtain spatial feature branches and channel feature branches. The spatial feature branches and channel feature branches are then processed to obtain spatial enhancement features and channel enhancement features. S5. The spatial modulation features are obtained by guiding spatial region localization through channel enhancement features. The channel modulation features are obtained by guiding semantic channel filtering through spatial enhancement features. The spatial modulation features and channel modulation features are fused to obtain the fused features. S6. First, perform convolution operation on the spatial feature branch and inherit the core operation of SPPF multi-scale pooling to form a multi-scale feature set. Perform channel concatenation and convolution on the multi-scale feature set to obtain multi-scale spatial features. Perform convolution and mapping on the channel feature branch and retain the target channel semantic statistical information to generate channel semantic features. S7. Perform target feature enhancement on the multi-scale spatial features and channel semantic features, and introduce bidirectional cross-modulation; S8. Introducing a multi-branch convolution reparameterization module and integrating a cross-attention adjustment module and a multi-scale feature enhancement module to construct an end-to-end efficient detection network for infrared scenes; S9. Based on the infrared scene, an end-to-end high-efficiency detection network is constructed, with the final loss value as the supervision strategy, to build an end-to-end training process.
[0005] In one embodiment, according to step S1, the optimal target scale range for each of the three feature layers of the feature pyramid in the YOLO algorithm is preset. For each foreground target, calculate the width, height, and area of its true bounding box. Combine the stride of each feature layer with the preset scale range to determine its scale adaptation score on different layers. Select the layer with the highest score as the optimal feature layer and calculate the mismatch compensation coefficient for the target on non-optimal layers accordingly to alleviate the positioning deviation caused by scale mismatch.
[0006] In one embodiment, according to step S2, the background features are the features of the target surrounding area extracted through a multi-layer feature map of a feature pyramid and by performing the RoIAlign operation. The probability distribution of the channel dimension The formula for calculating background entropy is shown below: ; In the formula, Represents the probability distribution along the channel dimension; The feature vector representing the channel dimension after the background features have been flattened; Indicates context weight; = .
[0007] In one embodiment, the background adaptation weight calculation formula is as follows: ; In the formula, This represents the background entropy normalization result, i.e., the output value of the Sigmoid function; This indicates the background adaptation weight.
[0008] In one embodiment, according to step S3, the basic weights are generated based on the target category score, and the scale weights are dynamically generated based on the target scale and the adaptability of the optimal feature layer; By integrating the base weights, scale weights, mismatch compensation coefficients, and context weights, the dynamic weights are obtained, and the calculation formula is shown below:
[0009] In the formula, Indicates dynamic weights; Indicates the basic weight; Indicates scale weight; Indicates the mismatch compensation coefficient; This indicates the context weight.
[0010] In one embodiment, the dynamic weights use CIoU loss as the base loss and combine it with the dynamic weights to calculate the final localization loss:
[0011] In the formula, This indicates the final location loss; The sum of the scores of all prospective objectives; Indicates the number of forward targets; The result is the calculated CIoU for the target.
[0012] In one embodiment, the total positioning loss is calculated using the following formula:
[0013] In the formula, This represents the total positioning loss; This represents the loss weight.
[0014] In one embodiment, according to step S4, a lightweight cross-fusion attention module (CFAM) is constructed based on the complementary mapping characteristics of the spatial feature branch and the channel feature branch and is embedded in the key feature layer of the network neck.
[0015] In one embodiment, according to step S5, the channel enhancement feature is used as a guiding signal to perform global average pooling and compression in the channel dimension to obtain statistical features that reflect the global distribution of spatial semantics. These features are then mapped to a channel attention weight map in the 0-1 interval by the Sigmoid activation function. The attention weight map is multiplied element-wise with the spatial enhancement feature to obtain the spatial modulation feature. The spatial enhancement features are used as guiding signals to perform global average pooling and global max pooling operations to obtain features reflecting the global semantic contribution of the channel and features reflecting the local target information of the channel. The two are fused and added as inputs and activated by Sigmoid to generate a spatial attention weight map. The spatial attention weight map is multiplied element-wise with the channel enhancement features to obtain the channel modulation features.
[0016] Compared with the prior art, the beneficial effects of this application are: 1. This invention starts by optimizing the loss calculation logic and proposes a dynamic weighting mechanism that fuses cross-layer scale verification and context awareness. This mechanism effectively avoids the problem of poor adaptability of fixed weights without requiring additional hardware or complex feature modules. While saving improvement costs, it guides the neural network to focus on correcting the localization deviation of small infrared targets and enhances robustness in interference scenarios through background complexity evaluation, providing a precise and efficient localization loss solution for small infrared target detection.
[0017] 2. The CFAM module of this invention achieves deep synergy between spatial and channel features through bidirectional cross-guided attention modulation. This module is adapted for deployment in a medium-resolution feature layer, which is the optimal range for matching the semantic information of small infrared targets with spatial resolution, maximizing the preservation of small target details and strengthening semantic associations. The processed features better match the information distribution characteristics of the target, effectively improving the target feature recognition in complex backgrounds.
[0018] 3. Traditional SPPF modules, due to their single-channel flow and fixed multi-scale pooling design, struggle to balance multi-scale coverage and feature discriminative power. The SPPF_CFAM module of this invention, while inheriting the advantages of multi-scale pooling, introduces a cross-attention mechanism to construct a mutual guidance logic between spatial and channel features, achieving feature collaboration. This module solves the problems of traditional SPPF lacking attention guidance and diluting spatial details of small targets, while also enhancing the distinction between targets and background, effectively compensating for the deficiencies of deep backbone features, and providing high-quality input for subsequent neck fusion. Its improved paradigm of multi-scale pooling and cross-attention fusion can be adapted to other scenarios requiring enhanced deep feature representation beyond infrared small target detection, and provides a reusable technical approach for optimizing similar modules.
[0019] 4. The efficient small target detection network constructed in this invention optimizes multi-scale fusion of the neck region by integrating a dynamic weighted localization loss function, CFAM, and SPPF_CFAM modules. This network not only enhances feature extraction and cross-scale correlation of infrared small targets but also improves the anti-interference capability in complex scenes. Furthermore, its architecture is compatible with mainstream detection frameworks, providing an efficient and highly adaptable innovative solution for small target detection. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a flowchart of a night patrol method for small infrared targets in oil and gas pipelines based on cross-fusion attention proposed in this application; Figure 2 A schematic diagram of the CFAM module constructed for this application; Figure 3 A schematic diagram of the structure of the SPPF_CFAM module for this application; Figure 4 This is a schematic diagram of the structure of the efficient infrared small target detection network model of the improved YOLOv8 in this application; Figure 5 The comparison results of the loss curves for model training and validation in this application; Figure 6 The comparison results of the model performance index (mAP) in this application; Figure 7 The heatmap comparison results are output by the detection head of the model in this application. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application are described clearly and completely below. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are also within the scope of protection of this application.
[0023] See Figures 1 to 7 As shown, this application provides a night patrol method for small infrared targets in oil and gas pipelines based on cross-fusion attention, which includes the following steps:
[0024] The infrared data collection unit of the UAV, especially the inspection and data acquisition unit, contains infrared radiation characteristic data of various targets such as personnel, non-motorized vehicles, motorized vehicles and construction machinery, which are labeled and used to build a training set.
[0025] In step S1, a feature layer that best matches the scale of each acquisition unit target is dynamically assigned. The mismatch compensation coefficient is calculated using the cross-layer response difference to avoid insufficient positioning weight caused by mismatch of small targets to large stride layers. The scale evaluation deviation caused by feature layer mismatch is corrected, thereby ensuring the consistency and integrity of feature expression of small targets in complex night patrol scenarios.
[0026] The specific steps are as follows: First, for the three feature layers of the feature pyramid in the YOLO series algorithms, namely stride=8, stride=16, and stride=32, the optimal target scale range for each layer is predefined. Let the feature layer be... The step size is Its corresponding optimal target scale range is .
[0027] For the output foreground target, calculate its width, height, and area within the ground truth bounding box. The scale adaptation score of the target feature layer is calculated by combining the step size of each feature layer with the preset scale range, and the feature layer with the highest score is selected as the optimal feature layer for the target.
[0028] Among them, if the area of the target for Then its feature layer The scale fit scores are shown below: ; In the formula, v represents the scale fit score. The resulting optimal feature layer index... The corresponding step size is The feature layer assigned to the current target. Its optimal feature layer When there is inconsistency, a mismatch compensation coefficient is calculated to enhance the positioning loss weight of small targets under mismatch conditions.
[0029] The mismatch compensation coefficient and positioning loss weight are calculated as follows:
[0030] In the formula, This represents the mismatch compensation coefficient. If the target... Mismatch to the extreme layer, Then the mismatch compensation coefficient At this point, the positioning loss weight increases by 50%.
[0031] S2. Extract target background features, flatten the background features into channel-dimensional feature vectors, calculate the probability distribution and background entropy of the channel dimensions, normalize the background entropy using the Sigmoid function, and map it to context weights, outputting background adaptation weights. By extracting the complexity of the target background features, context weights are generated to distinguish target localization requirements in simple or complex backgrounds. Specific operations are as follows: Multi-scale feature maps based on feature pyramid output The corresponding feature layers have strides of 8, 16, and 32, respectively. The RoIAlign operation is used to extract background features from the 3×3 region surrounding the target. Flatten it into a feature vector of the channel dimension. Then, the probability distribution of each channel is calculated. And background entropy. The calculation formula is shown below:
[0032] In the formula, Represents the probability distribution along the channel dimension; The feature vector representing the channel dimension after the background features have been flattened; Indicates context weight; = .
[0033] Furthermore, the background entropy is normalized using the Sigmoid function, and the output is denoted as... And mapped to context weights This assigns higher localization weights to targets in complex backgrounds, enhancing the model's perception capabilities in low-light, high-interference scenarios such as night patrols. The calculation formula is shown below:
[0034] In the formula, This represents the background entropy normalization result, i.e., the output value of the Sigmoid function; This indicates the background adaptation weight.
[0035] At this time, if the target has a complex background ,but The value is 1.5, if the goal is simple. ,but The value is 1.0, thus effectively achieving background complexity assessment based on target background entropy.
[0036] S3. Calculate the basic weight and scale weight, and obtain the dynamic weight by fusing the mismatch compensation coefficient and background adaptation weight in multiple dimensions. Calculate the final loss value based on the basic positioning loss CIoU combined with the dynamic weight. Obtain the total positioning loss by combining the final loss value with the DFL loss and the dynamic weight.
[0037] This approach constructs a multi-dimensional weight fusion and loss calculation unit, which is the core execution module of the target localization loss function. It integrates the compensation coefficients and adaptation weights output by cross-layer scale verification and context-aware mechanisms, and merges basic weights and scale weights to construct a dynamic, full-dimensional weighting system. This forms a unified weight framework that adapts to target confidence, scale changes, feature layer matching, and background complexity. Based on localization loss such as CIoU, it calculates the final loss value, achieving precise penalty for localization deviation and priority optimization of high-value targets.
[0038] Among them, the basic weight The target's overall confidence is reflected by summing its predicted scores across all categories. Valid foreground regions are then selected using a foreground mask, and the dimensions are expanded to accommodate subsequent calculations. This weight prioritizes high-confidence foreground targets, providing reliable initial values for dynamic adjustments while suppressing background interference. Scale weight. The normalized area is then obtained based on the ratio of the actual target area to the intermediate scale of the optimal feature layer. After truncation, the value is subtracted from 1.5 to obtain the scale weight value, so that small targets are given higher weights, and medium and large targets are assigned appropriate weights. This compensates for the difficulty in locating small targets due to feature weakening, and ensures that the model prioritizes optimizing the localization bias of small targets during training.
[0039] Normalized area The calculation formula is:
[0040] in, This represents the intermediate scale of the optimal feature layer.
[0041] Scale weight The calculation formula is:
[0042] Furthermore, by integrating the mismatch compensation coefficient, scale weight, basic weight, and context weight, the final dynamic weight is obtained. The calculation formula is as follows:
[0043] In the formula, Indicates dynamic weights; Indicates the basic weight; Indicates scale weight; Indicates the mismatch compensation coefficient; This represents the context weight. This dynamic weighting mechanism fully considers target confidence, scale characteristics, feature layer matching bias, and contextual semantic information to achieve multi-dimensional collaborative weighting.
[0044] Based on a dynamic weighted, multi-dimensional weighted system, the final localization loss is calculated by combining the CIoU loss with the dynamic weights, as shown in the following formula:
[0045] In the formula, This indicates the final location loss; The sum of the scores of all prospective objectives; Indicates the number of forward targets; The result is the calculated CIoU for the target.
[0046] The total localization loss is further optimized by incorporating Distributed Focal Point Loss (DFL). DFL improves regression accuracy by modeling the probability distribution of the true values of the bounding box coordinates on both sides of integer positions. The final total localization loss is a weighted sum of the dynamically weighted CIoU loss and the DFL loss, expressed as:
[0047] In the formula, This represents the total positioning loss; These represent the loss weights, which are 7.5 and 1.5 respectively.
[0048] S4. Segment the feature map using the CBAM attention mechanism to obtain spatial feature branches and channel feature branches. Process the spatial feature branches and channel feature branches to obtain spatial enhancement features and channel enhancement features. The operation steps are as follows: S401, Feature Channel Segmentation Strategy. This strategy is applied to the input feature map. The feature channels are divided into spatial feature branches using a 3:1 ratio. With channel feature branches .
[0049] S402, Spatial Feature Branch By allocating 3 / 4C channels and increasing channel resource allocation through spatial branching, the shallow texture and positional details of small infrared targets are effectively preserved. Through two 3×3 convolutional layers and one 1×1 convolutional layer, the semantic correlation of spatial features is enhanced and dimensional alignment is achieved, outputting spatially enhanced features. .
[0050] S403, Channel Feature Branch Allocate 1 / 4C channels, extract semantic association information along the channel dimension, and map the original features to a 1×1 convolution. Channel, output channel enhancement features .
[0051] S5. Spatial modulation features are obtained by guiding spatial region localization through channel enhancement features. These spatial modulation features are then used to guide semantic channel filtering, resulting in channel modulation features. Finally, the spatial and channel modulation features are fused to obtain the fused features. This step establishes a bidirectional, cross-guided attention modulation paradigm, allowing spatial and channel features to mutually provide attention weights, achieving precise filtering and enhancement of both types of information. The operation steps are as follows: S501, Enhance channel features As a pre-set spatial attention module for guiding signal input, global average pooling is performed on the channel enhancement features, and the channel enhancement features are... The spatial dimension is compressed to 1×1 to obtain statistical features that reflect the global distribution of channel semantics. These features are then normalized using the Sigmoid function to generate a spatial attention weight map. The higher the weight value of the spatial attention weight map, the stronger the semantic match between the spatial location and the infrared small target.
[0052] S502, Integrate spatial attention weight map with spatial enhancement features Element-wise multiplication yields spatial modulation features. This process can effectively suppress low-response regions in complex backgrounds, while enhancing the spatial feature representation of key structures such as edges and contours, thus alleviating the problem that infrared small targets are easily occluded due to their small size.
[0053] S503, Spatial Enhancement Features As guiding signals, global average pooling and global max pooling operations are performed respectively to obtain the channel's global semantic contribution features. Local target information features .
[0054] S504. Global semantic contribution features and local target information features are input into a shared MLP containing a bottleneck structure, and then element-wise summed. After Sigmoid activation, a channel attention weight map is generated. .
[0055] S505. Multiply the channel attention weight map element-wise with the channel enhancement features to obtain the channel modulation features. This enables the enhancement of the dedicated semantic channel for the grayscale features of small infrared targets.
[0056] S506. The spatial modulation features and channel modulation features are added element-wise and fused together, using the following formula: .
[0057] In the formula, The final output fused feature avoids the surge in channel number caused by feature splicing, thus achieving lightweight design. At the same time, the fused feature contains both accurate spatial location information guided by channel semantics and key semantic information guided by spatial details. It can be directly input into subsequent network layers such as feature pyramids or feature aggregation modules such as C2f and RepBlock, effectively alleviating the problem of target misjudgment caused by the disconnect between channel semantics and spatial details, and improving the model's ability to locate and recognize small infrared targets in complex scenes.
[0058] It should be noted that in the improved target detection network, the lightweight cross-fusion attention module CFAM based on complementary mapping of channel and spatial features is embedded in the key feature layer of the network neck. Specifically, it is deployed in the 80×80 resolution feature layer of the YOLOv8 network neck, located in the initial processing stage of receiving the output features of the backbone network and the secondary enhancement stage after multi-scale fusion, respectively. This enables dual fine-grained modeling of the spatial position and channel semantics of small infrared targets, significantly improving the detection sensitivity and robustness of small targets in complex backgrounds.
[0059] S6. First, perform convolution operations on the spatial feature branches, inheriting the core operation of SPPF multi-scale pooling to form a multi-scale feature set. Then, perform channel concatenation and convolution on the multi-scale feature set to obtain multi-scale spatial features. Perform convolution and mapping on the channel feature branches, retaining the target channel semantic statistics to generate channel semantic features. This step involves constructing the CFAM module, designing a lightweight attention fusion structure based on a dual-path interaction mechanism of channels and space, and improving the spatial pyramid pooling module SPPF_CFAM.
[0060] The specific operating steps are as follows: The S601 and SPPF_CFAM modules receive feature maps output from the deep layers of the backbone network. Its dimensions are ,in Input the number of channels. These represent the height and width of the feature map, respectively.
[0061] In this embodiment, the input feature map dimensions are 512×50×40. A 3:1 fixed-ratio channel segmentation strategy is adopted for... After splitting along the channel dimension, we obtain a spatial feature branch and a channel feature branch, where the spatial feature branch has a dimension of [missing information]. This branch is used to preserve the spatial details of small infrared targets, such as the edges and limb contours of infrared personnel, and provides a detailed foundation for subsequent multi-scale pooling; while the channel feature branch dimension is... This branch is used to extract semantic information of the target channel (such as the channel response corresponding to human infrared radiation) while reducing the complexity of semantic processing.
[0062] S602. The spatial feature branch first performs two-level 3×3 convolution operations to enhance the spatial details of small targets, such as the outline of a person's limbs, and suppress infrared thermal noise interference. Then, it inherits the core operation of SPPF multi-scale pooling, that is, it generates four sets of features with different receptive fields through iterative max pooling to form a multi-scale feature set, thereby covering the multi-scale detection requirements of targets of different sizes. Finally, it obtains multi-scale spatial features through channel splicing and 1×1 convolution.
[0063] In this embodiment, its dimension is ,in This means that the number of output channels of the SPPF_CFAM module remains consistent with the number of input channels. The channel feature branch performs a 1×1 convolution while maintaining the same spatial dimension, increasing the number of channels from... Mapped to It quickly aligns with the dimensions of the spatial branches while preserving the semantic statistics of the target channel and outputs the channel semantic features.
[0064] S7. Perform target feature enhancement on the multi-scale spatial features and channel semantic features, and introduce bidirectional cross-modulation.
[0065] In this step, cross-attention-driven target feature enhancement is performed on multi-scale spatial features and channel semantic features, and the feature response of small target locations such as people is improved through bidirectional cross-modulation.
[0066] Specifically, consistent with the CFAM module, channel attention is guided by multi-scale spatial features, efficiently generating accurate channel weights through dual pooling and MLP operations. This significantly enhances the channel responses related to the infrared characteristics of small targets, specifically those corresponding to high-temperature regions. Simultaneously, spatial attention is guided by channel semantic features, generating a spatial weight map focusing on the location of small targets, greatly improving the response intensity of multi-scale pooled spatial features in regions of small targets such as personnel. Finally, through channel concatenation and 1×1 convolution fusion, the enhanced spatial and channel features are deeply integrated, preserving multi-scale spatial details while strengthening the semantic association of targets. The final output features clearly highlight the location of small targets such as personnel, significantly improving target feature recognition in complex backgrounds.
[0067] S8. Introduce a multi-branch convolutional reparameterization module and integrate a cross-attention modulation module and a multi-scale feature enhancement module to construct an end-to-end efficient detection network for infrared scenes. The key to this step is solving the core problems of easy loss of feature details, weak multi-scale correlation, and insufficient anti-interference ability in complex backgrounds in infrared small target detection. This is achieved through collaborative optimization of network parameter configuration, backbone feature extraction, neck fusion interaction, and head detection output across the entire chain. A multi-branch convolutional reparameterization module (RepBlock) is introduced, and a cross-attention modulation module (CFAM) and a multi-scale feature enhancement module (SPPF_CFAM) are integrated to construct an end-to-end efficient detection network adapted to infrared scenes. Specific operations are as follows: S801. Optimize deep feature extraction in the backbone network: Increase the repetition frequency of the feature enhancement modules in layer 2 (C3 / C2f / ELAN, etc.) from 3 to 6 times, and in layer 6 from 6 to 9 times; remove layer P5 to enhance the semantic expression and detail preservation capabilities of mid-layer features; replace the traditional SPPF module with the SPPF_CFAM module in layer 7 (corresponding to the original layer 9), and improve the small target recognition of deep features through bidirectional cross-attention to solve the detail dilution problem. Note: This network is trained on an 800×640 rectangular scale, and the output dimension is maintained at 50×40 to adapt to subsequent neck fusion.
[0068] S802. Processing multi-scale features of backbone network output (200×160 / 100×80 / 50×40 resolution): 200×160 features are compressed to 256 channels by 1×1 convolution, 50×40 features are unified in dimension by convolution of the same specification, and 100×80 features are integrated into the CFAM module to enhance the semantic association of the target; the C2f module of the neck fusion link is replaced with the RepBlock module, and the multi-branch structure in the training stage is used to improve the non-linear expression ability, and the inference stage is fused into a single branch to maintain timeliness; a cross-level connection of "backbone output - intermediate fusion layer" is added at 100×80 resolution to build a multi-dimensional feature transmission path and avoid the loss of small targets across scales.
[0069] The S803 adds a 200×160 resolution detection branch to cover high-resolution small targets, and integrates a CFAM module before the 100×80 branch. It enhances the target response through spatial-channel feature cross-modulation and suppresses infrared thermal noise and false target interference. The size of the detection head convolution kernel and the number of output channels are adjusted to achieve synchronous detection and output of multi-scale features, forming a complete and efficient link from backbone feature extraction to head detection.
[0070] S9. Based on the infrared scene, an end-to-end high-efficiency detection network is constructed, with the final loss value as the supervision strategy, to build an end-to-end training process.
[0071] In this embodiment, an end-to-end training process is constructed based on an efficient infrared small target detection network and a dynamic weighted target localization loss function as a supervision strategy. The loss function evaluates the multi-scale localization deviation of small targets in real time and assigns weights based on background complexity. This guides the network to correct the localization deviation of small targets with weak features and suppresses thermal noise and false target interference, ultimately improving the accuracy and robustness of small target detection in complex infrared scenes.
[0072] Specifically, the training loss curve of the infrared small target high-efficiency detection network model in this embodiment is as follows: Figure 5 As shown, the improved target localization verification loss exhibits a faster convergence speed and a lower convergence value, indicating that the model has a stronger feature learning ability for difficult samples such as small targets. Figure 6 The mAP comparison results of this method with the baseline YOLOv8s are shown, with the accuracy on the infrared night patrol test set improved from 0.844 to 0.927 (mAP +8.3%). Furthermore, Figure 7 The results of the heat map visualization of small target personnel images at the oil and gas inspection site are presented. The comparison shows that the improved model shows higher activation intensity (richer orange and darker color) in the personnel and vehicle areas, indicating that the model is better at fine-grained feature representation and small target attention focus.
[0073] In summary, by strengthening the small target localization loss function and constructing an efficient infrared small target detection network integrating cross-fusion attention, multi-scale feature enhancement, and reparameterization fusion, the current poor performance of infrared small target detection in oil and gas fields can be effectively addressed, improving the operational capabilities of UAVs in extreme environments. However, this method also has areas for improvement. For example, to better adapt to the strong coupling between targets and backgrounds in oil and gas infrared scenarios, the current cross-fusion attention module does not specifically enhance the feature discrimination of the thermal radiation difference between targets and backgrounds, leaving room for improvement in its feature focusing capability for low-contrast infrared small targets.
[0074] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A night patrol method for small infrared targets in oil and gas pipelines based on cross-fusion attention, characterized in that: Includes the following steps: S1. Dynamically select the optimal feature layer for each target through the cross-layer scale verification unit, and calculate the mismatch compensation coefficient of the feature layer; S2. Extract target background features, flatten the background features into channel-dimensional feature vectors, calculate the probability distribution and background entropy of the channel dimensions, normalize the background entropy using the Sigmoid function, map it into context weights, and output background adaptation weights. S3. Calculate the basic weight and scale weight, and obtain the dynamic weight by fusing the mismatch compensation coefficient and background adaptation weight in multiple dimensions. Calculate the final loss value based on the basic positioning loss CIoU combined with the dynamic weight. The total positioning loss is obtained by combining the final loss value with the DFL loss and the dynamic weight. S4. The feature map is segmented using the CBAM attention mechanism to obtain spatial feature branches and channel feature branches. The spatial feature branches and channel feature branches are then processed to obtain spatial enhancement features and channel enhancement features. S5. The spatial modulation features are obtained by guiding spatial region localization through channel enhancement features. The channel modulation features are obtained by guiding semantic channel filtering through spatial enhancement features. The spatial modulation features and channel modulation features are fused to obtain the fused features. S6. First, perform convolution operation on the spatial feature branch and inherit the core operation of SPPF multi-scale pooling to form a multi-scale feature set. Perform channel concatenation and convolution on the multi-scale feature set to obtain multi-scale spatial features. Perform convolution and mapping on the channel feature branch and retain the target channel semantic statistical information to generate channel semantic features. S7. Perform target feature enhancement on the multi-scale spatial features and channel semantic features, and introduce bidirectional cross-modulation; S8. Introducing a multi-branch convolution reparameterization module and integrating a cross-attention adjustment module and a multi-scale feature enhancement module to construct an end-to-end efficient detection network for infrared scenes; S9. Based on the infrared scene, an end-to-end high-efficiency detection network is constructed, with the final loss value as the supervision strategy, to build an end-to-end training process.
2. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 1, characterized in that: According to step S1, the optimal target scale range for each of the three feature layers of the feature pyramid in the YOLO algorithm is preset. For each foreground target, calculate the width, height, and area of its true bounding box. Combine the stride of each feature layer with the preset scale range to determine its scale adaptation score on different layers. Select the layer with the highest score as the optimal feature layer and calculate the mismatch compensation coefficient for the target on non-optimal layers accordingly to alleviate the positioning deviation caused by scale mismatch.
3. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 1, characterized in that: According to step S2, the background features are the features of the target surrounding area extracted through the multi-layer feature map of the feature pyramid and the RoIAlign operation. The probability distribution of the channel dimension The formula for calculating background entropy is shown below: ; In the formula, Represents the probability distribution along the channel dimension; The feature vector representing the channel dimension after the background features have been flattened; Indicates context weight; = .
4. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 3, characterized in that: The formula for calculating the background adaptation weight is as follows: ; In the formula, This represents the background entropy normalization result, i.e., the output value of the Sigmoid function; This indicates the background adaptation weight.
5. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 1, characterized in that: According to step S3, the basic weights are generated based on the target category score, and the scale weights are dynamically generated based on the target scale and the adaptability of the optimal feature layer. By integrating the base weights, scale weights, mismatch compensation coefficients, and context weights, the dynamic weights are obtained, and the calculation formula is shown below: In the formula, Indicates dynamic weights; Indicates the basic weight; Indicates scale weight; Indicates the mismatch compensation coefficient; This indicates the context weight.
6. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 5, characterized in that: The dynamic weights use CIoU loss as the base loss and combine it with the dynamic weights to calculate the final localization loss: In the formula, This indicates the final location loss; The sum of the scores of all prospective objectives; Indicates the number of forward targets; The result is the calculated CIoU for the target.
7. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 6, characterized in that, The formula for calculating the total positioning loss is as follows: In the formula, This represents the total positioning loss; This represents the loss weight.
8. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 1, characterized in that: According to step S4, the lightweight cross-fusion attention module CFAM, constructed based on the complementary mapping characteristics of the spatial feature branch and the channel feature branch, is embedded in the key feature layer of the network neck.
9. The method for night patrol of small infrared targets in oil and gas pipelines based on cross-fusion attention as described in claim 1, characterized in that: According to step S5, the channel enhancement feature is used as a guiding signal to perform global average pooling and compression in the channel dimension to obtain statistical features that reflect the global distribution of spatial semantics. Then, it is mapped to a channel attention weight map in the 0-1 interval by the Sigmoid activation function. The attention weight map is multiplied element-wise with the spatial enhancement feature to obtain the spatial modulation feature. The spatial enhancement features are used as guiding signals to perform global average pooling and global max pooling operations to obtain features reflecting the global semantic contribution of the channel and features reflecting the local target information of the channel. The two are fused and added as inputs and activated by Sigmoid to generate a spatial attention weight map. The spatial attention weight map is multiplied element-wise with the channel enhancement features to obtain the channel modulation features.