Weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction

By employing adaptive image preprocessing, hybrid parallel feature extraction, and contrastive learning, the accuracy and reliability of weld seam X-ray image defect detection are improved. This approach addresses issues related to multi-scale, weak contrast, and category similarity, achieving highly reliable automated rating.

CN122289241APending Publication Date: 2026-06-26UNIV OF SCI & TECH BEIJING
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
UNIV OF SCI & TECH BEIJING
Filing Date
2026-04-20
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

Existing weld seam X-ray image defect detection models suffer from insufficient detection accuracy and reliability when faced with challenges such as multi-scale, weak contrast, and inter-category similarity, making it difficult to achieve highly reliable automated rating.

Method used

An end-to-end detection framework is constructed by employing an adaptive image preprocessing module, a hybrid parallel feature extraction network, and an auxiliary loss function based on contrastive learning. The detection accuracy is improved by adaptively enhancing image quality, parallel feature extraction, and feature discriminative optimization.

Benefits of technology

It significantly improves the accuracy and reliability of weld defect detection, better identifies multi-scale and low-contrast defects, reduces inter-class misclassification, and achieves high-quality automated rating.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122289241A_ABST
    Figure CN122289241A_ABST
Patent Text Reader

Abstract

This invention discloses a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction, belonging to the field of industrial non-destructive testing technology. The method includes: preprocessing a weld X-ray image dataset to construct training and testing sets; constructing an adaptive image preprocessing module based on gating mechanisms and hybrid control, building a hybrid parallel feature extraction network, and constructing an auxiliary loss function based on contrastive learning; constructing an end-to-end detection framework for X-ray weld image defect detection based on the adaptive image preprocessing module, the hybrid parallel feature extraction network, and the auxiliary loss function; training the end-to-end detection framework based on the training set and validating it based on the testing set to obtain a trained weld defect detection model; and performing defect detection on the X-ray weld image to be detected based on the trained weld defect detection model to obtain the detection result. This invention alleviates the technical problems of insufficient detection accuracy and reliability in existing technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial nondestructive testing technology, and in particular to a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction. Background Technology

[0002] Welding technology is a key joining process in modern industrial manufacturing, and its quality directly affects the product safety and operational reliability of strategic fields such as aerospace, oil and gas pipelines, and heavy equipment. X-ray nondestructive testing (NDT), as a conventional technique for assessing the internal quality of welds, is increasingly being incorporated into inspection models to achieve automated or assisted defect rating, thereby improving inspection efficiency and stabilizing inspection quality. Here, rating refers to classifying weld quality according to standards such as 47013, based on the type, quantity, location, and size of defects detected by the inspection model. However, due to challenges such as the diverse morphology and scale of weld defects, weak contrast between defects and background, and small defect size, the accuracy of existing general-purpose target inspection models in X-ray weld image defect detection is very limited, and inspection accuracy is a core factor determining the reliability and stability of the rating. Therefore, improving inspection accuracy plays a crucial role in achieving highly reliable automated rating.

[0003] With the development of deep learning technology, automated defect detection based on object detection has gradually become a research hotspot in the field of weld X-ray image analysis. However, weld defect detection in industrial scenarios still faces multiple challenges, directly restricting the detection accuracy and reliability of existing models. Currently, improving defect detection accuracy mainly faces the following challenges: First, defects exhibit significant scale variations and complex morphological features. Welding defects in industrial X-ray images are diverse; for example, slag inclusions typically appear as large, blocky areas, pores as tiny circular regions, and cracks as elongated linear structures. This scale variation makes it difficult for features at a single scale to simultaneously cover all defect types. While current general object detection models commonly employ feature pyramid network structures for multi-scale feature fusion, such methods still struggle to maintain the stability and consistency of feature representation across a large scale when fusing deep semantic information with shallow detail features.

[0004] Secondly, defects often exhibit weak contrast with the background, and some defects are quite small. Accurate defect identification relies not only on subtle features such as local texture and edges but also on the surrounding global context to eliminate background interference. However, while mainstream convolutional neural network backbones expand their receptive fields through layer-by-layer downsampling to capture global semantic information, they inevitably lose a significant amount of local detail crucial to minute defects. Existing research attempts to enhance feature representation by introducing attention mechanisms or designing more complex feature fusion modules, but these improvements primarily affect the backend of feature extraction and cannot fundamentally compensate for the detail loss caused by the backbone network during the feature extraction stage.

[0005] Furthermore, the high similarity in visual features among some defect categories can easily lead to misclassification. For example, incomplete fusion and incomplete penetration defects have similar grayscale distributions and morphological structures in X-ray weld images, making it difficult for the model to form clear category decision boundaries when strong discriminative features are lacking. While traditional classification loss functions (such as cross-entropy loss functions) can guide the model to distinguish between different categories, they lack explicit constraints on intra-class compactness and inter-class separability in the feature space. This results in insufficient classification confidence when the model faces similar categories, thus affecting detection accuracy. Summary of the Invention

