Wavelet frequency domain decoupling and attention weld defect identification method and system
Patent Information
- Application Number
- CN202611253078.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-18
- Publication Date
- 2026-10-16
AI Technical Summary
然而,这些方法通常在原始图像空间中进行单一尺度的特征提取,忽略了缺陷特征在不同频域尺度上的差异化表征特性
[0031] Compared with the prior art, the above-mentioned technical solution of the present invention has the following advantages: the present invention improves the interpretability of the model and solves the problem that traditional single-scale models are difficult to take into account both macroscopic structure and microscopic edge information; it improves the detection sensitivity of subtle defects and edge blurring defects; it eliminates the full calculation of all sub-band branches, greatly improves inference efficiency, and is more suitable for industrial online inspection scenarios.
Smart Images

Figure CN122928848A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of industrial nondestructive testing and deep learning technology, specifically relating to a wavelet frequency domain decoupling and attention weld defect identification method and system. Background Technology
[0002] Weld quality is a key factor affecting pipeline structural safety. X-ray non-destructive testing (NDT) technology has been widely used in industrial manufacturing because it can comprehensively detect internal defects in welds without damaging the pipeline structure. However, current weld defect identification faces two major technical bottlenecks: First, weld defect characteristics are complex and diverse, including various types such as porosity, slag inclusions, cracks, and undercut. These defects differ significantly in morphology, scale, and directionality, making it difficult for traditional single-scale feature extraction models to simultaneously capture both the macroscopic morphological structure and microscopic edge details of defects. Second, existing deep learning-based defect identification models generally lack interpretability and struggle to reveal the representational differences and identification mechanisms of different defect types from a frequency domain perspective.
[0003] In existing research on weld defect identification, most methods focus on improving the structure of convolutional neural networks, such as using classic networks like VGG16 and ResNet50 for transfer learning or introducing attention mechanisms to enhance feature representation. However, these methods typically perform feature extraction at a single scale in the original image space, ignoring the differentiated representational characteristics of defect features at different frequency domain scales. Some studies have attempted to introduce wavelet transform into defect detection tasks, but these are mostly limited to using wavelet decomposition as a simple preprocessing method, failing to design differentiated feature extraction strategies based on the physical characteristics of each frequency domain sub-band, and lacking effective inter-sub-band information fusion mechanisms.
[0004] In summary, how to achieve differentiated extraction and adaptive fusion of multi-scale features based on frequency domain decoupling, and improve inference efficiency while ensuring recognition accuracy, is a key technical problem that urgently needs to be solved in the field of intelligent weld defect recognition. Summary of the Invention
[0005] The core of this invention lies in constructing a four-branch defect recognition framework based on wavelet frequency domain decoupling and attention mechanisms. This framework first uses two-dimensional discrete wavelet transform to decouple weld X-ray images into low-frequency approximate sub-bands and three high-frequency detail sub-bands, effectively separating defect features in different directions in the frequency domain. Then, differentiated parallel convolutional neural network branches are designed for the frequency domain characteristics of each sub-band to extract defect features at different directions and scales. A spatial attention mechanism is embedded in each branch to enhance the response of key defect regions. In the fusion stage, a confidence-based dynamic adaptive weight strategy is introduced to replace the traditional simple stitching, and a streaming early stopping mechanism is used to improve inference efficiency.
[0006] To address the aforementioned technical problems, this invention proposes a wavelet frequency domain decoupling and attention-based weld defect identification method, comprising the following steps:
[0007] Step S1: Obtain X-ray images of pipe welds, perform Gaussian filtering for noise reduction and contrast-limited adaptive histogram equalization, extract candidate contour sets using adaptive threshold segmentation and spatial geometric constraints, and perform edge consistency verification using Hough transform, segment and output the region of interest image I of weld defects.
[0008] Step S2: Select a specified discrete wavelet basis to perform a single-layer two-dimensional discrete wavelet transform on the region of interest image I, and decouple it in the frequency domain into a low-frequency approximate subband, a horizontal low-frequency vertical high-frequency detail subband, a horizontal high-frequency vertical low-frequency detail subband, and a diagonal high-frequency detail subband;
[0009] Step S3: Based on the frequency domain characteristics of each sub-band, construct differentiated parallel convolutional neural network branches. The low-frequency branch uses large-size convolutional kernels to extract macroscopic contour features. The vertical abrupt change feature extraction branch targets the horizontal low-frequency and vertical high-frequency detail sub-bands and uses anisotropic convolutional kernels to extract longitudinal defect features along the weld direction. The horizontal abrupt change feature extraction branch targets the horizontal high-frequency and vertical low-frequency detail sub-bands and uses anisotropic convolutional kernels to extract transverse defect features perpendicular to the weld direction. The diagonal high-frequency branch uses small-size convolutional kernels to extract subtle defect features.
[0010] Step S4: Embed a spatial attention module in the convolutional neural network branch of each sub-band, perform channel average pooling and channel max pooling on the channel dimension and concatenate them, generate a two-dimensional spatial attention weight map by mapping through a convolutional layer of preset size and activation function, and then perform pixel-wise Hadamard product operation with the branch input feature map to enhance features.
[0011] Step S5: Each sub-band convolutional neural network branch independently outputs a defect classification probability distribution vector; the normalized discrimination confidence of each branch is calculated by combining the maximum prediction probability and the prediction information entropy; the dynamic contribution weight of each sub-band is generated by using the normalized exponential function; and the probability outputs of each branch are weighted and fused to obtain the comprehensive classification probability.
[0012] Step S6: Set the inference confidence threshold and a sliding window of a preset length. If the predicted branches of multiple consecutive sub-bands output the same category, and the arithmetic mean of the normalized discrimination confidence of all executed branches within the sliding window reaches or exceeds the inference confidence threshold, then the streaming early stop mechanism is triggered to terminate the forward propagation of subsequent branches that have not yet been executed, and the current defect category identification result is directly output. If the arithmetic mean of the normalized discrimination confidence of all executed branches within the sliding window does not reach the inference confidence threshold, then the streaming early stop mechanism is not triggered. The defect category is determined based on the comprehensive classification probability, the target defect category index is determined by the maximum probability selection operator, a high-probability weld defect classification identification decision result is output, and the confidence metric of the final classification decision is generated in combination with the normalized discrimination confidence.
[0013] Further, in step S1, the specific implementation process of adaptive threshold segmentation and spatial geometric constraint extraction of candidate contour set screening is as follows: extract the closed contours in the initial image segmentation stage and calculate their area, the width and height of the circumscribed rectangle, and the contour perimeter; compare the area with a preset minimum area threshold, compare the ratio of the maximum side length to the minimum side length in the width and height of the circumscribed rectangle with a preset aspect ratio threshold, and calculate the compactness index based on the ratio of the contour area to the square of the perimeter and compare it with a preset compactness threshold, and jointly perform validity screening on the candidate contour set to remove invalid contours that do not meet any threshold constraint.
[0014] Further, in step S2, the frequency domain decoupling process is as follows: using a one-dimensional low-frequency scaling function and a one-dimensional high-frequency wavelet basis function, cascaded filtering and downsampling projection operations are performed in the horizontal and vertical directions of the input region of interest image I, respectively; the spatial local energy of the image is adaptively mapped to the low-frequency approximate feature space, the horizontal low-frequency and vertical high-frequency detail feature space, the horizontal high-frequency and vertical low-frequency detail feature space, and the diagonal high-frequency detail feature space, thereby outputting four independent frequency domain feature sub-bands in discrete displacement spatial coordinates.
[0015] Furthermore, in step S3, differentiated parallel convolutional neural network branches are constructed based on the frequency domain characteristics of each sub-band, including a low-frequency branch, a vertical mutation feature extraction branch, a horizontal mutation feature extraction branch, and a diagonal high-frequency branch.
[0016] The low-frequency branch adopts a topology structure consisting of multiple layers of standard convolution and max pooling layers stacked together, which is used to extract the overall morphology structure of the weld and the gray field features of the macro environment that do not depend on local sharp edges.
[0017] The vertical mutation feature extraction branch introduces an asymmetric anisotropic horizontal enhanced convolution kernel in conjunction with standard convolution to selectively enhance the gray-level mutation response in the vertical direction of the image, which is specifically used to extract the defect mutation edges of longitudinal cracks.
[0018] The horizontal mutation feature extraction branch introduces an asymmetric anisotropic vertical direction enhancement convolution kernel in conjunction with standard convolution to selectively enhance the detail information in the horizontal direction of the image, which is specifically used to extract the features of horizontal inclusions and edge bite defects.
[0019] The diagonal high-frequency branch employs multiple small-sized convolution kernels, and a strongly regularized dropout layer is directly connected in series after the convolution activation layer. This is used to accurately capture point-like pores and micro-fine local anomaly features while suppressing high-frequency noise interference within the subband.
[0020] Further, in step S4, a spatial attention module is embedded in the convolutional neural network branch of each sub-band. The specific process is as follows: the input feature map of the corresponding sub-band branch is used as the spatial input, and different spatial statistical features are extracted by channel average pooling and max pooling operations respectively; the average feature and the maximum feature after pooling are concatenated in the channel dimension, and spatial nonlinear interaction and feature compression are performed by a 7×7 convolution kernel, and then extreme value mapping is performed by a sigmoid activation function to generate a two-dimensional spatial attention weight map that can characterize the spatial importance of the defect region; finally, the weight map and the corresponding branch input feature map are subjected to pixel-wise Hadamard product operation to output the enhanced sub-band feature map.
[0021] Further, in step S5, the calculation process of the dynamic contribution weight is as follows: First, based on the defect prediction probability distribution output by each parallel decoupled branch, the prediction information entropy corresponding to each branch is calculated, and combined with the maximum prediction probability of each branch, the primary discrimination confidence of the current branch is calibrated and normalized; then, a smoothness scaling factor of weight evolution control is introduced to numerically scale and adjust the normalized confidence, and it is fed into the normalization exponential function for exponential transformation and proportional normalization operation, adaptively outputting the dynamic contribution weight of each branch feature to the final decision.
[0022] Further, in step S6, the streaming early stopping mechanism is as follows: During the inference process, the predicted category index of the current input sample is monitored in real time through the maximum selection operator on adjacent parallel sub-band branches; when the defect maximum probability corresponding to the category predicted by the adjacent branches is completely consistent, and the arithmetic mean of the normalized discrimination confidence of all executed branches in the current sliding window reaches or exceeds the inference confidence threshold, it is determined that the category consistency and confidence necessity constraints are satisfied at the same time, and then the forward propagation is cut off and the streaming early stopping mechanism is triggered to terminate the forward calculation of subsequent branches that have not yet been executed, and the current defect classification result is directly output.
[0023] On the other hand, the present invention also provides a wavelet frequency domain decoupling and attention weld defect identification system to implement the above-mentioned wavelet frequency domain decoupling and attention weld defect identification method, including the following modules: region of interest segmentation module, two-dimensional discrete wavelet frequency domain decoupling module, four-branch feature extraction neural network module, spatial attention weighting module, confidence dynamic weighted decision module, streaming early stop judgment control unit, and decision classification output module;
[0024] The region of interest segmentation module is used to acquire X-ray images of pipe welds, segment them, extract and output the region of interest image I of weld defects;
[0025] The two-dimensional discrete wavelet frequency domain decoupling module is used to select a specified discrete wavelet basis to perform a single-layer two-dimensional discrete wavelet transform on the region of interest image I, and decouple it in the frequency domain into a low-frequency approximate sub-band, a horizontal low-frequency vertical high-frequency detail sub-band, a horizontal high-frequency vertical low-frequency detail sub-band, and a diagonal high-frequency detail sub-band.
[0026] The four-branch feature extraction neural network module is used to construct differentiated parallel convolutional neural network branches, including a low-frequency branch, a vertical mutation feature extraction branch, a horizontal mutation feature extraction branch, and a diagonal high-frequency branch, which extract the corresponding geometric shape and detail texture features for the four sub-bands respectively.
[0027] The spatial attention weighting module is used to embed spatial attention modules in each sub-network branch. It generates a spatial attention weight map by concatenating dual-channel pooling features and compressing them through convolution. The weight map is then enhanced by performing a pixel-wise Hadamard product operation with the feature map.
[0028] The confidence dynamic weighted decision module is used to combine the defect classification probability distribution vectors independently output by each sub-band convolutional neural network branch, calculate the normalized discrimination confidence of each branch based on its maximum prediction probability and prediction information entropy, generate the dynamic contribution weight of each branch using the normalized exponential function, and perform weighted fusion of the prediction outputs of each branch to generate the comprehensive classification probability.
[0029] The streaming early stop determination control unit is used to monitor the output results of adjacent activated branches in real time within the inference sliding window. When the class consistency of the continuous prediction results and the necessity of the average confidence both meet the preset threshold, early stop is directly triggered to block the forward propagation of subsequent unactivated branches.
[0030] The decision classification output module is used to perform the maximum selection operator on the weighted fusion comprehensive classification probability when the streaming early stop determination control unit does not trigger early stop or completes all branch calculations, and adaptively outputs the final defect identification classification result.
[0031] Compared with the prior art, the above-mentioned technical solution of the present invention has the following advantages: the present invention improves the interpretability of the model and solves the problem that traditional single-scale models are difficult to take into account both macroscopic structure and microscopic edge information; it improves the detection sensitivity of subtle defects and edge blurring defects; it eliminates the full calculation of all sub-band branches, greatly improves inference efficiency, and is more suitable for industrial online inspection scenarios. Attached Figure Description
[0032] To make the content of this invention easier to understand, the invention will be further described in detail below with reference to specific embodiments and accompanying drawings.
[0033] Figure 1 This is a schematic diagram of the overall process of the present invention;
[0034] Figure 2 Comparison of adaptive region of interest extraction processes for weld defects;
[0035] Figure 3 This is a diagram of the two-dimensional discrete wavelet frequency domain spatial decoupling structure.
[0036] Figure 4 Diagram of a wavelet subband differential CNN feature extraction and adaptive weight fusion network architecture;
[0037] Figure 5 Workflow diagram for four-sub weighted fusion and early stopping mechanism. Detailed Implementation
[0038] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments described are not intended to limit the present invention.
[0039] This invention discloses a wavelet frequency domain decoupling and attention-based weld defect identification method. Using X-ray images of pipe welds as input, this method constructs an end-to-end intelligent weld defect identification system through steps such as adaptive region of interest extraction, wavelet frequency domain decoupling, differentiated multi-branch feature extraction, spatial attention enhancement, dynamic weighted fusion of confidence scores, and streaming early stopping inference. This method aims to solve the problems of insufficient single-scale feature extraction, redundant conflicts in multi-scale information fusion, and low model inference efficiency in existing weld defect detection methods, achieving high-precision classification of four typical weld defects: porosity, cracks, slag inclusions, and undercut.
[0040] The overall process is as follows Figure 1As shown, firstly, in step S1, the system acquires the original X-ray image of the pipe weld, suppresses random noise interference through Gaussian filtering, and enhances the contrast between the defect area and the background using contrast-limited adaptive histogram equalization. Based on this, a candidate contour set is extracted using a strategy combining adaptive threshold segmentation and spatial geometric constraints, and edge consistency is verified through Hough transform. Finally, the region of interest image I of the weld defect is segmented and output, providing a precise defect localization basis for subsequent frequency domain analysis.
[0041] Subsequently, in step S2, a single-layer two-dimensional discrete wavelet transform is performed on the region of interest image I using the Daubechies wavelet basis, achieving fine decoupling of the image in the frequency domain. Specifically, cascaded filtering and downsampling projection are performed on the horizontal and vertical directions of the image using a one-dimensional low-frequency scaling function and a high-frequency wavelet basis function, respectively. This adaptively maps the spatial local energy of the image to four independent frequency domain feature sub-bands: a low-frequency approximation sub-band (LL, reflecting the overall contour and macroscopic morphology information of the defect), a horizontal low-frequency and vertical high-frequency detail sub-band (LH, depicting the longitudinal texture changes along the weld direction), a horizontal high-frequency and vertical low-frequency detail sub-band (HL, highlighting the transverse abrupt edges perpendicular to the weld direction), and a diagonal high-frequency detail sub-band (HH, preserving subtle texture and noise distribution information). This frequency domain decoupling method enables the subsequent network to extract defect features at different scales and directions in a targeted manner, avoiding the information trade-offs between macroscopic structure and microscopic edges inherent in traditional single-scale models.
[0042] In step S3, differentiated parallel convolutional neural network branches are constructed to address the frequency domain characteristics differences among the four sub-bands, enabling collaborative extraction of multi-scale features. The low-frequency branch employs a topology of stacked large-size convolutional kernels and max-pooling layers, focusing on extracting the overall defect morphology and macroscopic grayscale features independent of local sharp edges. The vertical abrupt change feature extraction branch introduces asymmetric anisotropic horizontal enhancement convolutional kernels to selectively enhance the grayscale abrupt change response in the vertical direction of the image, specifically for capturing defects such as longitudinal cracks along the weld direction. The horizontal abrupt change feature extraction branch introduces asymmetric anisotropic vertical enhancement convolutional kernels, specifically for extracting defect features perpendicular to the weld direction, such as transverse slag inclusions and edge undercuts. The diagonal high-frequency branch uses multiple layers of small-size convolutional kernels connected in series with strongly regularized dropout layers, accurately capturing point-like pores and subtle local anomalies while suppressing high-frequency noise interference. Through this differentiated design, each sub-band branch possesses targeted feature extraction capabilities, avoiding the homogeneity of feature extraction in traditional multi-scale networks.
[0043] In step S4, to enhance the model's ability to focus on key defect regions, a spatial attention module is embedded in the convolutional neural network branch of each sub-band. This module takes the branch input feature map as input and performs channel average pooling and channel max pooling operations in the channel dimension to extract two complementary spatial statistical features. These features are then concatenated in the channel dimension, and spatial nonlinear interaction and feature compression are performed using a 7×7 convolutional kernel. A two-dimensional attention weight map representing the spatial importance of the defect region is then generated using a sigmoid activation function. Finally, this weight map is combined with the original branch input feature map and subjected to a pixel-wise Hadamard product operation to strengthen the defect region response and suppress background interference. The introduction of the spatial attention mechanism enables the model to adaptively focus on the spatial location in each sub-band that contributes most to classification, improving the detection sensitivity for subtle defects and defects with blurred edges.
[0044] In step S5, after each sub-band convolutional neural network branch independently outputs the defect classification probability distribution vector, the traditional feature concatenation or simple weighted averaging fusion method is no longer used. Instead, a dynamic contribution weighted fusion strategy based on confidence level is introduced. Specifically, the system calculates the normalized discrimination confidence of each branch based on the maximum predicted probability and predicted information entropy of each branch's independent output. Then, a smoothness scaling factor controlled by weight evolution is introduced to numerically scale and adjust the normalized confidence, and an exponential transformation and proportional normalization are performed using a normalized exponential function to adaptively generate the dynamic contribution weights of each sub-band. Finally, the probability outputs of each branch are weighted and fused to obtain the comprehensive classification probability. The core advantage of this strategy is that the model can autonomously learn the optimal weight allocation scheme based on the actual discrimination contribution of each sub-band to different defect categories during training, avoiding redundant interference and noise amplification caused by direct feature concatenation, and realizing the adaptive organic fusion of multi-scale information.
[0045] In step S6, a streaming early stopping mechanism is designed to further improve inference efficiency. During the inference phase, the system sets a preset inference confidence threshold and a sliding window, and monitors the prediction output of adjacent parallel sub-band branches in real time. When the predicted category labels of multiple consecutive sub-band branches are completely consistent, and the arithmetic mean of the normalized discrimination confidence of all executed branches within the current sliding window reaches or exceeds the preset inference confidence threshold, the system determines that the current classification result has sufficient reliability and triggers the early stopping mechanism—terminating the forward propagation calculation of subsequent branches that have not yet been executed, and directly outputting the current defect category identification result. The design basis of this mechanism is that in the model's weight learning curve, the weight of the diagonal high-frequency sub-band is only about 0.05, and the effective discrimination information it carries is very little, mainly noise. The early stopping mechanism discards this part of redundant calculation while significantly reducing the average inference time, exchanging a significant efficiency improvement for a very small accuracy cost.
[0046] If the streaming early stop mechanism is not triggered during the inference process, the system determines the defect category based on the comprehensive classification probability generated in step S5, determines the target defect category index by selecting the maximum probability operator, outputs a high-confidence weld defect classification and identification decision result, and generates a credibility metric for the final classification decision by combining the normalized discrimination confidence, providing a reference for secondary manual review in engineering applications.
[0047] like Figure 2 As shown, this invention compares the performance of four methods—threshold segmentation, watershed segmentation, edge detection segmentation, and adaptive thresholding plus contour and line detection segmentation—for extracting regions of interest from the same X-ray image of a pipe weld. This comparison aims to visually demonstrate the performance differences between the various segmentation methods, providing visual support for the superiority of the adaptive thresholding plus contour and line detection segmentation strategy proposed in this invention.
[0048] Figure 2 The first row in the table represents threshold segmentation: a single global or local threshold is used to binarize the weld image. Because the grayscale difference between the defect and the background in the weld X-ray image is small, and there is significant grayscale inhomogeneity, the threshold segmentation method struggles to accurately distinguish the weld area from the background. The detection results show numerous fragmented noise patches (as shown in the second column), leading to blurred boundaries in the segmentation results (third column) and compromised weld area integrity, failing to provide a precise defect localization basis for subsequent frequency domain analysis.
[0049] Figure 2 The second row in the table shows watershed segmentation: based on morphological gradients and region growing principles, the image is treated as a terrain surface, and region segmentation is achieved by finding catchment basins and watershed lines. The watershed segmentation method produced significant oversegmentation in the detection results (second column). Although it could roughly locate the weld boundary (blue marker line), the boundary line was jagged and irregular, and redundant segmentation lines (red marker lines) were generated inside the weld. This resulted in the segmentation result (third column) preserving the overall weld area, but with insufficient edge accuracy, easily introducing background noise into the region of interest.
[0050] Figure 2 The third row in the table shows edge detection and segmentation: edge detection algorithms such as the Sobel operator are used to extract image edge information, and region filling is performed based on edge closure. Due to the presence of numerous subtle gray-level gradients and noise interference in the weld image, the edge detection method generates a large number of false and broken edges in the detection results (second column). This results in the segmentation results (third column) retaining only some discontinuous edge fragments, severely damaging the integrity of the weld region and failing to meet the quality requirements of subsequent deep learning models for input data.
[0051] Figure 2The fourth row in the table represents the adaptive thresholding and contour / line detection segmentation method proposed in this invention. This method first employs an adaptive thresholding strategy, dynamically adjusting the threshold based on local grayscale distribution to initially extract candidate weld regions (marked in green in the second column). The specific expression is as follows:
[0052]
[0053] Where T a (x,y) is the adaptive threshold function, μ1 is the local mean, C is a constant, I(x,y) is the region of interest image I of the weld defect, and B(x,y) is the binary segmentation result, where x and y are the coordinates of points in the image.
[0054] Secondly, the weld has specific geometric characteristics (elongated and continuous), and non-weld areas can be excluded through geometric constraints. Let the extracted contour be C=(C1,C2,...,C...). k To apply area constraints, the specific expression is as follows:
[0055]
[0056] Where A(C) i ) is the outline C i The area, A min This is the minimum area threshold.
[0057] The aspect ratio constraint for the weld is expressed as follows:
[0058]
[0059] Among them, w i h is the width of the bounding rectangle of the outline. i γ is the height of the bounding rectangle of the contour, and γ is the aspect ratio threshold.
[0060] The specific expression for constraining the compactness of the weld is as follows:
[0061]
[0062] Wherein, P(C) i ) represents the perimeter of the contour, and ɛ represents the compactness threshold.
[0063] Finally, the candidate contour set C is obtained through constraint filtering. w Contour filtering can accurately identify weld seam areas. The specific expression is as follows:
[0064]
[0065] Finally, the geometry of the weld can be inspected and corrected using line detection. First, the edge image E(x,y) is extracted, and the specific expression is as follows:
[0066]
[0067] in, For the Laplace operator, G σ For Gaussian kernel, R i (x,y) is the nodal displacement vector.
[0068] Then, the Hough transform parameter space is performed, with the specific expression as follows:
[0069]
[0070] ρ is the distance from the line in the image to the origin, and θ is the normal angle of the line.
[0071] The set of detected lines is L, and its specific expression is as follows:
[0072]
[0073] Where, ρ j Let θ be the distance from the j-th line in the image to the origin. j Let T be the normal angle of the j-th line. line This is the threshold for line detection.
[0074] Then, geometric consistency verification is performed, using the following expression:
[0075]
[0076] Among them, Ω i To match the i-th candidate contour R i A spatially related subset of straight lines.
[0077] If greater than T score (Geometric consistency threshold) indicates that the contour is indeed a long strip-shaped, approximately straight structure. Therefore, the region of interest image I for weld defects is output, and the specific expression is as follows:
[0078]
[0079] The detection results show that the adaptive threshold improves the local maladaptability of single-threshold segmentation to a certain extent, especially enhancing the adaptability to image illumination, and has a significant effect on the geometric constraints of contours. It detected over 99% of the weld seam areas, solving the detection problem caused by the uneven material distribution at the weld seam boundary to some extent. This demonstrates the superiority of the proposed adaptive threshold combined with contour and line detection segmentation method in the task of extracting regions of interest in weld seams. This method combines noise resistance, boundary accuracy, and region integrity, and is an important preliminary step for achieving high-precision weld seam defect identification in this invention.
[0080] Figure 3 This paper demonstrates the structural process by which a two-dimensional discrete wavelet transform decouples an input image I(x,y) into four independent frequency domain feature subbands. The mathematical implementation of this process is based on the Mallat fast wavelet transform algorithm. Through the tensor product of a one-dimensional scaling function φ(x) and a one-dimensional high-frequency wavelet basis function ψ(x), cascaded filtering and double-downsampling projection operations are performed in the horizontal (x-direction) and vertical (y-direction) directions of the image, respectively. This adaptively maps the spatial local energy of the image to four feature spaces with different frequency and directional characteristics.
[0081] Step 1: Horizontal scaling function filtering and high-pass wavelet filtering. First, in the horizontal direction, a one-dimensional low-frequency scaling function φ(x) and a one-dimensional high-frequency wavelet basis function ψ(x) are used to perform convolution filtering on each row of the input region of interest image I. Then, a 2x downsampling is performed, meaning one sampling point is retained for every other pixel, halving the amount of data in the horizontal direction. The horizontal low-pass filtering result is L. low (x, y), the smooth low-frequency components of the image are captured by the scaling function φ(x); the horizontal high-pass filtering result is L. high (x, y), the wavelet basis function ψ(x) captures the abrupt high-frequency components of the image. The above horizontal filtering process decouples the x-direction information of the original image into low-frequency and high-frequency components, laying the foundation for further decoupling in the vertical direction. The specific formula is as follows:
[0082]
[0083] Where m is the index of the discrete displacement spatial position coordinates in the horizontal direction.
[0084] Step 2: Vertical cascaded filtering and downsampling. After completing the horizontal filtering, L... low (x,y) and L high The two intermediate results (x, y) are then subjected to column convolution filtering and double downsampling in the vertical direction using the scaling function φ(x) and the one-dimensional high-frequency wavelet basis function ψ(x), respectively, to achieve frequency decoupling of the information in the y-direction. The specific formulas are as follows:
[0085]
[0086] Where n is the discrete displacement spatial coordinate index in the vertical direction, LL(x,y) is the low-frequency approximate subband, LH(x,y) is the horizontal low-frequency vertical high-frequency detail subband, HL(x,y) is the horizontal high-frequency vertical low-frequency detail subband, and HH(x,y) is the diagonal high-frequency detail subband.
[0087] Through the above cascaded filtering and downsampling operations, the spatial local energy of the image is adaptively mapped to four independent frequency domain feature sub-bands. The frequency and spatial characteristics of each sub-band are as follows:
[0088] The LL subband is obtained by filtering the image in both the horizontal and vertical directions using a low-pass filter. The specific formula is as follows:
[0089]
[0090] The LL subband is a projection of the original image into the low-frequency-low-frequency space, preserving the concentrated energy portion of the image and containing global structural information such as the overall outline of the weld area, the molten pool morphology, and the background grayscale distribution. The LL subband has a high mean, reflecting the overall grayscale level of the weld background. Since the LL subband transmits the vast majority of the image energy (statistically, the LL subband energy accounts for over 99.9% for all four types of defects), defects in the LL subband manifest as follows: regional defects such as porosity and inclusions are revealed through contrast between bright and dark areas, rather than relying on absolute brightness; linear defects such as cracks, although small in area, generate considerable structural disturbances by stretching the low-value tails of the grayscale distribution.
[0091] The LH subband is obtained by horizontal low-pass filtering and vertical high-pass filtering, as shown in the following formula:
[0092]
[0093] The LH sub-band is highly sensitive to abrupt changes in grayscale in the vertical direction, highlighting the vertical edge characteristics of longitudinal crack defects. Statistical analysis shows that the variance and energy of crack defects in the LH sub-band are several times higher than those in the HL and HH sub-bands, indicating a significant edge response of cracks in the horizontal direction, which is highly consistent with the geometric characteristics of cracks typically extending along the weld seam. The mean value in the LH sub-band is close to zero, indicating that isotropic defects such as porosity do not exhibit directional bias in this sub-band.
[0094] The HL subband is obtained through horizontal high-pass filtering and vertical low-pass filtering, as shown in the following formula:
[0095]
[0096] The HL sub-band primarily enhances edge information in the horizontal direction, exhibiting excellent responsiveness to transverse porosity and irregular variations in weld edges. Taking undercut defects as an example, this defect forms a continuous dark band along the weld edge, belonging to the geometric erosion type. In the HL sub-band, variance, energy, and entropy are all significantly higher than in the LH and HH sub-bands, demonstrating a significant vertical energy concentration characteristic, which is highly consistent with its geometric morphology—continuous along the weld direction but with a clear boundary in the vertical direction.
[0097] The HH subband is obtained by filtering the image in both the horizontal and vertical directions using a high-pass filter. The specific formula is as follows:
[0098]
[0099] The HH subband contains high-frequency information in the diagonal direction, capable of characterizing complex surface textures and randomly distributed small-scale defects in welds. Statistical analysis shows that the HH subband has the lowest energy among all defects, but its kurtosis values are generally high (porosity 4.898, cracks 4.994, inclusions 3.906, and undercut 3.703), indicating that the information in the HH subband exists in the form of sparse abrupt change points, mainly consisting of point anomalies and noise. Therefore, in the subsequent network design, the HH branch adopts a shallow network structure with small convolutional kernels and a strong regularization strategy, which can accurately capture the features of subtle local anomalies while suppressing high-frequency noise interference.
[0100] Tables 1 to 4 show the quantitative parameters of the four sub-zones: porosity, cracks, inclusions, and undercut.
[0101] Table 1. Parameters of each subzone of stomata
[0102]
[0103] Table 2 Parameters of each sub-zone of the crack
[0104]
[0105] Table 3 Parameters of each sub-band of inclusions
[0106]
[0107] Table 4. Parameters of each sub-band at the bite edge
[0108]
[0109] Figure 4 This is a diagram of the wavelet subband differential CNN feature extraction and adaptive weight fusion network architecture. In step S3, based on the frequency domain characteristic differences of the four subbands output in step S2, four differential convolutional neural network branches (LL-CNN, LH-CNN, HL-CNN, HH-CNN) are constructed to achieve collaborative extraction of multi-scale features.
[0110] The convolutional topology and feature capture targeting mapping design for each sub-band branch are as follows: The four sub-band images (LL, LH, HL, HH) output in step S2 are respectively fed into their corresponding CNN-Attention feature extraction modules. Considering the significant differences in frequency components, spatial structure, and defect representation capabilities among the sub-bands (as shown in Table 5 for the four-sub-band feature analysis), this invention abandons the traditional approach of using a unified CNN structure in multi-scale networks. Instead, it designs differentiated convolutional neural network branches for each sub-band, specifically: a low-frequency branch (LL-CNN), a vertical mutation feature extraction branch (LH-CNN), a horizontal mutation feature extraction branch (HL-CNN), and a diagonal high-frequency branch (HH-CNN), enabling the network to perform targeted feature extraction based on the physical characteristics of the sub-bands.
[0111] The low-frequency branch (LL-CNN) employs a deep topology consisting of multiple stacked standard convolutional and max-pooling layers. Specifically, the LL branch includes the following layers in sequence: a first layer of 3×3 convolutions (32 kernels); a second layer of 3×3 convolutions (32 kernels) with 2×2 max pooling; a third layer of 3×3 convolutions (64 kernels); a fourth layer of 3×3 convolutions (64 kernels) with 2×2 max pooling; and a fifth layer of 3×3 convolutions (128 kernels) with 1×1 adaptive average pooling. The 3×3 convolutional kernels are large-size filters (compared to the asymmetric 1×5 or 5×1 convolutional kernels in other branches), and the 2×2 max pooling expands the receptive field through downsampling. The design of this structure is based on the following: the LL subband retains the energy concentration part of the image (statistically, the energy proportion of the LL subband for all four types of defects is above 99.9%), with smooth feature changes, and contains global structural information such as the overall contour of the weld, the shape of the molten pool, and the background grayscale distribution; the combination of large convolutional kernels and deep networks can fully capture the macroscopic shape and grayscale field features of the target with fewer parameters, without relying on local sharp edges - which is highly consistent with the physical law that regional defects such as porosity and slag inclusions are revealed in the LL subband through the contrast of bright and dark areas (rather than absolute brightness or sharp edges).
[0112] Vertical abrupt change feature extraction branch (LH-CNN): Introduces asymmetric anisotropic horizontal enhancement convolutional kernel in conjunction with standard convolution. Specifically, the LH branch includes the following layers in sequence: a first layer of 1×5 convolution (32 kernels, horizontal strip enhancement kernel); a second layer of 3×3 convolution (32 kernels), 2×2 max pooling; a third layer of 1×5 convolution (64 kernels); and a fourth layer of 3×3 convolution (64 kernels), 1×1 adaptive average pooling. The 1×5 asymmetric convolutional kernel has a receptive field of 5 pixels horizontally and only 1 pixel vertically, enabling cross-pixel feature aggregation horizontally while preserving high-precision single-pixel localization vertically—this anisotropic design selectively enhances the gray-scale abrupt change response in the vertical direction of the image. The design of this structure is based on the fact that the LH subband is more sensitive to abrupt changes in grayscale in the vertical direction. Statistically, the variance (0.2495) and energy (4152.7778) of crack defects in the LH subband are orders of magnitude different from those in the HL and HH subbands, respectively, indicating that the geometric features of crack extension along the weld direction produce a significant edge response in the LH subband. Therefore, LH-CNN is specifically used to extract the defect abrupt edges of longitudinal cracks along the weld direction.
[0113] Horizontal Mutation Feature Extraction Branch (HL-CNN): Introduces asymmetric anisotropic vertical enhancement convolutional kernels in conjunction with standard convolutions. Specifically, the HL branch consists of the following layers: a first layer of 5×1 convolutions (32 kernels, vertical strip enhancement kernels); a second layer of 3×3 convolutions (32 kernels), with 2×2 max pooling; a third layer of 5×1 convolutions (64 kernels); and a fourth layer of 3×3 convolutions (64 kernels), with 1×1 adaptive average pooling. The 5×1 asymmetric convolutional kernels have a receptive field of 5 pixels vertically and only 1 pixel horizontally—forming a symmetrical complement to the 1×5 kernels of the LH branch. The design of this structure is based on the fact that the HL subbands primarily enhance edge and texture information in the horizontal direction. Taking undercut defects as an example, this defect forms a continuous dark band along the weld edge. The variance (0.2268) and energy (3776.7902) in the HL sub-band are both higher than those in the LH and HH sub-bands, exhibiting a significant vertical energy concentration characteristic. Therefore, HL-CNN is specifically used to extract defect features perpendicular to the weld direction, such as transverse slag inclusions and undercut. It should be noted that although both the LH and HL branches use asymmetric convolution kernels, their directions are orthogonal—the former enhances the response to abrupt changes in the horizontal weld direction, while the latter enhances the response to abrupt changes in the vertical weld direction. The two form a complementary targeted feature extraction system in the directional domain.
[0114] Diagonal High-Frequency Branch (HH-CNN): This branch employs a shallow network structure with multiple layers of small-sized convolutional kernels, followed directly by a strongly regularized dropout layer after the convolutional activation layers. Specifically, the HH branch consists of: a first layer of 3×3 convolutions (32 kernels); a second layer of 3×3 convolutions (32 kernels), a random dropout layer (dropout rate 0.4), and 2×2 max pooling; and a third layer of 3×3 convolutions (64 kernels) with 1×1 adaptive average pooling. The 3×3 convolutional kernels are small-sized filters, and the strongly regularized layer with a dropout rate of 0.4 randomly drops 40% of neuron responses during training. The design of this structure is based on the fact that the HH subband contains high-frequency information in the diagonal direction, which can characterize the complex texture of the weld surface and randomly distributed small-scale defects. However, statistical analysis shows that the HH subband has the lowest energy among all defects (porosity 740.5736, crack 719.8735, inclusion 989.4664), while the kurtosis values are generally high (porosity 4.898, crack 4.994, inclusion 3.906), indicating that the information in the HH subband exists in the form of sparse abrupt change points, mainly including point anomalies and noise. Small convolutional kernels are used to maintain the ability to capture fine textures at high resolution; the shallow structure avoids overlearning of noise by deep networks; and the strongly regularized dropout layer randomly suppresses neuronal responses during training, equivalent to model averaging in ensemble learning, reducing the risk of overfitting the model to high-frequency noise. Therefore, the HH branch achieves the design goal of accurately capturing point-like porosity and fine local anomaly features while suppressing high-frequency noise interference.
[0115] The structural design of the four CNN branches can be uniformly represented by the following sub-band feature extraction function, where the original feature map of any sub-band k is defined as:
[0116]
[0117] Among them, H k W represents the horizontal dimension of the original feature map of subband k. k represents the vertical dimension of the original feature map of subband k.
[0118] After attention-weighted enhancement, it yields the enhanced feature map I. zk The expression is:
[0119]
[0120] Where ⊙ represents the pixel-by-pixel Hadamard product operation, A k The spatial attention weights are expressed as follows:
[0121]
[0122] Among them, f 7×7 The kernel is a 7×7 convolution, σ is the sigmoid function that maps the weights to 0~1, and M... kavg and M k max The spatial description mapping value of the original feature map of the sub-band is expressed as:
[0123]
[0124] AvgPool is the average pooling operation, and MaxPool is the max pooling operation.
[0125] Step S3, by introducing differentiated CNN topologies and asymmetric convolution kernel designs, extends the advantages of wavelet frequency domain decoupling from the signal processing level to the feature learning level, achieving targeted feature extraction of weld defects at different frequencies and directions. Experimental verification shows that after replacing the four uniform low-frequency CNNs with the four differentiated sub-band dedicated CNNs mentioned above, the four-class classification accuracy improved from 80.01% to 84.63%, verifying the effectiveness of the sub-band differentiated CNN design.
[0126] Table 5. Analysis of Four Subband Characteristics
[0127]
[0128] Figure 5 The flowchart below illustrates the workflow of four-sub weighted fusion and early stopping mechanism. Figure 5 The confidence dynamic weighted fusion process in step S5 and the streaming early stopping mechanism in step S6 are described in detail.
[0129] The four sub-bands obtained from wavelet decomposition in step S2 are respectively processed by their corresponding CNN-Attention modules to obtain the classification probability output P. k The specific expression is:
[0130]
[0131] Where, p k (1) p is the predicted probability that the k-th subband belongs to a stomatal. k (2) p is the predicted probability that the k-th subband belongs to the crack. k (3) Let p be the predicted probability that the k-th sub-band belongs to the slag inclusion. k (4) Let be the predicted probability that the k-th subband belongs to the bit edge.
[0132] This model introduces a primary discrimination confidence level based on maximum probability. A higher confidence level indicates greater confidence in the prediction results for that subband. Its expression is:
[0133]
[0134] Where, γ k Let c be the maximum confidence level of the k-th subband, and c be 1, 2, 3, or 4.
[0135] To further utilize the prior information in the sub-band images, a prediction information entropy H is introduced. k This is used to supplement and calibrate the confidence level. A higher information entropy indicates a more uniform probability distribution and a less stable model; conversely, a lower information entropy indicates a more concentrated probability distribution and a more deterministic model. Its expression is:
[0136]
[0137] The normalized discrimination confidence γ is obtained by jointly calibrating the primary discrimination confidence score and the predicted information entropy. gk The expression is:
[0138]
[0139] Where C is the total number of categories.
[0140] The self-learning dynamic contribution weights of each sub-band are adaptively generated by their normalized discriminative confidence scores through a normalized exponential function (Softmax function). Specifically, a smoothness scaling factor β is introduced to control the weight evolution. After numerical scaling adjustment of the normalized confidence scores of each sub-band, the scores are fed into the normalized exponential function for exponential transformation and proportional normalization operations. Its expression is:
[0141]
[0142] Among them, w k β represents the dynamic contribution weight of the k-th sub-band, and β is a scaling factor that controls the smoothness of the weights.
[0143] By calculating the self-learning dynamic contribution weights of each sub-band, the probability distribution vectors of the independent outputs of each sub-band are weighted and fused to obtain the comprehensive classification probability:
[0144]
[0145] P fusion This is the weighted and fused comprehensive classification probability distribution vector.
[0146] The core advantage of this fusion method lies in the fact that the model can autonomously learn the optimal weight allocation scheme during training based on the actual discriminative contribution of each subband to different defect categories. This avoids redundant interference and noise amplification caused by direct feature concatenation, achieving adaptive and organic fusion of multi-scale information. Finally, the target defect category index is determined through the maximum probability selection operator.
[0147]
[0148] Where y y The index for the final predicted defect category (c is 1, 2, 3 and 4, corresponding to porosity, cracks, inclusions and undercut respectively).
[0149] In step S6, the streaming early stopping mechanism is a dynamic computation strategy based on uncertainty control. Its core objective is not simply to pursue maximum inference speed, but to significantly improve overall inference efficiency and reduce the risk of model overfitting, while minimizing or eliminating any impact on inference accuracy. The specific constraints triggering this mechanism are as follows:
[0150] During the inference phase, the system sets a preset inference confidence threshold τ and a sliding window of length m. It monitors in real-time the predicted class index of the current input sample as it passes through the maximum selection operator in adjacent parallel sub-band branches. Let y be the predicted class index of the k-th sub-band. y(k) The category index predicted for the (k+1)th sub-band is y. y(k+1) When the predicted categories of these two adjacent sub-bands are completely identical, i.e., y y(k) =y y(k+1) If so, the category consistency condition is initially met.
[0151] Based on the assumption of class consistency, the system further verifies the confidence necessity condition. It calculates the arithmetic mean of the normalized discrimination confidence scores of all executed branches within the current sliding window (from the k-th to the (k+m-1)-th). When this mean reaches or exceeds a preset inference confidence threshold τ, the system determines that the confidence necessity constraint is satisfied. The mathematical expression for this determination process is:
[0152]
[0153] When both of the above conditions—category consistency (adjacent subbands predict the same category) and confidence sufficiency (sliding window average confidence ≥ τ)—are met simultaneously, the system immediately triggers the streaming early stop mechanism: cutting off the forward propagation link, terminating the forward calculation of subsequent branches that have not yet been executed, and directly outputting the current defect classification result.
[0154] The design of this mechanism is based on the following: From a decision theory perspective, when the subband discrimination probability distribution exhibits a significant "peaking" characteristic, its corresponding information entropy is already at a low level. Introducing information from other subbands offers limited gain for the final decision and may even introduce noise interference. Experimental data shows that the weight of the HH subband is only 0.05, carrying very little effective discrimination information and primarily consisting of noise. The early stopping mechanism significantly reduces the average inference time while discarding this redundant computation.
[0155] Finally, if the streaming early stopping mechanism is not triggered during the inference process (i.e., the simultaneous triggering condition is not met), the system will proceed based on the comprehensive classification probability P generated in step S5. fusion The defect category is determined by using the maximum probability selection operator to identify the target defect category index and output a high-confidence weld defect classification and identification decision result.
[0156] To verify the effectiveness of the early stopping mechanism design, this embodiment conducts comparative experiments by setting different early stopping thresholds (τ=0.5, 0.6, 0.7, 0.8, 0.9). Experimental results show that when τ=0.5, the model accuracy is 80.13% and the average inference time is 15.23ms; when τ=0.9, the model accuracy is 89.59% and the average inference time is 18.01ms. Balancing these two factors, the optimal early stopping threshold for the model is τ=0.9. At this threshold, the early stopping mechanism achieves a minimal loss of 0.38% accuracy (from 89.97% to 89.59%) in exchange for a significant improvement in inference time of 3.98ms (from 21.99ms to 18.01ms). This fully verifies the effectiveness of the mechanism in significantly reducing the average inference time while maintaining essentially unchanged classification accuracy, significantly improving the model's engineering practicality and deployment value in actual weld defect detection systems.
[0157] The beneficial effects of this invention are as follows: This invention utilizes two-dimensional discrete wavelet transform to decouple weld X-ray images into four sub-bands with different directional characteristics in the frequency domain. This achieves effective frequency domain separation of various defect features, such as macroscopic morphology, edges along the weld direction, edges perpendicular to the weld direction, and fine textures. Furthermore, it constructs differentiated parallel convolutional neural network branches based on the frequency domain characteristics of each sub-band. The low-frequency branch uses large-size convolutional kernels to extract macroscopic contour features, while the vertical and horizontal abrupt change branches enhance edge features in specific directions using anisotropic convolutional kernels. The diagonal high-frequency branch uses small-size convolutional kernels to capture subtle anomalies. This reveals the differentiated representation mechanism of defect features at the frequency domain level, improves model interpretability, and solves the problem that traditional single-scale models cannot simultaneously take into account macroscopic structure and microscopic edge information. Simultaneously, a spatial attention mechanism is embedded within each branch, generating a two-dimensional spatial attention weight map by splicing dual-channel features using channel average pooling and max pooling. This drives the model to adaptively focus on spatial locations within each sub-band that contribute significantly to discrimination. During the fusion stage, a dynamic adaptive weight fusion strategy based on predicted information entropy and confidence is employed, abandoning the traditional simple splicing and fixed weighted average mode. The weight allocation is autonomously adjusted according to the actual discrimination capability of each sub-band for different defect types, completing multi-scale information adaptive fusion and improving the detection sensitivity of subtle defects and blurred-edge defects. Furthermore, this invention proposes a streaming early-stop mechanism with dual constraints of category consistency and confidence. During the inference stage, the consistency and confidence of outputs from adjacent sub-band branches are monitored in real time. Once the preset constraints are met, the forward computation of subsequent branches is truncated, and the classification result is output. While ensuring classification accuracy, this eliminates the need for full computation of all sub-band branches, significantly improving inference efficiency and making it more suitable for industrial online inspection scenarios.
[0158] Finally, it should be noted that the above specific embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to examples, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications and substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A wavelet frequency domain decoupling and attention-based weld defect identification method, characterized in that, The method includes the following steps: Step S1: Obtain X-ray images of pipe welds, perform Gaussian filtering for noise reduction and contrast-limited adaptive histogram equalization, extract candidate contour sets using adaptive threshold segmentation and spatial geometric constraints, and perform edge consistency verification using Hough transform, segment and output the region of interest image I of weld defects. Step S2: Select a specified discrete wavelet basis to perform a single-layer two-dimensional discrete wavelet transform on the region of interest image I, and decouple it in the frequency domain into a low-frequency approximate subband, a horizontal low-frequency vertical high-frequency detail subband, a horizontal high-frequency vertical low-frequency detail subband, and a diagonal high-frequency detail subband; Step S3: Based on the frequency domain characteristics of each sub-band, construct differentiated parallel convolutional neural network branches. The low-frequency branch uses large-size convolutional kernels to extract macroscopic contour features. The vertical abrupt change feature extraction branch targets the horizontal low-frequency and vertical high-frequency detail sub-bands and uses anisotropic convolutional kernels to extract longitudinal defect features along the weld direction. The horizontal abrupt change feature extraction branch targets the horizontal high-frequency and vertical low-frequency detail sub-bands and uses anisotropic convolutional kernels to extract transverse defect features perpendicular to the weld direction. The diagonal high-frequency branch uses small-size convolutional kernels to extract subtle defect features. Step S4: Embed a spatial attention module in the convolutional neural network branch of each sub-band, perform channel average pooling and channel max pooling on the channel dimension and concatenate them, generate a two-dimensional spatial attention weight map by mapping through a convolutional layer of preset size and activation function, and then perform pixel-wise Hadamard product operation with the branch input feature map to enhance features. Step S5: Each sub-band convolutional neural network branch independently outputs the defect classification probability distribution vector. The normalized discrimination confidence of each branch is calculated by combining the maximum prediction probability and the prediction information entropy. The dynamic contribution weight of each sub-band is generated by using the normalized exponential function. The probability outputs of each branch are weighted and fused to obtain the comprehensive classification probability. Step S6: Set the inference confidence threshold and a sliding window of a preset length. If the predicted branches of multiple consecutive sub-bands output the same category, and the arithmetic mean of the normalized discrimination confidence of all executed branches within the sliding window reaches or exceeds the inference confidence threshold, then the streaming early stop mechanism is triggered to terminate the forward propagation of subsequent branches that have not yet been executed, and the current defect category identification result is directly output. If the arithmetic mean of the normalized discrimination confidence of all executed branches within the sliding window does not reach the inference confidence threshold, then the streaming early stop mechanism is not triggered. The defect category is determined based on the comprehensive classification probability, the target defect category index is determined by the maximum probability selection operator, a high-probability weld defect classification identification decision result is output, and the confidence metric of the final classification decision is generated in combination with the normalized discrimination confidence.
2. The wavelet frequency domain decoupling and attention weld defect identification method according to claim 1, characterized in that: In step S1, the specific implementation process of adaptive threshold segmentation and spatial geometric constraint extraction of candidate contour set screening is as follows: extract the closed contours in the initial image segmentation stage and calculate their area, the width and height of the circumscribed rectangle, and the contour perimeter; compare the area with a preset minimum area threshold, compare the ratio of the maximum side length to the minimum side length in the width and height of the circumscribed rectangle with a preset aspect ratio threshold, and calculate the compactness index based on the ratio of the contour area to the square of the perimeter and compare it with a preset compactness threshold. Combine the effectiveness screening of the candidate contour set and remove invalid contours that do not meet any threshold constraint.
3. The wavelet frequency domain decoupling and attention weld defect identification method according to claim 1, characterized in that: In step S2, the frequency domain decoupling process is as follows: using a one-dimensional low-frequency scaling function and a one-dimensional high-frequency wavelet basis function, cascaded filtering and downsampling projection operations are performed in the horizontal and vertical directions of the input region of interest image I, respectively; the spatial local energy of the image is adaptively mapped to the low-frequency approximate feature space, the horizontal low-frequency and vertical high-frequency detail feature space, the horizontal high-frequency and vertical low-frequency detail feature space, and the diagonal high-frequency detail feature space, thereby outputting four independent frequency domain feature sub-bands in discrete displacement spatial coordinates.
4. The wavelet frequency domain decoupling and attention weld defect identification method according to claim 1, characterized in that: In step S3, based on the frequency domain characteristics of each sub-band, differentiated parallel convolutional neural network branches are constructed, including: low-frequency branch, vertical mutation feature extraction branch, horizontal mutation feature extraction branch, and diagonal high-frequency branch. The low-frequency branch adopts a topology structure consisting of multiple layers of standard convolution and max pooling layers stacked together, which is used to extract the overall morphology structure of the weld and the gray field features of the macro environment that do not depend on local sharp edges. The vertical mutation feature extraction branch introduces an asymmetric anisotropic horizontal enhanced convolution kernel in conjunction with standard convolution to selectively enhance the gray-level mutation response in the vertical direction of the image, which is specifically used to extract the defect mutation edges of longitudinal cracks. The horizontal mutation feature extraction branch introduces an asymmetric anisotropic vertical direction enhancement convolution kernel in conjunction with standard convolution to selectively enhance the detail information in the horizontal direction of the image, which is specifically used to extract the features of horizontal inclusions and edge bite defects. The diagonal high-frequency branch employs multiple small-sized convolution kernels, and a strongly regularized dropout layer is directly connected in series after the convolution activation layer. This is used to accurately capture point-like pores and micro-fine local anomaly features while suppressing high-frequency noise interference within the subband.
5. The wavelet frequency domain decoupling and attention weld defect identification method according to claim 1, characterized in that: In step S4, a spatial attention module is embedded in the convolutional neural network branch of each sub-band. The specific process is as follows: the input feature map of the corresponding sub-band branch is used as the spatial input, and different spatial statistical features are extracted by channel average pooling and max pooling operations respectively; the average feature and the maximum feature after pooling are concatenated in the channel dimension, and spatial nonlinear interaction and feature compression are performed by a 7×7 convolution kernel, and then extreme value mapping is performed by a sigmoid activation function to generate a two-dimensional spatial attention weight map that can characterize the spatial importance of the defect region; finally, the weight map and the corresponding branch input feature map are subjected to pixel-wise Hadamard product operation to output the enhanced sub-band feature map.
6. The wavelet frequency domain decoupling and attention weld defect identification method according to claim 1, characterized in that: In step S5, the calculation process of dynamic contribution weight is as follows: First, based on the defect prediction probability distribution output by each parallel decoupling branch, calculate the prediction information entropy corresponding to each branch, and combine the maximum prediction probability of each branch to calibrate and normalize the primary discrimination confidence of the current branch. Subsequently, a smoothness scaling factor with weight evolution control is introduced to numerically scale and adjust the normalized confidence score, and then fed into a normalized exponential function for exponential transformation and proportional normalization operations, adaptively outputting the dynamic contribution weights of each branch feature to the final decision.
7. The wavelet frequency domain decoupling and attention weld defect identification method according to claim 1, characterized in that: In step S6, the streaming early stopping mechanism is as follows: During the inference process, the predicted category index of the current input sample is monitored in real time through the maximum selection operator on adjacent parallel sub-band branches; when the defect maximum probability corresponding to the category predicted by the adjacent branches is completely consistent, and the arithmetic mean of the normalized discrimination confidence of all executed branches in the current sliding window reaches or exceeds the inference confidence threshold, it is determined that the category consistency and confidence necessity constraints are satisfied at the same time, and then the forward propagation is cut off and the streaming early stopping mechanism is triggered to terminate the forward calculation of subsequent branches that have not yet been executed, and the current defect classification result is directly output.
8. A wavelet frequency domain decoupling and attention-based weld defect identification system, used to implement the method described in any one of claims 1 to 7, characterized in that, It includes a region of interest segmentation module, a two-dimensional discrete wavelet frequency domain decoupling module, a four-branch feature extraction neural network module, a spatial attention weighting module, a confidence dynamic weighted decision module, a streaming early stop determination and control unit, and a decision classification output module; The region of interest segmentation module is used to acquire X-ray images of pipe welds, segment them, extract them, and output the region of interest image I of weld defects; The two-dimensional discrete wavelet frequency domain decoupling module is used to select a specified discrete wavelet basis to perform a single-layer two-dimensional discrete wavelet transform on the region of interest image I, and decouple it in the frequency domain into a low-frequency approximate sub-band, a horizontal low-frequency vertical high-frequency detail sub-band, a horizontal high-frequency vertical low-frequency detail sub-band, and a diagonal high-frequency detail sub-band. The four-branch feature extraction neural network module is used to construct differentiated parallel convolutional neural network branches, including a low-frequency branch, a vertical mutation feature extraction branch, a horizontal mutation feature extraction branch, and a diagonal high-frequency branch, which extract the corresponding geometric shape and detail texture features for the four sub-bands respectively. The spatial attention weighting module is used to embed spatial attention modules in each sub-network branch. It generates a spatial attention weight map by concatenating dual-channel pooling features and compressing them through convolution. The weight map is then enhanced by performing a pixel-wise Hadamard product operation with the feature map. The confidence dynamic weighted decision module is used to combine the defect classification probability distribution vectors independently output by each sub-band convolutional neural network branch, calculate the normalized discrimination confidence of each branch based on its maximum prediction probability and prediction information entropy, generate the dynamic contribution weight of each branch using the normalized exponential function, and perform weighted fusion of the prediction outputs of each branch to generate the comprehensive classification probability. The streaming early stop determination control unit is used to monitor the output results of adjacent activated branches in real time within the inference sliding window. When the class consistency of the continuous prediction results and the necessity of the average confidence both meet the preset threshold, early stop is directly triggered to block the forward propagation of subsequent unactivated branches. The decision classification output module is used to perform the maximum selection operator on the weighted fusion comprehensive classification probability when the streaming early stop determination control unit does not trigger early stop or completes all branch calculations, and adaptively outputs the final defect identification classification result.