Pipeline magnetic flux leakage image segmentation method based on multi-scale SegFormer network
By introducing multi-scale feature fusion and cascade attention modules into the SegFormer network, the problem of insufficient segmentation capability of the model for small targets is solved, and the segmentation accuracy and detection efficiency of leakage magnetic defects are significantly improved.
Patent Information
- Application Number
- CN202411310117.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2025-01-03
AI Technical Summary
The existing SegFormer model lacks the ability to segment small targets in pipeline magnetic leakage images, making it difficult to accurately detect and evaluate magnetic leakage signals.
Multi-scale feature fusion and cascade attention modules are added to the SegFormer network, and the model's segmentation ability of small objects is enhanced through feature pyramid fusion and attention mechanism, and the model's feature expression and local feature perception are improved.
The accuracy of leakage defect segmentation and detection ability of small targets are improved, and more efficient and accurate detection of leakage magnetic signal is achieved.
Smart Images

Figure CN119251500A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of magnetic flux leakage image processing, and in particular relates to a pipeline magnetic flux leakage image detection method based on a multi-scale SegFormer network. Background Art
[0002] Pipeline leakage accidents caused by corrosion, wear, accidental damage, etc. can cause loss of life and property and environmental pollution. Magnetic flux leakage detection technology plays an important role in long-distance oil and gas production. At present, the identification and analysis of magnetic flux leakage are mostly done manually, but the amount of magnetic flux leakage image data is large and the types are many, so there are some problems, such as time-consuming, leakage judgment, misjudgment, etc. Therefore, how to efficiently and accurately detect magnetic flux leakage signals is an urgent problem to be solved. Traditional target detection networks can locate defects, but for defects in pipeline magnetic flux leakage images, it is not enough to use traditional target detection networks to identify and locate defects. The purpose of pipeline magnetic flux leakage detection is to locate the defect position and evaluate the degree of damage of inner wall defects. The evaluation of the degree of damage of inner wall defects of pipelines requires not only defect position information but also defect size information. Traditional target detection networks often use anchor frames to locate targets, which is difficult to use as a reference for defect size. Therefore, image segmentation networks are needed to accurately segment defects to obtain defect size information.
[0003] The SegFormer network model can accurately and quickly segment target objects. However, the SegFormer model has poor detection capabilities for small targets and there is still room for improvement.
[0004] Based on this, the present invention proposes an improved magnetic flux leakage image segmentation method based on the SegFormer model. Summary of the invention
[0005] In order to overcome the above technical problems, the present invention provides a pipeline magnetic leakage image segmentation method based on a multi-scale SegFormer network to solve the problem of poor small target segmentation ability of the current SegFormer model.
[0006] The present invention adopts the following technical solutions:
[0007] A pipeline magnetic leakage image segmentation method based on a multi-scale SegFormer network comprises the following steps:
[0008] S1: Obtain the magnetic flux leakage signal in the pipeline through the magnetic flux leakage detector;
[0009] S2: Pseudo-color processing technology is used for image enhancement, and density segmentation is used for pseudo-color enhancement;
[0010] S3: Add multi-scale feature fusion and cascade attention modules to the SegFormer network to obtain a new SegFormer network model;
[0011] S4: Magnetic leakage image detection using the improved SegFormer network.
[0012] In S3, the SegFormer network consists of an improved TransFormer network encoder and a lightweight decoder. A feature pyramid fusion module is added to the decoder in the SegFormer network. Then, attention is paid to the feature map generated by the previous encoder, and upsampling is used to adapt to inputs of any size. The low-resolution feature map size is changed to be consistent with the image high resolution. The two feature maps are concatenated pixel by pixel to obtain a fused feature map of the underlying and high-level semantic information.
[0013] In S3, feature pyramid fusion modifies the feature fusion method based on the original network, changing the original direct addition to channel splicing to make it more suitable for segmentation tasks. After each feature fusion, a residual network is added to enable the network to transmit information more effectively, allowing shallower layers to be more directly involved in the expression of feature fusion, and transmitting the most original details and edge information directly to the second half of the feature fusion, thereby improving the overall feature expression capability.
[0014] In S3, a cascaded attention mechanism module TAL is proposed. This module uses two attention modules, TripletAttention and Lsk, and puts it after the feature fusion network to pay more attention to the local information and edges of the leakage magnetic image and better focus on the detail features.
[0015] In S3, in the shallow structure, the network’s attention is focused on the background and other areas, while in the deep structure, the network’s attention feature map is focused on the object to be detected.
[0016] In S3, the TAL module first uses TripletAttention to enhance the local feature representation of magnetic leakage defect information, and then puts the data processed by TripletAttention into the Lsk attention. After the local information is extracted and integrated, the feature expression can be further optimized. Finally, the results of the two attentions are spliced on the channel to give full play to the advantages of these two different attention mechanisms and enhance the model's perception and representation capabilities of local features.
[0017] In S4, after the pseudo-color enhanced image is placed into the improved model, the image is composed of four layers of multi-head attention. The feature maps generated by these four layers of attention are successively fused according to high and low resolutions, and upsampling is used to adapt to inputs of any size. The two feature maps are spliced pixel by pixel to obtain a fused feature map of the bottom-level and high-level semantic information.
[0018] The beneficial effects of the present invention are:
[0019] Multi-scale feature fusion is used to extract richer low-level and high-level semantic information features of small targets. The cascaded attention module enhances the model's perception and representation capabilities of local features, thereby improving the model's performance in magnetic flux leakage defect segmentation. It can effectively improve the segmentation accuracy of magnetic flux leakage defects and has a certain guiding role in the efficient and accurate detection of magnetic flux leakage signals. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a schematic diagram of the steps of the present invention;
[0021] Figure 2 It is the structure of the multi-scale fusion module;
[0022] Figure 3 It is the structure of the cascaded attention module;
[0023] Figure 4 It is the pipeline magnetic leakage detection data in the actual project;
[0024] Figure 5 It is the detection result image, where (a) is the input image, (b) is the segmentation result of the SegFormer model, and (c) is the segmentation result of the improved model. DETAILED DESCRIPTION
[0025] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0026] like Figure 1 As shown, a pipeline magnetic leakage image detection method based on a multi-scale SegFormer network includes the following steps:
[0027] S1: Obtain the magnetic flux leakage signal in the pipeline through the magnetic flux leakage detector:
[0028] Pipeline magnetic flux leakage internal detection uses a permanent magnet to fully magnetize the ferromagnetic pipeline through a rigid brush to make it saturated or close to saturation, and judges whether the pipeline has defects by the change of magnetic induction lines. If there are no defects in the pipe wall, the magnetic induction lines are parallel to the inside of the pipe; if there are defects in the pipe wall, the magnetic induction lines will leak from the surface of the pipe, causing magnetic leakage. The magnetic leakage signal collected by the magnetic sensor is imaged to determine the characteristics and location of the defect.
[0029] S2: Use pseudo color processing technology for image enhancement and density segmentation for pseudo color enhancement:
[0030] After the magnetic flux leakage image is input, since the magnetic flux leakage signal is a three-dimensional signal, the curve and grayscale image cannot fully display all the data information. Pseudo-color processing technology is an effective image enhancement method. It can improve the resolution of image details and obtain a clear and natural image. The color value can be used as a three-dimensional feature of the magnetic flux leakage signal, so that the complete data of the magnetic flux leakage signal can be displayed by color. The present invention uses pseudo-color processing technology for image enhancement and density segmentation for pseudo-color enhancement. The grayscale level of the image is divided into N intervals I from 0 to M0. i (i=1,2,3,...N), and set the color C i Assigned to each interval, so that a pseudo-color image can be generated. Assuming that the grayscale range of the original grayscale image is 0≤f(x,y)≤50, the grayscale range is divided into k segments, [(I0, I1, ..., I k ),I0=0,I k =L] to map each gray level to a color, and the mapping relationship is as follows:
[0031]
[0032] Among them, g(x,y) is the output pseudo-color image; C i To map the color.
[0033] S3: Add multi-scale feature fusion and cascade attention modules to the SegFormer network to obtain a new SegFormer network model;
[0034] The original SegFormer decoding layer only upsamples and concatenates the outputs of four different Transformer modules in terms of dimensions, and does not fully fuse feature maps of different scales. In order to enhance feature representation, the original decoder of SegFormer is replaced by a new decoder network MSF, which first interpolates low-resolution feature maps through upsampling, and then fuses feature maps of different sizes to achieve clearer magnetic leakage defect segmentation. Multi-scale feature fusion is added to the original network multi-scale feature fusion for further feature fusion, increasing the perception of detailed feature parts on low-resolution images, and using the cascaded attention module TAL (TripletAttention-Lsk) to focus on detail information, enhance useful features and suppress features that are useless for the task. Finally, the four feature maps of different sizes that have been fused step by step are fused again to better capture multi-scale information.
[0035] The specific structure of the multi-scale fusion module is as follows: Figure 2 As shown, is a low-resolution feature map. The high-resolution feature map is represented as is the output of this module, It is the output after adding high and low resolution feature maps. Conv2d is a convolution with a convolution kernel size of 1×1. is the output of this module.
[0036] The calculation process is described in (2)-(3).
[0037]
[0038]
[0039] In order to enhance the semantic features after multi-scale feature fusion, and dynamically filter the high-level semantic features that affect small defects and detail features in the image according to the spatial context information of the features during the fusion process, this paper proposes a cascaded attention mechanism module. This module uses two attention modules, TripletAttention and Lsk, to better focus on detail features. First, TripletAttention is used to enhance the local feature representation of leakage magnetic defect information by considering the triple relationship in the local area. Then the data processed by TripletAttention is put into the Lsk attention. After the local information is extracted and integrated, the feature expression can be further optimized, and the local adaptive ability of Lsk attention can be fully utilized. Finally, the results of the two attentions are spliced on the channel to give full play to the advantages of these two different attention mechanisms, enhance the model's perception and representation of local features, and thus improve the model's performance in leakage magnetic defect segmentation. The structure of the cascaded attention module is shown in the figure. Figure 3 shown.
[0040] in, It is the output after the fusion of high and low resolution feature maps. and is the output variable of the two attention modules, which represents the output feature map after the weighting of the two attention modules. concat is the concatenation operation on the channel, and conv is the convolution operation, which makes the number of channels of the concatenated feature map return to 256. The output of the TAL module is represented as
[0041] The calculation process is in (4)-(6). TA and Lsk are weighted by attention.
[0042]
[0043]
[0044]
[0045] S4: Application of the improved SegFormer network for magnetic flux leakage image detection:
[0046] In order to analyze the performance of the algorithm in more detail, multiple indicators will be used for evaluation. In the embodiment, MIoU, MPA and Accuracy are used as evaluation indicators. IoU is the ratio of the intersection and union of the model's prediction results and the true value of a certain category. MIoU (Mean Intersection over Union) is the most commonly used semantic segmentation evaluation indicator and can be used to judge the network segmentation effect. The MIoU principle formula is as follows.
[0047]
[0048] Where k is the number of categories, i is the true value, j is the predicted value, is the number of pixels that predict i as j, and is the number of pixels that predict j as i.
[0049] At the same time, MIoU is equivalent to formula (8), where TP is the true value, which represents the number of correct predictions;
[0050] FN is the false negative, which represents the number of targets predicted as background; FP is the false positive, which represents the number of backgrounds predicted as targets, and TP is the true negative, which represents the number of correct background predictions.
[0051]
[0052] MPA represents the pixel-level accuracy, which is the average ratio of the number of correctly segmented pixels to the total number of pixels at the pixel level. The calculation formula is as follows:
[0053]
[0054] Accuracy is a common indicator for evaluating the performance of classification models. It measures the proportion of samples correctly predicted by the model on the entire data set. The calculation formula is:
[0055]
[0056] To calculate the Accuracy value for a certain category, we need to first calculate the detection precision and recall. Precision refers to the ratio of the actual number of positive samples in the predicted sample to the total number of positive samples, as shown in the formula (11).
[0057]
[0058] In the formula, TP represents the number of predicted samples that are judged as positive examples and are actually positive examples, and FP represents the number of predicted samples that are judged as positive examples but are actually negative examples.
[0059] Recall refers to the ratio of the actual positive samples in the predicted samples to all predicted samples, as shown in the formula (12).
[0060]
[0061] In the formula, FN represents the number of positive examples judged as negative examples in the prediction samples.
[0062] The pipeline magnetic flux leakage image segmentation method based on the multi-scale SegFormer network provided by the present invention is verified below.
[0063] like Figure 4 As shown in the figure, the experimental data comes from real pipeline magnetic flux leakage detection data in actual projects. The pipeline magnetic flux leakage image dataset used in the experiment contains 1,500 pseudo-color images with different degrees of corrosion defects. The dataset combines multiple defects into one defect, ignores the defect type, and focuses on the defect size and corrosion condition, as well as the degree of damage to the pipeline.
[0064] Figure 5In the figure, (a) is a magnetic flux leakage detection image with a resolution of 512×512, which are respectively input into the improved model and the SegFormer model, (b) is the detection result of the SegFormer model, and (c) is the detection result of the improved model. The MIoU of defect segmentation in the improved model can reach more than 90%, while in the original model, the prediction accuracy of small defects is 88%. By comparing the results, the accuracy of the improved model is higher than that of the original model. From the comparison between (b) and (c), it can be seen that some small defects of SegFormer are not detected, while the prediction accuracy of the improved model is higher. By comparing the results of the two models, it can be found that the segmentation ability of the improved model is higher than that of the SegFormer model, especially for the segmentation of small target defects.
[0065] Although the embodiments of the present invention have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions and variations may be made to the above embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. A pipeline magnetic flux leakage image segmentation method based on a multi-scale SegFormer network, characterized in that: The steps include: S1: Obtain the magnetic flux leakage signal in the pipeline through the magnetic flux leakage detector; S2: Pseudo-color processing technology is used for image enhancement, and density segmentation is used for pseudo-color enhancement; S3: Add multi-scale feature fusion and cascade attention modules to the SegFormer network to obtain a new SegFormer network model; S4: Magnetic leakage image segmentation using the improved SegFormer network.
2. According to claim 1, a pipeline magnetic flux leakage image segmentation method based on a multi-scale SegFormer network is characterized in that: In S3, the SegFormer network consists of an improved TransFormer network encoder and a lightweight decoder. A feature pyramid fusion module is added to the decoder in the SegFormer network. Then, attention is paid to the feature map generated by the previous encoder, and upsampling is used to adapt to inputs of any size. The low-resolution feature map size is changed to be consistent with the image high resolution. The two feature maps are concatenated pixel by pixel to obtain a fused feature map of the underlying and high-level semantic information.
3. According to claim 2, a pipeline magnetic flux leakage image segmentation method based on a multi-scale SegFormer network is characterized in that: In S3, feature pyramid fusion modifies the feature fusion method based on the original network, changing the original direct addition to channel splicing to make it more suitable for segmentation tasks. After each feature fusion, a residual network is added to enable the network to transmit information more effectively, allowing shallower layers to be more directly involved in the expression of feature fusion, and transmitting the most original details and edge information directly to the second half of the feature fusion, thereby improving the overall feature expression capability.
4. The pipeline magnetic flux leakage image segmentation method based on a multi-scale SegFormer network according to claim 3 is characterized in that: In S3, a cascaded attention mechanism module TAL is proposed. This module uses two attention modules, TripletAttention and Lsk, and puts it after the feature fusion network to pay more attention to the local information and edges of the leakage magnetic image and better focus on the detail features.
5. The pipeline magnetic flux leakage image segmentation method based on a multi-scale SegFormer network according to claim 4, characterized in that: In S3, in the shallow structure, the network’s attention is focused on the background and other areas, while in the deep structure, the network’s attention feature map is focused on the object to be detected.
6. The pipeline magnetic flux leakage image segmentation method based on a multi-scale SegFormer network according to claim 4, characterized in that: In S3, the TAL module first uses TripletAttention to enhance the local feature representation of magnetic leakage defect information, and then puts the data processed by TripletAttention into the Lsk attention. After the local information is extracted and integrated, the feature expression can be further optimized. Finally, the results of the two attentions are spliced on the channel to give full play to the advantages of these two different attention mechanisms and enhance the model's perception and representation capabilities of local features.
7. The pipeline magnetic flux leakage image detection method based on a multi-scale SegFormer network according to claim 1 is characterized in that: In S4, after the pseudo-color enhanced image is placed into the improved model, the image is composed of four layers of multi-head attention. The feature maps generated by these four layers of attention are successively fused according to high and low resolutions, and upsampling is used to adapt to inputs of any size. The two feature maps are spliced pixel by pixel to obtain a fused feature map of the bottom-level and high-level semantic information.
Citation Information
Cited By
Pipeline defect magnetic flux leakage detection method and device based on multi-scale data driving deep learning
CN120992737A
Pipeline defect detection method and device, storage medium and computer equipment
CN121278541A
A pipeline defect detection method and device, a storage medium and a computer device
CN121278541B