[0006] To address the aforementioned technical problems in existing technologies, embodiments of the present invention provide a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction. The technical solution is as follows: On the one hand, a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction is provided. The method includes: preprocessing a weld X-ray image dataset to construct a training set and a test set; constructing an adaptive image preprocessing module based on gating mechanism and hybrid control, constructing a hybrid parallel feature extraction network, and constructing an auxiliary loss function based on contrastive learning; constructing an end-to-end detection framework for X-ray weld image defect detection based on the adaptive image preprocessing module, the hybrid parallel feature extraction network, and the auxiliary loss function; training the end-to-end detection framework based on the training set and validating it based on the test set to obtain a trained weld defect detection model; and performing defect detection on the X-ray weld image to be detected based on the trained weld defect detection model to obtain the detection result.

[0007] Optionally, the adaptive image preprocessing module includes multiple serial filters and parameter prediction networks, wherein each filter corresponds to a learnable gating weight, and the image is updated using residual gating when passing through each filter; the parameter prediction network includes a lightweight convolutional neural network for end-to-end prediction of the filter parameters and corresponding gating weights; the adaptive image preprocessing module also includes a global mixing control factor for balancing the contributions of the original image and the enhanced image; the output of the adaptive image preprocessing module includes:

[0008] In the formula, This refers to the global hybrid control factor. and These are the input and output of the plurality of serial filters, respectively. This is the output of the adaptive image preprocessing module.

[0009] Optionally, the filter includes: a white balance correction filter, a gamma correction filter, a tone remapping filter, a contrast enhancement filter, and a sharpening enhancement filter.

[0010] Optionally, the hybrid parallel feature extraction network includes a backbone convolutional neural network and a parallel feature extraction branch; wherein, the backbone convolutional neural network is used to extract global semantic information of the image to obtain a feature map; the parallel feature extraction branch is used to: perform multi-scale slicing processing on the feature map in the spatial dimension to obtain multiple image patches of different sizes corresponding to multiple levels; perform filtering operations based on local neighborhood consistency on the multiple image patches respectively to obtain multiple filtered image patches; reconstruct the features of the multiple filtered image patches to obtain a parallel branch feature map; the parallel branch feature map is aligned with the feature map in the channel dimension; the output of the hybrid parallel feature extraction network is a fused feature map after fusing the feature map and the parallel branch feature map.

[0011] Optionally, filtering operations based on local neighborhood consistency are performed on the plurality of image blocks respectively, including: calculating the average value of all pixels in the central neighborhood of each image block, and using the average value as the reference feature of the central neighborhood of each image block; calculating the absolute deviation of each pixel in each image block from the corresponding reference feature; if the absolute deviation exceeds a preset hyperparameter threshold, the corresponding pixel is retained, otherwise the response value of the corresponding pixel is set to zero; wherein, the preset hyperparameter threshold is determined based on statistical analysis of the difference in grayscale between defective regions and the background in the dataset.

[0012] Optionally, constructing an auxiliary loss function based on contrastive learning includes: using the InfoNCE loss function as the optimization objective of contrastive learning to construct a contrastive loss function; constructing positive and negative sample pairs using features extracted from the Transformer decoder of Co-DETR and multiple auxiliary decoders; combining the contrastive loss function with the original detection loss function of the detection task to construct an auxiliary loss function based on contrastive learning, and introducing the auxiliary loss function into the Co-DETR framework for training.

[0013] On the other hand, an electronic device is also provided, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method provided in the embodiments of the present invention.

[0014] On the other hand, a computer-readable storage medium is also provided, wherein program code is stored in the computer-readable storage medium, and the program code can be called by a processor to execute the method provided in the embodiments of the present invention.

[0015] This invention provides a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction. By introducing an adaptive image preprocessing module with a gating mechanism, the signal-to-noise ratio of the input image is improved from the source, highlighting defect features. By designing parallel feature extraction branches, fine-grained details lost by the backbone network are explicitly captured and preserved. At the same time, a contrast-based auxiliary loss function is introduced to enhance the compactness within classes and the separation between classes in the feature space. This alleviates the technical problems of insufficient detection accuracy and reliability in existing technologies. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart of a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction provided by an embodiment of the present invention; Figure 2 This is a schematic diagram of the overall architecture of a weld defect detection model provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the processing flow of an adaptive image preprocessing module provided in an embodiment of the present invention; Figure 4 This is a flowchart illustrating a parallel feature extraction branch provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the construction process of a comparative auxiliary loss provided by an embodiment of the present invention; Figure 6 This is a schematic diagram of the detection results of different models under different weld defect categories provided in an embodiment of the present invention. Detailed Implementation

[0018] The technical solution of the present invention will now be described with reference to the accompanying drawings.

[0019] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.

[0020] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.

[0021] Figure 1 This is a flowchart of a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction according to an embodiment of the present invention. Figure 1 As shown, the method specifically includes the following steps: Step S102: Preprocess the weld X-ray image dataset to construct training and test sets respectively.

[0022] Step S104: Construct an adaptive image preprocessing module based on gating mechanism and hybrid control, construct a hybrid parallel feature extraction network, and construct an auxiliary loss function based on contrastive learning.

[0023] Step S106: Based on the adaptive image preprocessing module, the hybrid parallel feature extraction network, and the auxiliary loss function, an end-to-end detection framework for X-ray weld image defect detection is constructed.

[0024] Step S108: Train the end-to-end detection framework based on the training set and validate it based on the test set to obtain the trained weld defect detection model.

[0025] Step S110: Based on the trained weld defect detection model, perform defect detection on the X-ray weld image to be detected, and obtain the detection result.

