X-ray weld defect detection method based on multi-scale feature enhancement

CN122989662APending Publication Date: 2026-10-27TAIYUAN UNIVERSITY OF SCIENCE AND TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611203577.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-10
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

[0005]为了解决现有目标检测模型处理X射线焊缝缺陷图像时存在对不同尺度缺陷、弱纹理缺陷识别能力不足,进而产生漏检或定位不准确的技术问题,本发明提供一种基于多尺度特征增强的X射线焊缝缺陷检测方法

Benefits of technology

本发明利用CA-MSFF减少尺度较小或局部响应较弱的缺陷在特征提取过程中的信息损失,利用LGFA强化缺陷区域的边缘、纹理和方向性上下文信息,同时抑制复杂焊缝背景干扰,利用ASSFL增强模型对困难样本和低质量预测样本的学习能力,通过三个模块协同作用,提高对多尺度、弱纹理及模糊边界焊缝缺陷的检测精度,减少漏检和误检,同时提升模型训练稳定性及复杂工业场景下的检测鲁棒性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122989662A_ABST
    Figure CN122989662A_ABST
Patent Text Reader

Abstract

The present application relates to a kind of X-ray weld defect detection methods based on multi-scale feature enhancement in the field of nondestructive testing technology.The weld defect detection model is constructed.Weld defect detection model is based on RT-DETR network as basic network, in its high-level semantic feature processing position and top-down feature fusion path Channel perception multi-scale feature fusion module CA-MSFF and local department control feature attention module LGFA are constructed.X-ray weld image is input into weld defect detection model to identify the defect class and position of weld.The present application uses CA-MSFF to reduce the information loss of defects with smaller scale or weaker local response during feature extraction, uses LGFA to enhance the edge, texture and directional context information of defect area, while suppressing the interference of complex weld background, through the synergistic effect of the three modules, improves the detection accuracy of multi-scale, weak texture and fuzzy boundary weld defects, reduces missed detection and false detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of nondestructive testing technology, and in particular to an X-ray weld defect detection method based on multi-scale feature enhancement. Background Technology

[0002] X-ray nondestructive testing (NDT) utilizes the penetrating power of X-rays to obtain images of the internal structure of welds. It can detect internal weld defects without damaging the integrity of the component, making it an important method for industrial weld quality inspection. With the development of computer vision and deep learning technologies, weld defect detection methods based on target detection networks are gradually being applied. Existing target detection methods mainly include single-stage detection methods based on convolutional neural networks, two-stage detection methods, and end-to-end target detection methods based on Transformer structures. Among them, real-time end-to-end target detection models based on Transformer structures can balance detection accuracy and speed, showing good application prospects in industrial defect detection. However, X-ray weld defect images have the following characteristics: First, different types of weld defects exhibit significant differences in scale and morphology. Porosity typically appears as dots or nearly circular shapes, while cracks, lack of fusion, and incomplete penetration are usually elongated or strip-shaped, and slag inclusions are often irregular in shape. Some defects have a low pixel count in the image, and their local responses are easily weakened or even lost after multiple downsampling by the backbone network. Existing feature fusion networks usually employ fixed feature fusion topologies, making it difficult to fully extract defect information from different receptive fields, resulting in insufficient model representation of defects with small scale or significant morphological changes.

[0003] Second, X-ray weld defect images typically exhibit slow grayscale changes, blurred defect edges, weak defect textures, and complex background structures. The grayscale difference between some defect areas and normal weld areas is small, making it difficult for ordinary convolution and conventional attention mechanisms to simultaneously extract local edge, texture, and directional contextual information of the defect. This can easily lead to confusion between the defect and the background, resulting in missed detections, false detections, or inaccurate localization.

[0004] Third, during training, object detection models encounter a large number of easily classifiable background samples, ordinary positive samples, and low-quality difficult samples simultaneously. Existing classification loss functions typically use fixed settings for focusing parameters and sample weights, making it difficult to dynamically adjust them according to changes in model training status and sample matching quality. When the matching quality between predicted and ground truth boxes fluctuates across different training batches, fixed loss weights may lead to insufficient attention to difficult samples. Furthermore, some threshold-based segmented weighting methods can cause abrupt changes in the loss weights for samples near the threshold, affecting the continuity of training gradients and the model's convergence stability. Summary of the Invention

[0005] To address the technical problem that existing target detection models lack the ability to identify defects of different scales and weak textures when processing X-ray weld defect images, resulting in missed detections or inaccurate localization, this invention provides an X-ray weld defect detection method based on multi-scale feature enhancement.

[0006] In a first aspect, the present invention proposes an X-ray weld defect detection method based on multi-scale feature enhancement, which includes the following steps: First, a weld defect detection model is constructed. This model uses the RT-DETR network as its base network, and incorporates a channel-aware multi-scale feature fusion module (CA-MSFF) and a local gated feature attention module (LGFA) in its high-level semantic feature processing location and top-down feature fusion path. The CA-MSFF enhances the semantic information of defects at different scales through multi-scale convolution, residual connections, and channel recalibration. The LGFA strengthens the edge, texture, and directional contextual information of the defect region through local attention, bi-branch enhancement, and gating mechanisms.