[0026] Figure 2 This is a schematic diagram of the overall architecture of a weld defect detection model provided according to an embodiment of the present invention. Figure 2As shown, the model consists of three collaborative stages: input augmentation, feature extraction, and loss optimization. The overall processing flow is as follows: The input image first enters the Adaptive Image Preprocessing (APM) module. This module dynamically analyzes the image content using a lightweight neural network, adaptively generating the optimal combination of enhancement parameters to improve the image's signal-to-noise ratio from the source, making defect features more prominent. The enhanced image is then fed into a hybrid parallel feature extraction network: the main path is a standard convolutional neural network backbone responsible for extracting rich global semantic information; the other path is a parallel feature extraction branch (ResPatch), which explicitly captures and retains fine-grained details lost during downsampling by the backbone network through multi-scale slicing, local filtering, and feature reconstruction. The features from the two paths are fused at multiple scales to form a hybrid feature representation that balances global semantics and local details. Finally, the fused features are fed into a Transformer decoder with multiple auxiliary heads for object detection. During the training phase, an InfoNCE-based contrastive auxiliary loss function is introduced, utilizing the multi-detector head structure to construct positive and negative sample pairs, optimizing the discriminative power of the feature space, and effectively improving the model's ability to distinguish easily confused defects.

[0027] The three modules mentioned above work together from different dimensions: the adaptive preprocessing module addresses the fundamental constraint of input image quality on detection performance, the parallel feature extraction branch compensates for the information loss in the backbone network, and the contrastive auxiliary loss enhances the discriminative power of the features. The specific implementation steps of each module are explained in detail below.

[0028] In industrial X-ray weld inspection, image quality directly restricts the accuracy of subsequent defect identification. In actual production environments, due to factors such as fluctuations in radiation dose, differences in workpiece thickness, and scattering noise, the original weld images often suffer from insufficient contrast, uneven brightness, and blurred edges, causing defects such as cracks and porosity to be submerged in the complex background. Traditional image enhancement methods (such as histogram equalization and fixed-parameter gamma correction) can improve the visual effect to some extent, but they often employ a globally uniform transformation strategy, which is difficult to adapt to the local characteristics of different images and regions. They may even amplify noise or introduce artifacts, which is detrimental to the accurate extraction of defects.

[0029] To address the aforementioned technical problems, this invention proposes an adaptive image preprocessing module based on deep learning. The core idea is to utilize a lightweight neural network to analyze the input image in real time, dynamically determining the most suitable combination of enhancement parameters for that image, thereby achieving refined enhancement tailored to the specific image. This method is inspired by the manual adjustment of window width and level by professional film critics based on differences in image brightness and contrast. The aim is to transform this experiential knowledge into a learnable model, improving the signal-to-noise ratio of the input image from the source, making defect features more prominent, and providing high-quality input for subsequent feature extraction.

[0030] Figure 3 This is a schematic diagram of the processing flow of an adaptive image preprocessing module according to an embodiment of the present invention. Figure 3 As shown, the adaptive image preprocessing module includes multiple serial filters and parameter prediction networks, where each filter corresponds to a learnable gating weight, and the image is updated using residual gating when passing through each filter.

[0031] Specifically, in traditional serial filter chains, each filter is applied to the image in a fixed order during image processing. This lacks the ability to determine whether the current image is suitable for the filter, easily leading to ineffective enhancement or even error accumulation. To address this issue, this invention introduces a learnable gating weight for each filter. Its value ranges from 0 to 1 and is obtained by mapping from the sigmoid function. The image is updated using residual gating as it passes through each filter:

[0032] In the formula, This represents the k-th filter. Let be the parameters of the k-th filter. This mechanism allows the model to adaptively determine the contribution of each filter based on the image content: when the gate weights are close to 0, the filter's effect is suppressed, and the image remains almost unchanged; when the weights are close to 1, the filter is fully effective. In this way, the model can dynamically select the most effective filter combination for enhancing current image defects, effectively avoiding redundant or harmful enhancement paths, while reducing the coupling risk of serial structures and improving training stability.

[0033] Preferably, the parameter prediction network includes a lightweight convolutional neural network for end-to-end prediction of filter parameters and corresponding gating weights.

[0034] Specifically, to enable the enhancement parameters to be dynamically adjusted according to the image content, this invention designs a lightweight convolutional neural network. This is used to predict the parameters of all filters end-to-end. To avoid excessive computational overhead, the input image is first... Downsample to a fixed size (256×256) to obtain a thumbnail. .network by The input is the filter parameter, and the output contains all filter parameters. and gating weight parameters The set of:

[0035] Furthermore, by using constraint functions, the generated parameters are ensured to conform to the basic principles of image enhancement, avoiding distortion. This prediction network enables the entire preprocessing module to be integrated into the training process of the object detection model, achieving joint optimization.

[0036] In the early stages of model training, unstable enhancement strategies may disrupt the original image structure and interfere with the learning of the backbone network. Therefore, the adaptive image preprocessing module in this embodiment introduces a global hybrid control factor. This is used to balance the contributions of the original image and the enhanced image.

[0037] Specifically, the output of the adaptive image preprocessing module includes:

[0038] In the formula, As a global mixed control factor, and These are the input and output of multiple serial filters, respectively. This is the output of the adaptive image preprocessing module. It is obtained by mapping the learnable parameter β through the sigmoid function. During initialization, β is set to a negative number, so that... The value is close to 0, even though the model relies more on the original image in the initial stage; as training progresses, the model can automatically adjust according to the gradient. The enhancement effect is gradually introduced by adjusting the values. This design effectively avoids the interference of unstable enhancement in the early stage of training on feature extraction, and improves the robustness of the module.

[0039] Based on the analysis of the characteristics of weld X-ray images, this invention selects several filters that are crucial for defect enhancement and dynamically adjusts their parameters using the aforementioned adaptive mechanism. Preferably, the filters include: a white balance correction filter, a gamma correction filter, a tone remapping filter, a contrast enhancement filter, and a sharpening enhancement filter.

[0040] Specifically, the white balance correction filter (WB) addresses the issue that although X-ray images are grayscale, color shifts can occur during digitization due to differences in acquisition equipment. White balance correction works by learning a gain parameter for each channel. The image is color constant adjusted to ensure that the grayscale representation of defects is not affected by device deviation, providing color-consistent input for subsequent processing.

[0041] Gamma Correction Filter: Gamma correction is a common method for adjusting image brightness and contrast. This invention learns a nonlinear exponent for each channel. This allows the model to adaptively stretch or compress the grayscale distribution based on the overall brightness of the image. For example, for an underexposed image, a smaller gamma value can brighten dark areas, making cracks or pores hidden in shadows visible.

[0042] Tone remapping filter: Defines a piecewise linear mapping function using a set of learnable control points to flexibly adjust the grayscale distribution of an image. This mapping can simulate complex nonlinear transformations and redistribute pixel intensity in an optimal way, stretching grayscale values ​​that were originally clustered in the histogram (such as defect areas with similar grayscale to the background), thereby highlighting the grayscale differences of defects.

[0043] Contrast Enhancement Filter: To enhance the contrast between defects and the background, this invention proposes a contrast enhancement method based on local brightness. This method first calculates the image brightness, then constructs a brightness-related enhancement coefficient using a cosine function. Stronger contrast stretching is applied in medium-brightness areas, while maintaining a smooth transition in extremely bright or dark areas, thus enhancing defects while avoiding amplifying noise.

[0044] Sharpen Enhancement Filter: To highlight the boundaries and fine structures of defects, this invention introduces an adaptive sharpening method based on an unsharpened mask. This method first blurs the image using a Gaussian kernel of a fixed scale to obtain low-frequency components. The original image is then subtracted from the blurred image to extract high-frequency components containing edges and details. Subsequently, the model predicts a sharpening intensity coefficient through a network, and the high-frequency components are weighted according to this coefficient and superimposed back onto the original image, thereby significantly enhancing defect edges while suppressing noise.

[0045] Through the synergistic effect of the gating mechanism and the parameter prediction network, the aforementioned filter can adaptively generate a customized enhancement strategy based on the characteristics of each input image. Experiments demonstrate that this module can effectively improve the visibility of various defects in images, providing higher-quality input for subsequent feature extraction networks, thereby improving overall detection accuracy.

[0046] In computer vision, convolutional neural networks (CNNs) and the Transformer architecture exhibit significant complementarity in feature extraction. CNNs naturally possess the ability to capture detailed information such as texture and edges through local convolution operations, and their inductive bias makes them efficient and stable in processing local features. However, as the number of network layers increases and multiple downsampling operations occur, CNNs inevitably lose fine-grained details crucial for minor defects. In contrast, the Transformer effectively captures long-distance dependencies by dividing the image into a sequence of image patches and performing global self-attention modeling, but its patching operation itself disrupts the local continuity of the image. How to simultaneously preserve fine local details and effectively model global semantics within the same framework has become a key issue in improving defect detection performance.

[0047] Inspired by the Transformer's approach of dividing images into blocks for processing, this invention provides a hybrid parallel feature extraction network, comprising a backbone convolutional neural network and a parallel feature extraction branch. The core idea is to retain the backbone convolutional neural network for global semantic feature extraction while simultaneously establishing a parallel processing path dedicated to "block processing - local filtering - feature reconstruction" of the feature map. This explicitly captures and enhances the fine-grained local information lost by the backbone network. This method effectively combines the local modeling advantages of convolutional neural networks with the block processing concept of the Transformer, achieving synergistic complementarity between local details and global semantics.

[0048] Specifically, the backbone convolutional neural network is used to extract global semantic information from the image to obtain feature maps.

[0049] Figure 4 This is a flowchart illustrating a parallel feature extraction branch according to an embodiment of the present invention. Figure 4 As shown, the parallel feature extraction branch is used for: Multi-scale slicing of the feature map in the spatial dimension yields multiple image patches of different sizes corresponding to multiple levels; Multiple image patches are filtered based on local neighborhood consistency to obtain multiple filtered image patches. Multiple image patches after filtering are reconstructed to obtain a parallel branch feature map; the parallel branch feature map is aligned with the feature map in the channel dimension. The output of the hybrid parallel feature extraction network is a fused feature map obtained by fusing the feature map with the feature maps of the parallel branches.