[0007] Next, the X-ray weld image is input into the weld defect detection model for identification. The weld defect detection model first outputs feature maps at three different scales through a backbone network. P 3. P 4. P 5. Next, P 5. Input CA-MSFF processing to obtain high-level enhanced features Y 5. [The sentence is incomplete and requires more context to be translated accurately.] Y 5 and P 4. After fusion, the input is processed by LGFA to obtain the mid-layer enhancement features. Y 4. [The sentence is incomplete and requires more context to be translated accurately.] Y 4 and P 3. Fusion yields high-resolution detection features X 3. [The following is a list of steps / points:] ... X 3 and Y 4. Fusion yields medium-resolution detection features .Will and Y 5. Fusion yields low-resolution detection features .Will X 3. , Input the inspection head to obtain the defect type and location of the weld.

[0008] Secondly, the present invention also proposes a computer-readable storage medium storing a computer program / instructions. When the computer program / instructions are executed by a processor, the steps of the X-ray weld defect detection method based on multi-scale feature enhancement in the first aspect are implemented.

[0009] Thirdly, the present invention also proposes a computer program product comprising a computer program / instructions. This computer program / instructions are used to cause a computer to perform the steps of the X-ray weld defect detection method based on multi-scale feature enhancement of the first aspect.

[0010] The beneficial effects of this invention are as follows: This invention utilizes CA-MSFF to reduce information loss during feature extraction for defects with small scales or weak local responses, employs LGFA to enhance the edge, texture, and directional contextual information of the defect region while suppressing interference from complex weld backgrounds, and utilizes ASSFL to enhance the model's learning ability for difficult and low-quality predicted samples. Through the synergistic effect of these three modules, the detection accuracy for multi-scale, weakly textured, and fuzzy boundary weld defects is improved, reducing missed and false detections, while also enhancing model training stability and robustness in complex industrial scenarios. Attached Figure Description

[0011] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are 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.

[0012] Figure 1 This is the overall architecture diagram of the weld defect detection model; Figure 2 This is a structural diagram of the channel-aware multi-scale feature fusion module CA-MSFF; Figure 3 This is a structural diagram of the Localized Feature Attention Module (LGFA). Figure 4 This is a diagram illustrating the detection and recognition results in the embodiment. Detailed Implementation

[0013] The technical solutions in the embodiments of the present invention will be clearly and completely described below. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0014] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the specification of this invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "or / and" as used herein includes any and all combinations of one or more of the associated listed items.

[0015] This invention identifies X-ray weld defects in images using a constructed weld defect detection model to determine the defect type and location. The model uses the RT-DETR-R18 network as its base network, with improvements in that a channel-aware multi-scale feature fusion module (CA-MSFF) and a local area-controlled feature attention module (LGFA) are constructed at the high-level semantic feature processing location and in the top-down feature fusion path, respectively. During inference, the X-ray weld image is input into the model, and the backbone network first outputs feature maps at three different scales. P 3. P 4. P 5. Next, P 5. Input CA-MSFF processing: Multi-receptive field features are extracted through convolutional branches of different scales in CA-MSFF. Combined with feature concatenation, residual enhancement, and channel attention mechanisms, the model's ability to represent features of weld defects of different scales and morphologies is improved, resulting in high-level enhanced features. Y 5. [The sentence is incomplete and requires more context to be translated accurately.] Y 5 and P 4. After fusion, the input is processed by LGFA. Through local importance modeling, bi-branch feature enhancement, and spatial gating recalibration, the local fine-grained features of weak textures, blurred boundaries, and slender defects such as cracks, lack of fusion, and incomplete penetration are enhanced to obtain mid-layer enhanced features. Y 4. [The sentence is incomplete and requires more context to be translated accurately.] Y 4 and P 3. Fusion yields high-resolution detection features X 3. [The following is a list of steps / points:] ... X 3 and Y 4. Fusion yields medium-resolution detection features .Will and Y 5. Fusion yields low-resolution detection features .Will X 3. , The input detector head yields the defect type and location of the weld. The following section details the steps of the X-ray weld defect detection method, based on the architecture of the weld defect detection model: Please refer to Figure 1In this embodiment, X-ray weld images are acquired using an X-ray inspection device. The weld defect detection model includes: a backbone network, a hybrid encoder, a neck network, a query selection module, and a head network. The backbone network can be a ResNet-18 backbone network. A channel-aware multi-scale feature fusion module (CA-MSFF) is constructed at the high-level semantic feature processing position of the hybrid encoder. Its core function is to extract feature information of weld defects of different scales and shapes through convolutional branches with multiple receptive fields. Combined with feature splicing, fusion convolution, residual connections, and channel attention mechanisms, it adaptively strengthens feature channels containing effective defect information, reducing the loss of small-scale or locally weak defect features during network downsampling and feature transformation. In the middle layer fusion feature position of the top-down fusion branch, the Local Gated Feature Attention Module (LGFA) is introduced. Through local importance modeling, bi-branch local feature enhancement and spatial gated recalibration, the local edge, weak texture, morphology and directional context information of weld defects are extracted, making the features of slender and blurred defects such as cracks, lack of fusion and incomplete penetration more prominent, while suppressing the interference of complex weld background and redundant information.

[0016] During the inference phase, the preprocessed X-ray weld image is used as the model input. First, in the ResNet-18 backbone network, multi-level feature extraction and semantic upscaling are completed sequentially through convolutional layers, residual structures, and downsampling operations, outputting feature maps at three different levels. P 3. P 4 and P 5. Among them, shallow feature maps P 3. It has high spatial resolution, used to preserve the edge, texture, and location information of defects. Mid-layer feature map. P 4. Contains local details and mid-level semantic information. High-level feature map. P 5. It has strong high-level semantic expression capabilities.