[0050] The hybrid parallel feature extraction network provided in this invention is designed based on an in-depth analysis of the physical processes of X-ray imaging and the essential characteristics of defects. In X-ray imaging, the grayscale values ​​of pixels in the weld area depend on the material density and thickness distribution of the inspected workpiece. For the same defect area, its internal structure is relatively uniform, thus appearing as a high degree of similarity and continuity of grayscale values ​​within the local neighborhood in the image. Conversely, random noise, imaging artifacts, and other factors often manifest as isolated outlier pixels, lacking this spatial continuity. In other words, the essence of a defect lies in the "local structural relationship between pixels" rather than the "isolated value of a single pixel." Based on this understanding, this invention designs a local consistency filtering operation, aiming to strengthen this inherent property at the feature level: by retaining pixel responses that are highly consistent with the features of the local neighborhood, it suppresses outlier noise that disrupts structural consistency, thereby guiding the model to focus more on the structural features of the defect. This design introduces the classic prior of local image smoothness into the deep feature extraction process, enabling the model to better inherit the basic laws of human image understanding during the learning process, improving its robustness to noise interference and its ability to capture the essential features of defects.

[0051] Specifically, such as Figure 4 As shown, the processing flow of the parallel feature extraction branch provided in this embodiment of the invention includes the following steps: Step 1: Multi-scale feature map slicing.

[0052] To achieve refined perception of local details in the feature map, the feature map output by the backbone network is first processed by multi-scale slicing in the spatial dimension. Specifically, the feature map is first layered, and each layer is divided into several regular image blocks according to the slice size. Each image block covers a local region of the feature map, and its size is set to k×k (and let k=2r+1, where r is the slice radius). Different values ​​of k at each layer result in image block slices of different sizes to capture image features at different scales. At the same time, by adjusting the slice stride, the degree of overlap between adjacent image blocks can be controlled, thereby capturing local structural information in the feature map at different granularities. Here, Ci represents different downsampling levels. This operation ensures that the feature dimension of the model's structural slices is consistent with the hierarchical feature dimension extracted by the backbone convolutional neural network. This operation borrows the idea of ​​dividing the image into image blocks in the Transformer model, but its purpose is not to perform global self-attention calculation, but to lay the foundation for subsequent local consistency filtering processing, enabling the model to perform independent refined analysis of each local region while maintaining the overall structure of the feature map.

[0053] Step 2: Local filtering and feature extraction.

[0054] For each image patch segmented in step 1, this invention provides a filtering operation based on local neighborhood consistency, aiming to enhance the structural features of defective regions and suppress noise interference. This operation first calculates the average value of all pixels within the center neighborhood of each image patch, using this as the baseline feature of that local region. Let the center coordinates of the image patch be... If the neighborhood radius is r, then the mean of the central neighborhood is... The calculation formula is:

[0055] In practical applications, r can be used as a hyperparameter to adjust according to the defect scale. For example, a smaller radius can be used for small defects to preserve details, while a larger radius can be appropriately increased to enhance region consistency for larger defects. For example, taking r=3 corresponds to a 7×7 neighborhood. Subsequently, for each pixel within the image patch... Calculate its characteristics relative to the reference feature The absolute deviation. If the absolute deviation is less than the preset hyperparameter threshold... If the absolute deviation exceeds a preset hyperparameter threshold, the pixel is considered to have high consistency with the dominant features of the local region and is retained; otherwise, if the absolute deviation exceeds the threshold, the pixel is considered outlier noise or irrelevant information, and its response value is set to zero. This filtering operation can be expressed as:

[0056] Among them, the preset hyperparameter threshold The threshold setting is based on statistical analysis of the grayscale difference between defective regions and the background in the dataset. Specifically, by randomly sampling several image regions containing typical defects, the average grayscale difference between the pixels in the defective region and its neighboring background is statistically analyzed, and this statistical value is used as a reference for threshold selection. For example, based on the statistics of the training set samples, a threshold is selected... As the default threshold, this value effectively distinguishes defect features from background noise, ensuring that the filtering operation preserves the local consistency of defects while suppressing outlier interference. In practical applications, It can also be used as an adjustable parameter to be adaptively adjusted according to the image quality and defect characteristics under specific working conditions.

[0057] The core function of this filtering mechanism is to enhance the consistent representation of features within local regions. For pixel groups belonging to the same defect, their grayscale values ​​tend to fluctuate within a small range, and this filtering operation can highlight such consistent regions. Random noise or background clutter, due to their large deviation from surrounding pixels, is easily filtered out. After this processing, the pixels retained in each image block are the feature points that conform to the local consistency assumption and may belong to the defect region, thus enhancing the local texture and edges of the defect.

[0058] Step 3: Feature recombination and multi-branch fusion.

[0059] All image patches after filtering Reassemble the data according to their original spatial positions to restore a feature tensor with the same size as the input feature map X. At this point, the parallel feature extraction branch has completed the local detail enhancement of the original feature map. Subsequently, a 1×1 convolutional layer is used to perform channel-dimensional information fusion and feature projection on X′, aligning it with the feature map of the backbone network in the channel dimension. This operation can be represented as:

[0060] Finally, the output of the parallel feature extraction branch is... Feature maps at the scale corresponding to the backbone network The feature maps are then fused. Fusion methods can include element-wise addition or convolution after concatenating channel dimensions. For example, using element-wise addition, the fused feature maps... It can be represented as:

[0061] Where ⊕ represents element-wise addition. If a concatenation method is used, channels are concatenated first, and then the number of channels is adjusted using a 1×1 convolution. Through this fusion mechanism, the global semantic information extracted by the backbone network and the local detail information enhanced by the parallel branches are effectively integrated, forming a hybrid feature representation that contains rich contextual semantics and preserves fine local structure. This feature will be fed into the subsequent detection head for defect classification and localization, providing key feature support for improving the detection accuracy of minute defects and complex-shaped defects.

[0062] Specifically, an auxiliary loss function based on contrastive learning is constructed, including: The InfoNCE loss function is used as the optimization objective of contrastive learning to construct a contrastive loss function; Positive and negative sample pairs are constructed using features extracted from the decoder of the Co-DETR Transformer and multiple auxiliary decoders; By combining the contrastive loss function with the original monitoring loss function of the detection task, an auxiliary loss function based on contrastive learning is constructed, and the auxiliary loss function is introduced into the Co-DETR framework for training.

[0063] Specifically, in industrial weld defect detection tasks, the similarity of visual features between different defect categories is one of the main reasons for model misclassification. Taking incomplete fusion and incomplete penetration as examples, they often exhibit similar grayscale distributions and morphological structures in X-ray images. Without strong discriminative features, the model struggles to form clear category decision boundaries. While traditional classification loss functions can guide the model to distinguish different categories, their optimization objectives mainly focus on the accurate prediction of category probabilities, without imposing explicit constraints on the compactness of intra-class features and the separability of inter-class features in the feature space. Therefore, when faced with defect categories with highly similar visual features, the features learned by the model may be mixed and overlapping, leading to insufficient classification confidence or even misclassification.

[0064] To address the aforementioned technical problems, this invention employs the InfoNCE loss function as the optimization objective for contrastive learning. This loss function optimizes the distribution of the feature space by comparing positive and negative sample pairs, and its mathematical form can be expressed as:

[0065] Where q is the feature vector of the anchor point sample. The feature vector of the positive sample. The feature vector of the negative sample. This represents the cosine similarity function, used to measure the degree of similarity between feature vectors. Temperature is a hyperparameter used to adjust the degree of attention the loss function pays to difficult-to-differentiate negative samples. The optimization objective of this loss function is intuitive and clear: for a given anchor sample, it is desirable to have the highest possible similarity to positive samples and the lowest possible similarity to all negative samples, thereby forming a distribution structure of "intra-class clustering and inter-class separation" in the feature space. In this embodiment of the invention, positive and negative sample pairs are constructed using features extracted from the decoder of the Co-DETR Transformer and multiple auxiliary decoders, as follows: Figure 5 shown. Specifically: For constructing positive sample pairs, the characteristic that the same real target may be matched simultaneously by different detection heads is utilized. Specifically, a query embedding that matches a certain real defect category A is selected from the main detection head as an anchor point q; subsequently, a query embedding that also matches the same target category A is selected from any auxiliary detection head as a positive sample k. + Although these two query embeddings come from different detection heads, they correspond to the same real defect target, and their representations in the feature space should be highly consistent, thus forming a natural positive sample pair.

[0066] The construction of negative samples includes two types of samples to enhance the comprehensiveness of the constraints: the first type is intra-class negative samples, which refer to the query embeddings of all targets matched by all detector heads in the same batch and the same image, whose categories are different from A; the second type is inter-class negative samples, which refer to the query embeddings of all targets matched by all detector heads in other images in the same batch. By introducing these two types of negative samples, the model can not only distinguish different categories in the same image, but also establish category discriminativeness between different images, thereby obtaining richer supervision signals.

[0067] The core advantage of the above sample pair construction strategy is that it does not require additional data annotation or a complex sample mining process. It can build high-quality contrastive learning tasks using only the intermediate features generated by the detection framework itself, thus making full use of computing resources.

[0068] By combining the contrastive loss function with the original monitoring loss function of the detection task, an auxiliary loss function based on contrastive learning is constructed as follows:

[0069] in Let be the original monitoring loss function (including classification loss and regression loss), and λ be the weighting coefficient balancing the two losses. Through joint optimization, while completing the classification and localization tasks, the model is additionally constrained by feature discriminativeness, forcing different categories to form clearer decision boundaries in the feature space.

[0070] In this embodiment of the invention, the contrastive auxiliary loss function is introduced into the Co-DETR framework for training. Experimental results show that after introducing this loss, the classification accuracy of the model is improved, and the overall detection accuracy gains a significant advantage on public datasets. This verifies the effectiveness of this method in enhancing feature discriminative power, and its design concept is not dependent on a specific detection framework, making it applicable to other multi-detector head structures.

[0071] To verify the effectiveness of the method provided in this embodiment of the invention in actual weld defect detection tasks, a systematic experimental verification was conducted on the SWRD weld X-ray image dataset disclosed in this embodiment.

[0072] 1. Data preparation.

[0073] In this embodiment of the invention, 80% of the samples (2,940 images) are randomly selected from the SWRD dataset as the training set, and 20% of the samples (735 images) are selected as the test set. The training set is used for model parameter learning, and the test set is used for final performance evaluation.

[0074] Before being fed into the neural network, the input images are first uniformly cropped to a fixed size of 640×640 pixels. For the training set, random horizontal flipping is used for data augmentation to improve the model's generalization ability; the test set only undergoes size normalization and no augmentation is performed.

[0075] 2. Forward calculation.