[0017] The hybrid encoder includes an AIFI (Adaptive Inter-Scale Feature Interaction) attention layer and a channel-aware multi-scale feature fusion module (CA-MSFF). It integrates high-level feature maps... P 5. A 1×1 convolutional layer is used to complete channel mapping, and then an AIFI attention layer is used to establish the correlation between different spatial locations within the feature map, resulting in encoded high-level semantic features. X , can be represented as: ; In the formula, C , H and W These represent the number of channels, height, and width of the feature map, respectively.

[0018] One of the innovations of this invention is the Channel-Aware Multi-Scale Feature Fusion (CA-MSFF) module. This CA-MSFF enhances the semantic information of defects at different scales through multi-scale convolution, residual connections, and channel recalibration, reducing information loss during feature extraction for defects with smaller scales or weaker local responses. Please refer to [link / reference]. Figure 2 In this embodiment, CA-MSFF includes: four convolutional branches, a channel attention module, and a residual fusion unit. High-level semantic features. X It is fed into four parallel convolution branches. One of the convolution branches uses a 1×1 convolution to... C Channel mapping as C Channels, and obtain intermediate features F 1. The remaining three convolutional branches adopt a bottleneck structure, first using a 1×1 convolution to... C Compressed to the middle channel M Then, 3×3, 5×5, and 7×7 convolutions are used to extract the corresponding receptive field information, and finally, a 1×1 convolution is used to... M Restore to C The corresponding intermediate features were obtained respectively. F 3. F 5. F 7. Batch normalization and ReLU activation are performed sequentially after each convolutional layer. The stride of all convolutional layers is set to 1, and padding corresponding to the kernel size is used to maintain the spatial resolution of the output features of the four convolutional branches. H × W Intermediate features obtained through the four convolutional branches F 1. F 3. F 5. F 7, all of which are of the following dimensions. C × H × W The channel attention module runs in parallel with four convolutional branches, integrating high-level semantic features. X Global average pooling and global max pooling are performed separately to obtain the average and maximum response information of the input features on different channels. Then, these two types of response information are input into a shared feature mapping structure to obtain the corresponding channel description features. Next, the two channel description features are added element-wise, and then the Sigmoid activation function is used to map them to the range of 0 to 1, generating channel attention weights. W c : W c = s (MLP(GAP( X ))+ MLP(GMP( X ))).

[0019] In the formula, s (·) represents Sigmoid activation, MLP(·) represents shared feature mapping, GAP(·) represents global average pooling, and GMP(·) represents global max pooling. Intermediate features are processed through residual fusion units. F 1. F 3. F 5. F 7. By stitching along the channel dimension, defect features extracted from different receptive fields are aggregated to obtain multi-scale aggregated features. F ms : F ms =Concat( F 1. F 3. F 5. F 7).

[0020] Concat(·) indicates concatenation. Next, multi-scale features are aggregated. F ms Input a 1×1 convolutional layer and reduce its channel count from 4 C Compress to C Then, 3×3 convolution is used to further integrate multi-scale spatial information to obtain multi-scale fused features. F fusion : F fusion =Conv( F ms ).

[0021] Conv(·) represents convolution processing, fusing features across multiple scales. F fusion With high-level semantic features X By performing residual summation, while preserving the original high-level semantic information, the loss of effective defect information caused by multi-branch convolution and feature fusion is reduced, resulting in multi-scale residual enhancement features. F r : F r = F fusion + X .

[0022] Finally, the channel attention weights are... W c Multi-scale residual enhancement features F rChannel-by-channel multiplication is performed to give higher weights to channels containing valid weld defect information and suppress the responses of redundant or defect-irrelevant channels, resulting in the high-level enhancement features of the CA-MSFF output. Y 5: .

[0023] The neck network consists of: a top-down fusion branch, a localized feature attention module (LGFA), and a bottom-up aggregation branch. In the fusion branch, high-level features are enhanced. Y 5. Perform double upsampling and compare with the middle layer feature map. P 4. The features are stitched together along the channel dimension, and then feature fusion and channel adjustment are performed through the RepC3 module to obtain the mid-layer fused features. F in : F in = RepC3[Concat( U ( Y 5) P 4).

[0024] U (·) indicates upsampling. The Local Gated Feature Attention Module (LGFA) is another innovation of this invention. It enhances the edge, texture, and directional contextual information of defect regions through local attention, bi-branch enhancement, and gating mechanisms, while suppressing interference from complex weld seam backgrounds. Please refer to... Figure 3 In this embodiment, the Local Feature Attention Module (LGFA) includes: a local extraction unit, a bi-branch local feature enhancement unit, a gating unit, and a fusion unit. During the intermediate feature fusion... F in After inputting the local area feature attention module LGFA, the input first enters the local extraction unit. The local extraction unit first uses a 1×1 convolution to process the input features (i.e., the mid-level fused features). F in )Depend on C Each channel is mapped to having f The intermediate feature space of each channel is used to reduce the computational cost in subsequent local importance modeling. Next, the channel-mapped features are input into a Soft Pooling layer with a 7×7 kernel and a stride of 3 for local response aggregation. Soft Pooling assigns corresponding contributions based on the magnitude of the feature response at different locations, giving higher weights to local defect features with stronger responses, thereby reducing the loss of local significant defect information caused by ordinary average pooling during downsampling. The features output from the Soft Pooling layer are then input into a 3×3 convolutional layer with a stride of 2 for further feature extraction, and then another 3×3 convolutional layer restores the number of feature channels to [previous value]. CThen, Sigmoid activation is performed, and bilinear interpolation is used to restore the response map to the fused features of the middle layer. F in With the same spatial resolution, a local importance map is obtained. A l : .