[0076] Model training is based on the PyTorch deep learning framework. Given an input image... The forward calculation process is as follows: Step 1: Adaptive Image Enhancement: The image first enters the Adaptive Image Preprocessing (APM) module. This module contains four learnable filters: white balance correction, gamma correction, contrast enhancement, and tone remapping. The parameters of each filter are dynamically generated by a lightweight parameter prediction network based on the image content. Let the original image be... The intermediate result is obtained after processing by the k-th filter. Through learnable gating weights Perform residual fusion:

[0077] in For the k-th filter, The corresponding parameters are used. The final output is an enhanced image. In this embodiment, the parameters of each filter and the gating weights are calculated in real time from the input image by the parameter prediction network, thereby achieving refined enhancement that is adaptive to different images.

[0078] Step 2: Hybrid Parallel Feature Extraction Enhanced image The input is divided into two parallel paths: Backbone: Employs ResNet-50 as the backbone network, outputting multi-scale feature maps. Let the feature map output by the backbone network at layer l be... ,in For the number of channels, and The spatial resolution is defined as follows. In this embodiment, the outputs of the last three stages of the backbone network are taken as multi-scale features, with resolutions of 1 / 8, 1 / 16, and 1 / 32 of the input image, respectively.

[0079] Parallel Branch (ResPatch): To address the easily lost details in the shallow feature maps of the backbone network, this embodiment designs a parallel feature extraction branch. The feature map output from the first stage of the backbone network is used as the basis for this design. For example, firstly, the image is divided into several image blocks according to a step size s, and each image block has a size of k×k (in this embodiment, k=7 and step size s=4). For each image block... Calculate its mean and with threshold =15 performs local consistency filtering:

[0080] After filtering, all image patches are rearranged according to their original spatial positions to obtain a feature map of the same size as the input. By using 1×1 convolution... Project the features onto the same channel dimension as the backbone network, and then fuse them element by element:

[0081] Repeat the above operations for each output level of the backbone network to form an enhanced multi-scale feature representation.

[0082] Step 3: Target Detection and Loss Calculation The fused multi-scale features are fed into the Transformer decoder for object detection. The decoder output includes classification predictions and bounding box regression results, and calculates the conventional detection loss. It consists of two parts: classification loss and regression loss.

[0083] Step 4: Compare with auxiliary loss calculations: While the encoder and decoder perform routine supervised computation, this embodiment additionally introduces a contrastive auxiliary loss. Specifically, query features with high matching quality to the real target are selected from the main detection head as anchor points q, and query features that match the same real target are selected from the auxiliary detection head as positive samples k. + negative samples k are sampled from other targets and the background. - Calculate the comparative auxiliary loss based on the InfoNCE loss function:

[0084] in For cosine similarity, Temperature hyperparameter (taken in this embodiment) =0.07). This loss encourages query-key features corresponding to the same target to be close to each other in the representation space, while maintaining distinction from features of other targets or background, thereby improving the discriminativeness and robustness of the features.

[0085] 3. Backpropagation and parameter update.

[0086] After the forward computation is completed, construct the total loss function:

[0087] In this embodiment, the balance coefficient is set to λ=0.5. The AdamW optimizer is used for backpropagation, with an initial learning rate set to 2×10⁻⁶. -4 The batch size is 4, and the training runs for 12 epochs. During training, if the validation set loss does not decrease for three consecutive epochs, the learning rate is reduced to 0.1 times its original value.

[0088] 4. Performance verification.

[0089] To comprehensively evaluate the detection performance of the method of this invention, the Co-DETR object detection model with high accuracy based on Transformer was selected as the baseline model for comparative experiments. All comparative experiments were conducted under the same dataset partitioning and training strategy to ensure fair comparison.

[0090] Table 1. Performance comparison with the Base detector on the SWRD dataset.

[0091] Table 1 presents the comparative experimental results of each model on the SWRD dataset. The results show that the proposed method achieves optimal detection performance under both ResNet-50 and Swin-L backbone networks. Under the ResNet-50 backbone, the proposed method achieves an mAP@0.5 of 67.3%, a 1.4 percentage point improvement over the baseline model's Co-DETR; under the Swin-L backbone, the mAP@0.5 reaches 73.8%, a 2.2 percentage point improvement over the baseline model.

[0092] This improvement in accuracy is significant for automated defect rating. For example, a 1.4 percentage point improvement in mAP translates to approximately 14 fewer missed or false positives for every 1000 weld images inspected in a real-world inspection scenario. In safety-sensitive fields such as aerospace and oil and gas pipelines, this level of accuracy can significantly reduce safety risks caused by missed defects. Furthermore, improved detection accuracy means the model's defect identification is more stable and reliable, providing more credible input for subsequent automated rating.

[0093] It is worth noting that the method of this invention significantly improves the detection accuracy of minute defects, increasing from 20.4% to 27.4% on the Swin-L backbone, an improvement of 7 percentage points. Minute defects are easily missed in manual image evaluation, and the method of this invention enhances the ability to capture such details through parallel feature branches.

[0094] In addition to quantitative indicators, Figure 6This paper demonstrates the detection performance of the method of this invention on typical difficult samples, comparing the detection results of ground truth (GT), the baseline model Co-DETR (Base), and the improved model of this invention. The figures clearly show that the baseline model exhibits significant missed and false detections—small pores and low-contrast cracks are missed, complex background textures are misidentified as defects, and some detection boxes are inaccurately positioned or too loose. In contrast, the improved model of this invention successfully detects these defects missed by the baseline, effectively suppressing false detections caused by background interference. These visualization results directly demonstrate the improvements in detection accuracy and reliability of the method of this invention, providing more accurate and stable detection results for the automated rating of weld defects.

[0095] As described above, the embodiments of the present invention provide a weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction, which has the following technical advantages compared with the prior art: First, this method designs an adaptive preprocessing module with gating mechanism and hybrid control, which can dynamically generate enhancement parameters according to the characteristics of each image, significantly improving the quality of the input image, effectively suppressing noise, highlighting defect features, and providing more favorable input conditions for subsequent feature extraction.

[0096] Secondly, this method innovatively designs a parallel feature extraction branch, which explicitly captures the fine-grained details lost by the backbone network through slicing, filtering, and recombination operations. This effectively compensates for the information loss of convolutional neural networks in difficult-to-detect targets such as tiny pores and slender cracks, and provides an effective technical path to solve the problem of "difficult detection of small targets".

[0097] Finally, this method introduces a contrast-assisted loss function and uses a multi-detector structure to construct positive and negative sample pairs. It applies explicit constraints of intra-class compactness and inter-class separation in the feature space, which effectively improves the model's detection performance for visual similarity defects and easily confused samples.

[0098] Overall, this invention constructs a systematic solution from three levels: input enhancement, feature extraction, and loss function optimization. It significantly improves the accuracy and reliability of weld defect detection, provides accurate and stable technical support for automated defect rating, and has significant industrial application value.

[0099] The present invention also provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method provided in the embodiments of the present invention.

[0100] The present invention also provides a computer-readable storage medium storing program code, which can be called by a processor to execute the method provided in the embodiments of the present invention.

[0101] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0102] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0103] In the several embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0104] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0105] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0106] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0107] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A weld defect detection method based on adaptive enhancement and hybrid parallel feature extraction, characterized in that, The method includes: The X-ray image dataset of welds was preprocessed to construct training and test sets, respectively. An adaptive image preprocessing module is constructed based on gating mechanism and hybrid control, a hybrid parallel feature extraction network is constructed, and an auxiliary loss function based on contrastive learning is constructed. Based on the adaptive image preprocessing module, the hybrid parallel feature extraction network, and the auxiliary loss function, an end-to-end detection framework for X-ray weld image defect detection is constructed. The end-to-end detection framework is trained based on the training set and validated based on the test set to obtain a trained weld defect detection model. Based on the trained weld defect detection model, defect detection is performed on the X-ray weld image to be detected, and the detection results are obtained.

2. The method according to claim 1, characterized in that, The adaptive image preprocessing module includes multiple serial filters and parameter prediction networks, wherein each filter corresponds to a learnable gating weight, and the image is updated in the form of residual gating when passing through each filter; The parameter prediction network includes a lightweight convolutional neural network for end-to-end prediction of the filter parameters and corresponding gating weights. The adaptive image preprocessing module also includes a global fusion control factor to balance the contributions of the original image and the enhanced image; The output of the adaptive image preprocessing module includes: In the formula, This refers to the global hybrid control factor. and These are the input and output of the plurality of serial filters, respectively. This is the output of the adaptive image preprocessing module.

3. The method according to claim 2, characterized in that, The filters include: white balance correction filter, gamma correction filter, tone remapping filter, contrast enhancement filter, and sharpening enhancement filter.

4. The method according to claim 1, characterized in that, The hybrid parallel feature extraction network comprises a backbone convolutional neural network and a parallel feature extraction branch; wherein... The backbone convolutional neural network is used to extract global semantic information of the image to obtain a feature map; The parallel feature extraction branch is used for: The feature map is sliced ​​at multiple scales in the spatial dimension to obtain multiple image patches of different sizes corresponding to multiple levels; The multiple image blocks are filtered based on local neighborhood consistency to obtain multiple filtered image blocks. The filtered image blocks are reconstructed to obtain a parallel branch feature map; the parallel branch feature map is aligned with the feature map in the channel dimension. The output of the hybrid parallel feature extraction network is a fused feature map obtained by fusing the feature map with the parallel branch feature map.

5. The method according to claim 4, characterized in that, Perform filtering operations based on local neighborhood consistency on the multiple image blocks respectively, including: Calculate the average value of all pixels in the central neighborhood of each image block, and use the average value as the reference feature of the central neighborhood of each image block; Calculate the absolute deviation of each pixel within each image patch from the corresponding reference feature; If the absolute deviation exceeds the preset hyperparameter threshold, the corresponding pixel is retained; otherwise, the response value of the corresponding pixel is set to zero. The preset hyperparameter threshold is determined based on statistical analysis of the difference in grayscale between the defect area and the background in the dataset.

6. The method according to claim 1, characterized in that, Constructing an auxiliary loss function based on contrastive learning, including: The InfoNCE loss function is used as the optimization objective of contrastive learning to construct a contrastive loss function; Positive and negative sample pairs are constructed using features extracted from the decoder of the Co-DETR Transformer and multiple auxiliary decoders; The contrastive loss function is combined with the original monitoring loss function of the detection task to construct an auxiliary loss function based on contrastive learning, and the auxiliary loss function is introduced into the Co-DETR framework for training.

7. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the method as claimed in any one of claims 1-6.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1 to 6.