[0025] This represents the aggregation of local responses. Local importance graph. A l Input a bi-branch local feature enhancement unit. This bi-branch local feature enhancement unit includes: a dimensionality reduction unit, a spatial convolution branch, a directional context branch, and a fusion output unit. Local importance map. A l Entering the dimensionality reduction unit, its channel number is reduced from [previous value] to [current value] through a 1×1 pointwise convolutional layer. C Compress to N This reduces the computational cost of subsequent bi-branch local feature enhancement processes, resulting in dimensionality-reduced features. Dimensionality reduction features The inputs are the spatial convolution branch and the directional context branch. In the spatial convolution branch, local edge, texture, and morphological information of weld defects are extracted using a regular 3×3 convolution, followed by batch normalization and ReLU activation. The processed features are then added to the original dimensionality-reduced features using residuals to obtain the output features of the spatial branch. F sp : .

[0026] Conv 3×3 (·) indicates a 3×3 convolution process. BN (·) indicates batch normalization. ReLU [·] indicates ReLU activation. In the directional context branch, it represents a dimensionality reduction feature. By adding a dimension, the original two-dimensional features are expanded into a feature form suitable for 3D convolution processing. Then, a 3D convolution with a kernel size of 1×1×3 is used to extract directional local dependencies along the width direction of the expanded feature representation. After that, the added dimension is removed, and the processing result is restored to the two-dimensional feature format, resulting in the directional context branch output features. F 3d Finally, the spatial branch output features are fused through the output fusion unit. F sp and directional context branch output features F 3dThe features are concatenated along the channel dimension to complement local spatial information with directional contextual information. The concatenated features are then subjected to batch normalization and ReLU activation, followed by a 1×1 projective convolution to reduce the number of channels. 2N Restore to C The bi-branch enhancement features were obtained. F e : F e =Conv 1×1 (ReLU(BN(Concat( F sp , F 3d )))).

[0027] The gating unit operates in parallel with the local extraction unit and the dual-branch local feature enhancement unit, fusing features from the middle layer. F in The first channel is selected as the representative spatial response, and a single-channel spatial gating map is generated using the Sigmoid activation function. G The fusion unit will fuse mid-layer features. F in Dual-branch enhancement features F e Single-channel space gating diagram G Element-wise multiplication is performed to enhance the effective response of local defect regions while suppressing the characteristic responses of complex weld backgrounds and redundant regions, resulting in the mid-level enhanced features output by the LGFA module. Y 4: .

[0028] Mid-layer enhancement features Y 4. Then, enter a fusion branch, first perform a 2x upsampling, and then combine it with the shallow feature map. P 3. The features are stitched together along the channel dimension and then fused using the RepC3 module to obtain high-resolution detection features. X 3: X 3 = RepC3[Concat( U ( Y 4) P 3).

[0029] Then, through a bottom-up aggregation branch, high-resolution detection features are... X 3. Perform downsampling and combine with mid-layer enhancement features. Y 4. The features are stitched together along the channel dimension and then fused using the RepC3 module to obtain medium-resolution detection features. : = RepC3[Concat( D ( X 3) Y 4).

[0030] D (·) indicates downsampling. This applies to features detected at medium resolution. Continue downsampling through an aggregation branch and combine it with high-level enhancement features. Y 5. The features are stitched together along the channel dimension and then fused using the RepC3 module to obtain low-resolution detection features. : = RepC3[Concat( D ( ), Y 5).

[0031] High-resolution detection features X 3. Medium resolution detection features Low-resolution detection features The concatenated data is then input into the query selection module. The query selection module flattens and encodes the input features to obtain multi-scale encoded features, and evaluates the quality of candidate targets among the multi-scale encoded features, selecting the candidate features with the highest classification confidence and localization quality as the initial object query.

[0032] The head network includes a decoder and a detection head. The decoder updates the defect category and spatial location information in the object query layer by layer based on the interaction between the initial object query and multi-scale encoded features, establishing a correlation between the weld defect target and global image features, thus outputting the object query. The detection head outputs the defect category prediction probability and defect bounding box coordinates for each candidate target based on the object query, thereby obtaining the defect category and location of the weld. The defect categories include: cracks, lack of fusion, incomplete penetration, porosity, and inclusions. The defect bounding box coordinates are used to determine the location and extent of the defect in the X-ray weld image. In practical applications, the detection results of the weld defect detection model are mapped onto the original X-ray weld image. Specifically, as shown... Figure 4 As shown, the defect category name, prediction confidence level, and defect bounding box are plotted on the original X-ray weld image to generate X-ray weld defect visualization detection results. The detection results can be used for weld quality judgment, defect quantity statistics, defect location recording, and quality control in industrial manufacturing processes.

[0033] Furthermore, it should be noted that the weld defect detection model needs to be used for inference after training. In the model training phase, this invention uses the Adaptive Smooth Sliding Focus Loss Function (ASSFL) instead of the original classification loss function. This allows the model to further extract and enhance features of weld defects of different scales, shapes, and weak textures, while improving its learning ability for difficult and low-quality predicted samples, thereby improving the classification and localization accuracy of X-ray weld defects. This ASSFL is another core innovation of this invention. It dynamically calculates the quality of positive sample matching through EMA and adaptively adjusts the focusing parameters based on historical prediction states. Simultaneously, it uses a continuous smoothing function to adjust the loss weights of samples of different quality, enhancing the model's learning ability for difficult and low-quality predicted samples and avoiding abrupt loss changes caused by fixed threshold weighting. Specifically, the training method using the Adaptive Smooth Sliding Focus Loss Function (ASSFL) includes: A dataset of weld defects from X-ray weld images was obtained. The defect categories in the dataset include at least one or more of the following: cracks, lack of fusion, incomplete penetration, porosity, and inclusions. Defect locations are labeled using rectangular bounding boxes, each including at least a defect category label, bounding box center coordinates, bounding box width, and bounding box height. In this embodiment, the images in the weld defect dataset were filtered, organized, and manually labeled, forming a dataset containing 2153 images. Next, the model training environment was configured: after preprocessing the dataset, a dataset configuration file was constructed. The paths to the training and test sets, as well as the category information in the dataset, were written into the dataset configuration file. The configured training environment consisted of an NVIDIA RTX 4090 GPU, PyTorch 2.1.1 deep learning framework, CUDA version 12.1, and Python 3.9.13 programming language. The experiment was set with 100 epochs and a training batch size of 4. The constructed weld defect detection model was loaded into the model training environment, and the labeled dataset was imported for training and detection. During training, the dataset is divided into training and test sets. The training set contains 1507 images, and the test set contains 646 images. The training run consists of 100 epochs, with 4 images input per batch. Training logs are monitored in real-time during training, and a weight file is saved after training is complete.

[0034] During the training phase, the Hungarian matching method is first used to determine the correspondence between the object queries output by the model and the real defects. For successfully matched positive samples, the Intersection over Union (IoU) between their predicted bounding boxes and the corresponding real defect bounding boxes is calculated, and this IoU is used as the quality-aware soft label for the positive sample on the predicted item corresponding to the real category. q For unmatched object queries and non-true category predictions in matched object queries, quality-aware soft labels will be applied. q Set to 0. Therefore,q The bounding box values ​​are ∈[0,1], and their values ​​characterize the quality of the bounding box localization for matching positive samples. A larger value indicates higher matching quality. Subsequently, the class prediction probability is calculated based on the model's output. p Quality-perceived soft labels q The classification loss is calculated, and the adaptive focusing parameters and sample loss weights are dynamically adjusted based on the historical positive sample IoU quality obtained during training, thus obtaining the adaptive smooth sliding focus classification loss. L ASSFL Specifically, in the first t In each training iteration, the IoU between the predicted bounding box of each positive sample in the current batch and its corresponding ground truth defect bounding box is calculated, and the IoU of the positive samples is averaged to obtain the positive sample quality statistic for the current batch. Next, an exponential moving average mechanism is used to calculate the quality statistic of the positive samples in the current batch. The model is updated to obtain a smoothed IoU statistic that reflects the historical prediction quality of the weld defect detection model. : .

[0035] .

[0036] In the formula, d t The dynamic attenuation coefficient, β This is the control coefficient for maximum attenuation intensity. t This is the smoothing speed control coefficient. In this embodiment, β It can be set to 0.999. t It can be set to 2000. The initial value is set to 0.5. During the initial training phase, the dynamic decay coefficient... d t Smaller, resulting in a smaller updated smoothed IoU statistic. The model primarily references the quality of positive sample matching in the current batch to quickly adapt to its initial prediction state. The dynamic decay coefficient increases with the number of training iterations. d t Gradually increase the smoothing IoU statistic The approach gradually transitions from relying on current batch information to referencing historical statistical information, thereby reducing the impact of sample composition and outlier matching results on the loss weights within a single training batch. Subsequently, the smoothed IoU statistic is used... Updated historical IoU statistics EMA Dynamic calculation of adaptive focusing parameters c adaptive : .

[0037] In the formula, c 0 is the base focusing parameter. l γ To adaptively adjust the intensity coefficient, i As a reference threshold, c min For the minimum focusing parameter, c max This is the maximum focusing parameter. In this embodiment, the basic focusing parameter is... c 0 is set to 2.0. Reference threshold. i Set to 0.8. Adaptively adjust the intensity coefficient. l γ Set it to 1.5 and adjust the adaptive focus parameter. c adaptive Limited to 1.0 to 4.0 (i.e.) c min to c max The range between (and) is considered. When the model's historical prediction quality is low, the IoU... EMA Decrease c adaptive This is subsequently increased to reduce the loss contribution of easily classified samples and enhance the model's attention to difficult samples. As the model gradually converges, the IoU... EMA Increase c adaptive The corresponding values ​​are reduced to avoid the model focusing excessively on a small number of outlier samples. Then, based on the adaptive focusing parameters... c adaptive Calculate the adaptive weights corresponding to each candidate object query and its category prediction term in the model output. W adaptivee Adaptive weights corresponding to different candidate object queries. W adaptive for: .

[0038] In the formula, α Represents the negative sample balance coefficient. y This represents the prospect indicator for candidate object queries. It is used when a candidate object query successfully matches a real defect. y =1. When the candidate object query is the background location. y =0. Simultaneously, based on the quality-perceived soft label... q Constructing a positive sample mask indicator function M pos : M pos =I( q >0). I(·) represents the indicator function. When the current candidate query is a positive sample, When the current candidate object query is a background sample, This ensures that subsequent smooth sliding weights modulate the quality of only positive samples. Then, a continuously smooth sample weight modulation term is constructed using Gaussian and Sigmoid functions. W smooth : .

[0039] In the formula, l 1 and l 2 represents the weight enhancement coefficients of the Gaussian and Sigmoid terms, respectively. σ is the smoothing control coefficient. In this embodiment, l 1 is set to 0.18. l 2 is set to 0.12. σ is set to 0.08. A Gaussian modulation term is used to enhance the matching quality of fuzzy boundary samples that are close to the historical average, allowing the loss weights in the boundary region between easy and difficult samples to change continuously. A Sigmoid modulation term is used to enhance the matching quality of low-quality difficult positive samples that are below the historical average, making the model pay more attention to defective samples that have not been fully learned during training, thus avoiding abrupt changes in loss weights when using a fixed threshold for sample interval division. The class prediction probability is then calculated. p With quality-perceived soft labels q Binary cross-entropy loss (BCE) between (p,q) and BCE (p,q) With adaptive weights W adaptive and sample weight modulation term W smooth By combining these methods, we obtain the adaptive smooth sliding focus classification loss. L ASSFL : L ASSFL = BCE (p,q) · W adaptive · W smooth .

[0040] Querying different candidate objects and corresponding to different defect categories L ASSFLElement-level aggregation and normalization are performed to obtain the final classification loss. This final classification loss is then combined with the bounding box regression loss to form the total training loss. The network parameter gradients are calculated through backpropagation, and the model parameters are updated using the optimizer. This process of forward propagation, ASSFL classification loss calculation, bounding box regression loss calculation, backpropagation, and model parameter updates is repeated until the preset number of training epochs is reached. After training, the model weight file is saved, and the trained model is evaluated using a test set. ASSFL only participates in loss calculation during the model training phase and does not introduce additional network structures or model parameters into the model inference phase. By introducing ASSFL during model training, training fluctuations caused by fixed parameters and segmented weights can be avoided, thereby improving the model's ability to distinguish between defects and background, reducing false negatives and false negatives, and improving the overall detection accuracy, stability, and robustness.

[0041] In summary, through the synergistic effect of the three core innovative modules CA-MSFF, LGFA, and ASSFL, the model improves the detection accuracy of multi-scale, weakly textured, and fuzzy boundary weld defects without changing the end-to-end detection process, reduces missed detections and false detections, and enhances the model training stability and detection robustness in complex industrial scenarios.

[0042] The following ablation experiments were conducted to verify whether the various modules of the core innovation of this invention function in the weld defect detection model. The ablation experiment results are shown in Table 1: Table 1: Ablation experiment results (√ indicates that this module was used).

[0043] 1 √ 79.2 2 √ √ 81.6(↑2.4) 3 √ √ √ 84.1(↑4.9) 4 √ √ √ √ 85.2(↑6.0)

[0044] Ablation experiments show that, compared to the basic RT-DETR-R18 model (mAP50 of 79.2%), the introduction of the CA-MSFF module improves the mAP50 to 81.6%, an increase of 2.4 percentage points. Further, the introduction of the LGFA module further enhances the mAP50 to 84.1%, a total improvement of 4.9 percentage points compared to the basic model. Finally, the introduction of the ASSFL loss function further improves the mAP50 to 85.2%, a total improvement of 6.0 percentage points compared to the basic model, fully validating the synergistic gain effect of the three improved modules.

[0045] In addition, comparative experiments were conducted to verify the effectiveness of the present invention. These comparative experiments selected representative single-stage detection algorithms, two-stage detection algorithms, and DETR-type algorithms in the current object detection field, as well as RT-DETR models with different backbone configurations, for comparison. The results of the comparative experiments are shown in Table 2. Table 2: Comparative experimental results.

[0046] RT-DETR-R18 76.4 71.8 79.2 41.3 74.0 RT-DETR-R34 83.5 70.8 80.6 41.7 76.6 RT-DETR-R50 85.2 73.2 81.9 41.5 78.7 RT-DETR-R101 81.7 74.3 81.4 42.7 77.8 YOLO26 56.0 55.2 57.2 23.9 55.6 YOLOv12 66.1 62.2 67.6 31.5 64.1 YOLO11 58.5 59.5 61.5 25.8 59.0 YOLOv10-s 64.4 58.5 64.9 28.5 61.3 YOLOv10-n 64.8 60.9 67.0 32.3 62.8 YOLOv9-s 72.4 68.0 74.0 33.3 70.1 YOLOv8 66.7 66.5 69.7 31.0 66.6 YOLOv6 57.8 57.8 61.8 29.3 57.8 YOLOv5 58.7 62.5 62.6 28.9 60.5 Faster R-CNN — 38.9 58.8 22.5 — Deformable DETR — 50.5 57.8 25.2 — RT-DETR-AdaFusion (ours) 84.9 77.0 85.2 44.9 80.8

[0047] As shown in Table 2, compared with the RT-DETR series models, the model of this invention improves the mAP50 and F1 scores by 3.3 and 2.1 percentage points, respectively, and the recall and mAP50-95 scores by 2.7 and 2.2 percentage points, respectively, compared with RT-DETR-R101. Compared with YOLOv9-s, which has good performance among single-stage algorithms, its mAP50, mAP50-95, and F1 scores are improved by 11.2, 11.6, and 10.7 percentage points, respectively. Compared with Faster R-CNN and Deformable DETR, the mAP50 is improved by 26.4 and 27.4 percentage points, respectively. Combined with the overall detection metrics, it can be seen that the model of this invention exhibits better recognition and localization performance in test samples containing defects with small scale, low contrast, and difficult localization.

[0048] In another embodiment, a computer-readable storage medium is also proposed, which stores a computer program / instructions. When the computer program / instructions are executed by a processor, they implement the steps of the X-ray weld defect detection method based on multi-scale feature enhancement described in the above embodiments. The computer-readable storage medium may include, but is not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.

[0049] In another embodiment, a computer program product is also proposed, comprising a computer program / instructions. This computer program / instructions are used to cause a computer to perform the steps of the X-ray weld defect detection method based on multi-scale feature enhancement described in the above embodiments. The computer program / instructions may exist in a computer-readable medium in forms including, but not limited to, source files, executable files, and installation package files. Accordingly, the computer program / instructions may be executed by a computer in ways including, but not limited to: the computer directly executing the instructions; the computer compiling the instructions and then executing the corresponding compiled program; the computer reading and executing the instructions; or the computer reading and installing the instructions and then executing the corresponding installed program.

[0050] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0051] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.

Claims

1. A method for detecting X-ray weld defects based on multi-scale feature enhancement, characterized in that, It includes: Construct a weld defect detection model; The weld defect detection model uses the RT-DETR network as its base network. A channel-aware multi-scale feature fusion module (CA-MSFF) and a local gated feature attention module (LGFA) are constructed in its high-level semantic feature processing position and top-down feature fusion path. The CA-MSFF is used to enhance the semantic information of defects at different scales through multi-scale convolution, residual connections, and channel recalibration. The LGFA is used to strengthen the edge, texture, and directional contextual information of the defect region through local attention, bi-branch enhancement, and gating mechanisms. The X-ray weld image is input into the weld defect detection model for identification; the weld defect detection model first outputs feature maps of three different scales through a backbone network. P 3. P 4. P 5; Next, P 5. Input CA-MSFF processing to obtain high-level enhanced features Y 5; will Y 5 and P 4. After fusion, the input is processed by LGFA to obtain the mid-layer enhancement features. Y 4; will Y 4 and P 3. Fusion yields high-resolution detection features X 3; will X 3 and Y 4. Fusion yields medium-resolution detection features ;Will and Y 5. Fusion yields low-resolution detection features ;Will X 3. , Input the inspection head to obtain the defect type and location of the weld.

2. The X-ray weld defect detection method based on multi-scale feature enhancement according to claim 1, characterized in that, The weld defect detection model includes: The backbone network is used to process X-ray weld images and output feature maps at three different scales. P 3. P 4. P 5; The hybrid encoder includes: an AIFI attention layer and a channel-aware multi-scale feature fusion module (CA-MSFF); the AIFI attention layer is used to build high-level feature maps. P 5. The associations between different spatial locations within the interior are used to obtain the encoded high-level semantic features. X High-level semantic features X High-level enhanced features are obtained by processing the input CA-MSFF. Y 5; The neck network comprises: a fusion branch, a localized feature attention module (LGFA), and an aggregation branch; the fusion branch is used to fuse high-level augmentation features. Y 5. Mid-layer feature map P 4. Obtaining mid-layer fusion features F in It is also used to fuse mid-layer enhancement features. Y 4. Shallow feature map P 3. Obtain high-resolution detection features X 3; LGFA is used for mid-layer fusion features F in Processing yields mid-layer enhancement features Y 4; Aggregation branches are used to aggregate high-resolution detection features. X 3. Mid-layer enhancement features Y 4. Obtain medium-resolution detection features It is also used to aggregate medium-resolution detection features. High-level enhanced features Y 5. Obtain low-resolution detection features ; The query selection module is used for high-resolution detection features. X 3. Medium resolution detection features Low-resolution detection features Multi-scale encoded features are obtained by flattening and location encoding; the quality of candidate features in the multi-scale encoded features is evaluated, and the candidate feature with the highest classification confidence and location quality is selected as the initial object query. The head network includes a decoder and a detection head. The decoder outputs an object query based on the interaction information between the initial object query and the multi-scale encoded features. The detection head outputs the defect category and location of the weld based on the object query.

3. The X-ray weld defect detection method based on multi-scale feature enhancement according to claim 2, characterized in that, The channel-aware multi-scale feature fusion module CA-MSFF includes: Four convolutional branches; one of the convolutional branches is used to process high-level semantic features. X Mapped to C The channel obtains intermediate features F 1; The other three convolutional branches extract high-level semantic features using convolutional kernels of different sizes. X The receptive field information yields the corresponding intermediate features. F 3. F 5. F 7; The channel attention module is used to process high-level semantic features. X After performing global average pooling and global max pooling respectively, the channel attention weights are fused to generate the channel attention weights. W c ; Residual fusion unit, which is used to integrate intermediate features F 1. F 3. F 5. F 7. Multi-scale fused features are obtained by concatenating and convolving the data. F fusion Multi-scale fusion features F fusion With high-level semantic features X The residuals are summed and then combined with the channel attention weights. W c Channel-by-channel multiplication yields high-level enhancement features Y 5.

4. The X-ray weld defect detection method based on multi-scale feature enhancement according to claim 2, characterized in that, The Localized Feature Attention Module (LGFA) includes: Local extraction units, which are used for mid-level fusion features F in Local importance maps are obtained by extracting local defect features with strong responses. A l ; The bi-branch local feature enhancement unit, which is important to the local importance map A l Local feature enhancement processing is performed to obtain bi-branch enhanced features. F e ; Gating unit, which integrates features from the middle layer F in The first channel is selected as the representative spatial response to obtain a single-channel spatial gating diagram. G ; The fusion unit integrates mid-layer fusion features. F in Dual-branch enhancement features F e Single-channel space gating diagram G Element-wise multiplication yields the mid-layer enhancement features. Y 4.

5. The X-ray weld defect detection method based on multi-scale feature enhancement according to claim 4, characterized in that, The dual-branch local feature enhancement unit includes: Dimensionality reduction unit, which reduces the local importance graph A l The number of channels is determined by C Compress to N Dimensionality reduction features are obtained ; Spatial convolution branch, which affects dimensionality reduction features After performing feature enhancement processing, it is then combined with dimensionality reduction features. The residuals are summed to obtain the spatial branch output features. F sp ; Directional context branching, which extracts dimensionality-reduced features The local dependencies in the width direction yield the directional context branch output features. F 3d ; Fusion output unit, which is for F sp , F 3d After splicing, activate and restore to the number of channels. C The bi-branch enhancement feature was then obtained. F e .

6. The X-ray weld defect detection method based on multi-scale feature enhancement according to claim 1, characterized in that, The weld defect detection model is used for inference after training; training methods include: During the training phase, the probability of the category is predicted based on the output of the weld defect detection model. p Quality-aware soft labels generated during the sample matching process q The adaptive smooth sliding focus classification loss is calculated based on the matching quality between the predicted bounding box and the true defect bounding box. L ASSFL ; Querying different candidate objects and corresponding to different defect categories L ASSFL Element-level aggregation and normalization are performed to obtain the final classification loss. The final classification loss and the bounding box regression loss are combined to form the total training loss. The gradient of the network parameters is calculated through backpropagation, and the model parameters are updated using the optimizer until the preset number of training rounds is reached to complete the model training.

7. The X-ray weld defect detection method based on multi-scale feature enhancement according to claim 6, characterized in that, The adaptive smooth sliding focus classification loss was calculated. L ASSFL The methods include: In the t In each training iteration, the IoU between the predicted bounding box of each positive sample in the current batch and its corresponding ground truth defect bounding box is calculated, and the IoU of the positive samples is averaged to obtain the positive sample quality statistic for the current batch. ; The positive sample quality statistic for the current batch is calculated using an exponential moving average mechanism. The model is updated to obtain a smoothed IoU statistic that reflects the historical prediction quality of the weld defect detection model. ; Based on smoothed IoU statistics Calculate adaptive focusing parameters γ adaptive ; Based on adaptive focusing parameters γ adaptive Calculate the adaptive weights for different candidate object queries W adaptive : ; In the formula, α Represents the negative sample balance coefficient. y This indicates the prospective indicator for the candidate object query; Based on quality perception soft labels q Constructing a positive sample mask indicator function M pos When the current candidate query is a positive sample, When the current candidate object query is a background sample, ; Based on positive sample mask indicator function M pos Constructing sample weight modulation terms W smooth : ; λ 1 and λ 2 represents the weight enhancement coefficients of the Gaussian and Sigmoid terms, respectively; σ is the smoothing control coefficient; Calculate the predicted probability of the category p With quality-perceived soft labels q Binary cross-entropy loss (BCE) between (p,q) and BCE (p,q) With adaptive weights W adaptive and sample weight modulation term W smooth By combining these methods, we obtain the adaptive smooth sliding focus classification loss. L ASSFL .

8. The X-ray weld defect detection method based on multi-scale feature enhancement according to claim 7, characterized in that, Positive Sample Quality Statistics The calculation formula is: ; ; In the formula, d t The dynamic attenuation coefficient, β This is the control coefficient for maximum attenuation intensity. τ This is the smooth speed control coefficient; And / or, adaptive focus parameters γ adaptive The calculation formula is: ; In the formula, γ 0 is the base focusing parameter. λ γ To adaptively adjust the intensity coefficient, θ As a reference threshold, IoU EMA To use the smoothed IoU statistic Updated historical IoU statistics γ min For the minimum focusing parameter, γ max This is the maximum focusing parameter; And / or, adaptive smooth sliding focus classification loss L ASSFL The expression is: L ASSFL = BCE (p,q) · W adaptive · W smooth 。 9. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the X-ray weld defect detection method based on multi-scale feature enhancement as described in any one of claims 1 to 8.

10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the X-ray weld defect detection method based on multi-scale feature enhancement as described in any one of claims 1 to 8.