A method and system for defect detection oriented to X-ray weld seam images

By using a multi-backbone shared network and a hybrid attention fusion mechanism, the problem of multi-scale feature extraction and fusion in X-ray weld images was solved, achieving high-precision and high-efficiency defect detection, improving detection accuracy and reducing computational complexity.

CN121437509BActive Publication Date: 2026-04-14WUHAN INST OF TECH +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-30
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing technologies struggle to achieve multi-scale feature extraction and fusion in X-ray weld image defect detection, making it difficult to balance detection accuracy and inference efficiency. This is especially true when dealing with small targets and complex background interference, resulting in high false detection and false negative rates and insufficient generalization ability.

Method used

We employ a multi-backbone shared network and a collaborative architecture combining hybrid attention fusion and directional receptive field enhancement. By combining feature pyramids and a three-scale detection head, we achieve cross-branch semantic alignment and weighted fusion of multi-scale features and introduce directional squeezing convolution to optimize parameter efficiency.

Benefits of technology

It significantly improves the detection accuracy of multi-scale, small-target defects, enhances robustness to complex background interference, reduces the number of parameters and increases the inference frame rate, achieving high-precision and high-efficiency detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121437509B_ABST
    Figure CN121437509B_ABST
Patent Text Reader

Abstract

The application discloses a kind of X-ray weld seam image-oriented defect detection method and system, belong to computer vision and nondestructive testing technical field.The method includes: through double-path parallel initial convolution, shared dry end is constructed, and shared shallow layer feature is parallelly input three functionally divided backbone branches to obtain multi-scale feature;Cross-branch feature of the same scale is fused by using the mixed attention fusion block containing local path and global path for semantic alignment and weighted fusion;Directional extrusion convolution is introduced in the backbone and backflow stage to expand the effective receptive field and control the parameter amount;Finally, the feature pyramid and three-scale detection head are combined to complete the defect class and position prediction.The experiment shows that the method improves the detection ability of small size, low contrast weld defects, and improves the detection accuracy while maintaining real-time, which can effectively solve the problems of multi-scale defect detection, small target blur and complex background interference in X-ray images.
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 based on computer vision, and more specifically, to a defect detection method and system for X-ray weld images. Background Technology

[0002] In the manufacturing and in-service inspection of critical industrial components such as pipelines and pressure vessels, the quality of welded joints directly determines the load-bearing capacity and service safety of the equipment. X-ray non-destructive testing technology, due to its ability to non-contactly image internal weld defects (such as cracks, lack of fusion, incomplete penetration, porosity, and slag inclusions), has become an important means of quality inspection in industrial settings. As industrial production lines develop towards automation and intelligence, the requirements for inspection systems are increasing. These systems not only need to achieve high-precision identification of various types and scales of defects, but also need to meet the demands of high-speed, high-robust online inspection within the limited computing resources available in industrial settings.

[0003] Currently, defect detection technologies based on X-ray weld images are mainly divided into two categories:

[0004] The first category is based on traditional image processing and machine learning methods. These methods typically rely on thresholding, edge detection, and morphological operations to extract candidate regions, and then combine hand-designed features (such as texture and shape features) to train a classifier for defect identification. However, X-ray images generally suffer from low contrast, strong noise interference, and numerous structural artifacts, making it difficult for these methods to extract defect features stably and accurately. Especially when faced with small target defects and complex background texture interference, the false positive and false negative rates are high, and the generalization ability and stability are insufficient.

[0005] The second category is deep learning-based object detection methods. In recent years, end-to-end detectors, represented by the YOLO series, have been introduced into the field of weld defect recognition, achieving significant progress thanks to their powerful feature learning capabilities. However, directly applying existing general object detection models to weld defect detection scenarios still faces several prominent bottlenecks:

[0006] 1. Insufficient multi-scale representation: A single backbone network path struggles to extract semantic features from targets of different sizes in a balanced manner. Shallow features of small targets and fine-grained defects are easily submerged in deep networks, resulting in insufficient sensitivity of the model to minute defects.

[0007] 2. Insufficient fusion of heterogeneous features: In structures such as feature pyramids, feature maps from different levels or branches differ semantically (i.e., a "semantic gap"). Simple concatenation or weighted summation operations are insufficient to achieve effective semantic alignment, easily introducing redundant noise or alignment bias, thus weakening the representational power of the fused features.

[0008] 3. Trade-off between receptive field and computational efficiency: Expanding the receptive field helps the model capture a wider range of contextual information to suppress background interference, but it is usually accompanied by an increase in the size of the convolutional kernel, an increase in the number of parameters, and an increase in computational latency, which is not conducive to real-time online deployment in resource-constrained industrial sites.

[0009] In summary, existing technologies have not yet achieved an ideal balance between detection accuracy and inference efficiency when dealing with challenges such as multi-scale defects, small target blurring, and complex background interference in X-ray weld images. Therefore, there is an urgent need for a defect detection method that can specifically enhance multi-scale feature extraction and fusion capabilities while maintaining high accuracy and low latency to meet the stringent requirements of modern industrial quality inspection. Summary of the Invention

[0010] This invention addresses the technical problems existing in the prior art by providing a defect detection method and system for X-ray weld images. Through a collaborative architecture of multiple backbone sharing, hybrid attention fusion, and directional receptive field enhancement, it achieves both high precision and high efficiency in computer vision-based non-destructive testing.

[0011] According to a first aspect of the present invention, a defect detection method for X-ray weld images is provided, comprising:

[0012] S1, Acquire X-ray weld images and perform defect adaptation preprocessing;

[0013] S2, Based on a multi-backbone shared network, shared shallow features are extracted from the preprocessed image, and heterogeneous features of different scales and different semantic levels are extracted based on the shared shallow features;

[0014] S3 uses a hybrid attention fusion mechanism to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency.

[0015] S4, based on feature pyramids and a three-scale detection head, identifies the category and location prediction results of defects based on the fused and enhanced multi-scale features.

[0016] Based on the above technical solution, the present invention can also be improved as follows.

[0017] Optionally, in step S1, during the model training phase, the defect adaptability preprocessing includes:

[0018] S101, Adaptive grayscale normalization of the image, including: based on the grayscale distribution statistics of the weld area, mapping the image grayscale values ​​to a specific range to enhance the contrast between the weld and the background;

[0019] S102, Perform multi-scale conformal scaling on the image, including: scaling the image to multiple preset sizes while maintaining the original aspect ratio of the weld seam, in order to generate multi-scale training samples;

[0020] S103, the image is processed using a defect-aware enhancement combination strategy, the strategy including:

[0021] a) Combine affine transformation with small target copying and pasting to increase the sample diversity of small target defects;

[0022] b) Combine global brightness contrast perturbation with adaptive histogram equalization based on weld region characteristics to optimize the contrast of the weld region.

[0023] c) Apply directional Gaussian blur along the X-ray scanning direction to simulate texture interference in a specific direction;

[0024] d) Image stitching based on the continuity of weld structure.

[0025] Optionally, step S2 includes:

[0026] S201, based on the shared stem end with a dual-path parallel initial convolutional structure, extracts shared shallow features. The first path uses a 3×3 standard convolution to extract local edge details, and the second path uses a 5×5 depth-separable convolution to capture large-scale texture patterns. The two outputs are then concatenated by a 1×1 convolution to generate shared shallow features F0.

[0027] S202, the shared shallow feature F0 is simultaneously input into three differentiated parallel backbone branches to extract heterogeneous features at different scales and semantic levels, wherein:

[0028] The first backbone branch focuses on the surface texture details of the weld and the edge features of small targets, outputting a feature map at the first scale;

[0029] The second backbone branch focuses on capturing the mesoscale weld structure and background context, and outputs a feature map at the second scale.

[0030] The third backbone branch focuses on extracting large-scale weld contours and global semantic information, and outputs a feature map at the third scale.

[0031] S203 reuses shallow features of each backbone branch through a cross-branch feature caching mechanism.

[0032] Optionally, the shared trunk adopts a dual-path parallel structure, specifically including:

[0033] The first path uses a standard 3x3 convolution to extract local edge details;

[0034] The second approach uses 5x5 depthwise separable convolutions to capture large-scale texture patterns.

[0035] The outputs of the first path and the second path are concatenated to generate the shared shallow feature.

[0036] Optionally, in step S3, the cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels through a hybrid attention fusion mechanism includes:

[0037] Linear projection is performed on heterogeneous features of different scales and semantic levels of the input to obtain basic features;

[0038] The base features are fed into the local attention path and the global attention path in parallel.

[0039] The local attention path uses a convolutional operation with a first dilation rate to capture local detail dependencies;

[0040] The global attention path uses convolutional operations with a second dilation rate greater than the first dilation rate to capture global context dependencies;

[0041] The outputs of the local attention path and the global attention path are fused with the base features, and after channel compression, local geometric enhancement is performed sequentially through group convolution or RepConv, and finally integrated output is obtained.

[0042] Optionally, step S3, the directional compression convolution operation, includes:

[0043] Perform asymmetric zero-padding in multiple directions on the input feature map;

[0044] One-dimensional convolution is applied to the features after padding in each direction to obtain multi-path one-dimensional convolution output features;

[0045] Channel concatenation is performed on the output features of one-dimensional convolutions in multiple directions.

[0046] Small kernel convolution is used to fuse and downsample the concatenated features.

[0047] Optionally, step S4 includes:

[0048] The multi-scale features fused and enhanced in step S3 are input into the feature pyramid network for top-down and bottom-up feature fusion to generate an enhanced multi-scale feature pyramid.

[0049] The feature pyramid is input into a three-scale detection head to predict the class probability and bounding box location of defects on feature maps of three different resolutions.

[0050] Optionally, the three-scale detector head also predicts the distribution values ​​of the bounding boxes for bounding box regression using distributed focus loss.

[0051] Optionally, step S4 also includes:

[0052] The prediction results are post-processed using a non-maximum suppression algorithm to obtain the final defect detection box.

[0053] According to a second aspect of the present invention, a defect detection system for X-ray weld images is provided, comprising:

[0054] The acquisition and preprocessing module is used to acquire X-ray weld images and perform defect adaptation preprocessing.

[0055] The multi-scale feature extraction module is used to extract shared shallow features from the preprocessed image based on a multi-backbone shared network, and to extract heterogeneous features of different scales and different semantic levels based on the shared shallow features.

[0056] The feature fusion and enhancement module is used to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels through a hybrid attention fusion mechanism, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency.

[0057] The result prediction module is used to identify the category and location of defects based on the feature pyramid and the three-scale detection head, according to the fused and enhanced multi-scale features.

[0058] According to a third aspect of the present invention, an electronic device is provided, including a memory and a processor, wherein the processor is configured to execute a computer management program stored in the memory to implement the steps of the above-described defect detection method for X-ray weld images.

[0059] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, on which a computer management class program is stored, which, when executed by a processor, implements the steps of the above-described defect detection method for X-ray weld images.

[0060] This invention provides a defect detection method, system, electronic device, and storage medium for X-ray weld images. It achieves shallow feature reuse and multi-scale heterogeneous feature extraction by constructing a multi-backbone shared network, utilizes a hybrid attention fusion mechanism to complete semantic alignment and adaptive weighting of cross-branch features, and introduces directional compression convolution to expand the effective receptive field in a lightweight manner of "multi-core parallelism-stitching-compression." Finally, it combines a feature pyramid with a three-scale detection head to achieve multi-level feature collaborative prediction. This method systematically enhances the model's ability to capture multi-scale, small-target defects in X-ray images, improves robustness to complex background interference, significantly suppresses complex background interference, and improves detection accuracy (e.g., mAP improvement of 5.2%–7.8%) while reducing the number of parameters by 12% through structural optimization, achieving a higher inference frame rate (e.g., 89 FPS), effectively balancing the dual requirements of accuracy and efficiency in industrial weld defect detection. Attached Figure Description

[0061] Figure 1 A flowchart of a defect detection method for X-ray weld images provided by the present invention;

[0062] Figure 2 A block diagram of a defect detection system for X-ray weld images provided by the present invention;

[0063] Figure 3 A schematic diagram of the hardware structure of a possible electronic device provided by the present invention;

[0064] Figure 4 This is a schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. Detailed Implementation

[0065] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.

[0066] Figure 1 A flowchart of a defect detection method for X-ray weld images provided by this invention is shown below. Figure 1 As shown, the method includes steps S1 to S4:

[0067] S1, acquire X-ray weld images and perform defect adaptation preprocessing;

[0068] S2, based on a multi-backbone shared network, extracts shared shallow features from the preprocessed image, and extracts heterogeneous features of different scales and different semantic levels based on the shared shallow features;

[0069] S3 uses a hybrid attention fusion mechanism to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency.

[0070] S4, based on feature pyramids and a three-scale detection head, identifies the category and location prediction results of defects based on the fused and enhanced multi-scale features.

[0071] Understandably, given the shortcomings in the background technology, this invention proposes a defect detection method, system, electronic device, and storage medium for X-ray weld images. It achieves shallow feature reuse and multi-scale heterogeneous feature extraction by constructing a multi-backbone shared network, utilizes a hybrid attention fusion mechanism to complete semantic alignment and adaptive weighting of cross-branch features, and introduces directional compression convolution to expand the effective receptive field in a lightweight "multi-core parallel-stitching-compression" manner. Finally, it combines a feature pyramid with a three-scale detection head to achieve multi-level feature collaborative prediction. This method systematically enhances the model's ability to capture multi-scale, small-target defects in X-ray images, improves robustness to complex background interference, significantly suppresses complex background interference, and improves detection accuracy (e.g., mAP improvement of 5.2%–7.8%) while reducing the number of parameters by 12% through structural optimization, achieving a higher inference frame rate (e.g., 89 FPS), effectively balancing the dual requirements of accuracy and efficiency in industrial weld defect detection.

[0072] Based on the above embodiments, the technical solution of the present invention can be further improved as follows.

[0073] In one possible embodiment, step S1 mainly includes acquiring an X-ray weld image and preprocessing the acquired image.

[0074] The X-ray weld images obtained mainly come from typical industrial scenarios such as circumferential welds of pressure vessels and butt welds of pipelines. The defects in the images mainly include five types of weld defects, such as cracks, lack of fusion, incomplete penetration, porosity, and slag inclusions.

[0075] If the collected X-ray weld images are used for model training, they need to cover typical scenarios such as standard butt welds and T-joint welds, and label the defect categories and locations with bounding boxes.

[0076] In practice, a dual process of high-precision annotation tools and manual verification can be adopted: the defect boundary is selected based on the LabelImg tool to ensure that the bounding box overlaps with the actual contour of the defect, and samples with an overlap rate of <85% are re-annotated, ultimately forming a training / validation / test set with annotation consistency ≥95%. The samples can be divided into training / validation / test sets in an 8:1:1 ratio.

[0077] Based on the enhancement strategy of defect perception and customized standardization, the acquired images are preprocessed for defect adaptation, specifically including sub-steps S101~S103.

[0078] S101, performing adaptive grayscale normalization on the image, including: mapping the image grayscale values ​​to a specific range based on the grayscale distribution statistics of the weld area, in order to enhance the contrast between the weld and the background.

[0079] For example, the grayscale distribution of the weld area in the image can be extracted (the mean μ and variance σ of the weld area can be calculated), and the image grayscale values ​​can be normalized to the range of [μ-2σ, μ+2σ] to enhance the contrast between the weld and the background, so as to solve the problem of "uneven grayscale and low contrast in the weld area" in X-ray images.

[0080] S102, Perform multi-scale conformal scaling on the image, including: scaling the image to multiple preset sizes while maintaining the original aspect ratio of the weld seam, in order to generate multi-scale training samples to solve the problem of "poor adaptability of single-scale model to defects of different sizes".

[0081] For example, a single-channel input After linear normalization and standardization, scale / fill to size. (S is preferred 640), achieved using the following formula:

[0082] .

[0083] in, For the normalized result, To standardize the processing results, To scale / fill the result.

[0084] S103, addressing the challenges of small target blurring, texture interference, and sample imbalance in X-ray weld seams, a defect perception enhancement combination strategy is employed to process the image. This strategy includes a)~d):

[0085] a) Combine affine transformation with small target copy-paste to increase the sample diversity of small target defects.

[0086] For example, based on affine transformation (translation / rotation), small target defects with an area of ​​<100 pixels² are identified through target detection, and copied to 3-5 different locations in the image. This retains the enhancement of general geometric transformations while increasing the sample size of small targets.

[0087] b) Combine global brightness contrast perturbation with adaptive histogram equalization based on weld region characteristics to optimize the contrast of the weld region.

[0088] For example, based on the global brightness contrast perturbation, the parameters are dynamically adjusted according to the weld structure characteristics (direction / curvature / defect density), and histogram equalization and edge smoothing are applied only to the weld mask area, which retains the general brightness adjustment and solves the problem of grayscale overlap in the weld area.

[0089] c) Apply directional Gaussian blur along the X-ray scanning direction to simulate texture interference in a specific direction.

[0090] For example, applying Gaussian blur along the X-ray scanning direction (perpendicular to the weld direction) serves as a directional noise perturbation for the affine transformation, enhancing the model's robustness to scan texture interference.

[0091] d) Image stitching based on the continuity of weld structure.

[0092] For example, weld structure Mosaic splicing optimization of general Mosaic: multiple weld images are spliced ​​together according to the weld direction to maintain structural continuity, avoid defect deformation caused by general Mosaic, and improve the realism of small targets.

[0093] It is understandable that the targeted defect adaptation preprocessing method in this embodiment ensures data consistency through normalization and standardization, and adopts a defect perception enhancement strategy that includes affine transformation, brightness and contrast perturbation, and Mosaic hybrid stitching. This effectively improves the diversity and quality of training data, significantly enhances the model's sensitivity and detection rate for small targets and low-contrast defects, and improves the model's generalization ability to different imaging conditions and workpiece postures. It provides a high-quality input foundation for subsequent advanced processing modules such as multiple backbone networks and hybrid attention fusion, providing key support from the data source for the overall solution to achieve high-precision and high-robust detection results.

[0094] In one possible embodiment, step S2 includes sub-steps S201~S203: S201, extracting shared shallow features based on the shared stem end using a dual-path parallel initial convolutional structure, wherein the first path uses a 3×3 standard convolution (output channel) (Stride 2), extracting local edge details; the second path uses a 5×5 depthwise separable convolution (output channels). (Step size 2), capture large-scale texture patterns.

[0095] The outputs of the first and second paths are concatenated using a 1×1 pointwise convolution to generate shared stem features. This enables the initial fusion of shallow multi-scale features, providing a basis for differentiated inputs for subsequent branches.

[0096] It is understandable that this embodiment differs from the single initial convolution of traditional YOLOv11 by designing HGStem with multi-branch parallel initial convolution to achieve multi-scale capture and sharing of shallow edge and texture features.

[0097] S202 sets up three parallel backbone branches as multi-path feature extraction and shared links for parameter reuse.

[0098] In this step, the shared trunk characteristics obtained in step S201 are used. To unify the input, three differentiated parallel backbone branches are constructed to extract heterogeneous features at different scales and semantic levels. Each branch achieves parameter reuse and shallow feature sharing through "core module combination + feature caching".

[0099] Specifically, among them:

[0100] 1. The first backbone branch serves as a texture enhancement path, focusing on the texture details of the weld surface and the edge features of small targets, and outputs a feature map at the first scale.

[0101] For example, the module combination of the first backbone branch is: shared trunk module HGStem output. →Feature extraction basic unit C3k2 module (replace the Bottleneck of the regular C3k2 module with a residual attention block) →DSConv (directional compression convolution, dilation rate d=2, enhances horizontal / vertical features).

[0102] The output features of the first backbone branch are: P3 / 8 scale feature map (resolution S / 8×S / 8, number of channels C1), focusing on weld surface texture and small target edges.

[0103] 2. The second backbone branch serves as a multi-scale context path, focusing on capturing the mesoscale weld structure and background context, and outputting a feature map at the second scale.

[0104] For example, the module combination of the second backbone branch is: shared trunk module HGStem output. →DWConv (Depthwise separable convolution, channel expansion factor 4) →HGBlock (Lightweight multiscale block, containing 1×1 convolution + 3×3 convolution + 5×5 dilated convolution, dilation rate d=1 / 3 / 5).

[0105] The output features of the second backbone branch: P4 / 16 scale feature map (resolution S / 16×S / 16, number of channels C2), capturing the medium-scale weld structure and background context.

[0106] 3. The third backbone branch serves as a global semantic path, focusing on extracting large-scale weld contours and global semantic information, and outputting a feature map at the third scale.

[0107] For example, the module combination of the third backbone branch is: shared trunk module HGStem output. → Cross-branch feature caching module (shares shallow features of branch 1 / 2, reducing redundant calculations) → Dual-path HGBlock (lightweight multi-scale block, one path of 3×3 convolution, one path of 7×7 dilated convolution, dilation rate d=4).

[0108] The output features of the third backbone branch are: P5 / 32 scale feature map (resolution S / 32×S / 32, number of channels C3), which extracts large-scale weld contours and global semantic information.

[0109] S203, based on the shallow feature sharing mechanism, realizes cross-branch feature caching and reuse, that is, reuses the shallow features of each backbone branch through the cross-branch feature caching mechanism.

[0110] For example, in the shared cache module: after extracting feature maps at scales of P3 / 8, P4 / 16, and P5 / 32 in each of the above parallel backbone branches, the parallel outputs at each level are then subjected to cross-branch semantic alignment and fusion by subsequent HAFB.

[0111] Reuse logic: When performing cross-branch semantic alignment, the subsequent HAFB (Hybrid Attention Fusion Block) module prioritizes reading shallow features from the cache to avoid redundant calculations.

[0112] In this embodiment, the input image is first pre-processed using a shared stem (HGStem). This shared stem employs dual-path parallel convolution (3x3 standard convolution and 5x5 depthwise separable convolution) to simultaneously capture local details and large-scale textures from the source, generating a rich, multi-scale shared shallow feature set. This serves as a unified, high-quality input foundation for all subsequent parallel backbone branches. Then, shallow features are shared. The parallel input consists of three specialized backbone branches: The C3k2 module, integrating residual attention blocks and directional compression convolution (DSConv), focuses on amplifying the microscopic texture and small target edge features of the weld surface; the HGBlock, incorporating depthwise separable convolutions and multi-scale dilated convolutions, captures mid-scale structural information and background context to understand the relationship between defects and their surroundings; and the dual-path HGBlock (containing large-kernel dilated convolutions) extracts macroscopic weld contours and global semantic information. Finally, a cross-branch feature caching mechanism is introduced, allowing shallow features extracted from each branch to be directly called by the subsequent Hybrid Attention Fusion (HAFB) module, avoiding redundant computation and achieving efficient reuse of parameters and computational resources.

[0113] In this embodiment, the efficient extraction and reuse of shallow multi-scale features is achieved through a shared backbone (HGStem). Differentiated feature extraction is performed by relying on three functionally specialized parallel backbone branches (texture enhancement, context awareness, and global semantic path). Combined with a cross-branch feature caching mechanism, the model's detection accuracy and generalization ability for multi-scale and small-target defects in welds are significantly improved. At the same time, the computational complexity is effectively controlled through parameter sharing and computation reuse, achieving a balance between high accuracy and high real-time performance.

[0114] In step S3, the semantic alignment and fusion of features of different backbone branches at the same scale are mainly achieved through the Hybrid Attention Fusion Module (HAFB).

[0115] In one possible embodiment, step S3, which involves performing cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels using a hybrid attention fusion mechanism, includes sub-steps S301-S303:

[0116] S301 performs linear projection on heterogeneous features of different scales and semantic levels of the input to obtain basic features.

[0117] For example, in one embodiment: Input The number of channels are respectively The output channel is Hidden passage .

[0118] Linear projection and basis priors are performed using the following formula:

[0119] .

[0120] in, Indicates based on input quantity The obtained linear projection, Indicates based on input quantity The obtained linear projection, Indicates based on linear projection and linear projection The obtained basis features.

[0121] S302, Local / Global Parallel Path: The base features are fed into the local attention path and the global attention path in parallel;

[0122] The local attention path uses a convolutional operation with a first dilation rate to capture local detail dependencies;

[0123] The global attention path uses convolutional operations with a second dilation rate greater than the first dilation rate to capture global context dependencies.

[0124] For example, the linear projection of the previous step and Apply "local path (expansion rate)" respectively ")" and "global path" Extracting fine-grained details and contextual dependencies yields the following:

[0125] .

[0126] S303, Three-way fusion and compression: The outputs of the local attention path and the global attention path are fused with the base features. After channel compression, local geometric enhancement is performed sequentially through group convolution or RepConv, and finally integrated output is obtained.

[0127] For example, the outputs of the local attention path and the global attention path are fused with the base features and compressed to... Channels, then local geometry is enhanced with RepConv of group convolutions, and then with The linearly integrated output is represented as follows:

[0128] .

[0129] in, Y represents the result after fusion and compression, and Y represents the linear integration output result.

[0130] Understandably, in this embodiment, feature alignment is established by linear projection of Hybrid Attention Fusion Block (HAFB), and a parallel architecture of local attention path and global attention path is adopted. Convolutional operations with different dilation rates are used to capture detailed features and contextual dependencies. Finally, semantic alignment and adaptive weighting of cross-scale features are achieved through three-way feature fusion and channel compression mechanisms. This effectively solves the semantic gap problem when fusion of heterogeneous features and significantly improves the model's ability to discriminate defect features and its robustness in detecting them in complex backgrounds.

[0131] In one possible embodiment, step S3, the directional compression convolution (DSConv) operation, includes:

[0132] S304 performs asymmetric zero-padding in multiple directions on the input feature map;

[0133] One-dimensional convolution is applied to the features after padding in each direction to obtain multi-path one-dimensional convolution output features;

[0134] Channel concatenation is performed on the output features of one-dimensional convolutions in multiple directions.

[0135] Small kernel convolution is used to fuse and downsample the concatenated features.

[0136] Understandably, DSConv is used to expand the directional receptive field while balancing downsampling and channel compression fusion.

[0137] For example, given input Core size (Option 3), Step size (Option 2) Set four groups of asymmetric zero-fill ,through and Two types of 1D convolutions yield four-way features, with each output channel being... splicing the channels and Convolutional fusion, represented as:

[0138] .

[0139] in, This indicates that four sets of asymmetric zero-padding operations are performed on the input quantity X. This represents the four-way features obtained from convolution. Y represents the features obtained by concatenating the concatenated features in the output channel, and Y represents the fused features obtained by convolutional fusion of the concatenated features.

[0140] In this embodiment, DSConv replaces conventional convolutional / downsampling layers in multiple places in the backbone, improving the effective receptive field and multi-scale expression at a lower cost, and forms a scale enhancement path of "multi-core parallelism - splicing - compression" in conjunction with C3k2 / HGBlock.

[0141] In one possible embodiment, step S4 includes sub-steps S401-S402:

[0142] S401, the multi-scale features fused and enhanced in step S3 are input into the feature pyramid network for top-down and bottom-up feature fusion to generate an enhanced multi-scale feature pyramid.

[0143] For example, first, upsampling and cross-layer concatenation are performed: the aforementioned P5 / 32 features are upsampled and fused with P4 / 16 to obtain a semantically stronger P4; then upsampled and fused with the aforementioned P3 / 8 features to obtain a high-resolution feature P3 (for small targets).

[0144] Then, backflow and re-fusion are performed: DSConv downsampling backflow to features P4 and P5, and splicing and fusion with the previous features to form a stable three-layer feature pyramid of P3 / P4 / P5.

[0145] S402, the feature pyramid is input to the three-scale detection head to predict the category probability and bounding box position of the defect on the feature maps of three different resolutions.

[0146] Furthermore, the three-scale detection head also predicts the distribution values ​​of the bounding boxes, which are used for bounding box regression through distributed focus loss.

[0147] For example, in a three-scale detection head: at each grid position in each level. Simultaneously predict the category probability vector Bounding box distance representation And (optional) distributed regression logits Used for DFL decoding.

[0148] In this embodiment, a Feature Pyramid Network (FPN) is introduced to achieve multi-scale feature fusion from top to bottom and bottom to top, effectively transmitting and enhancing deep semantic information and shallow localization details. Combined with a three-scale detection head, predictions are made on feature maps of different resolutions. This structure significantly improves the model's adaptability to multi-scale defects, enabling it to accurately classify large-sized defects using high-level features and accurately locate small target defects using low-level high-resolution features. Ultimately, it achieves synergistic optimization of detection accuracy and localization accuracy while maintaining high inference efficiency.

[0149] In one possible embodiment, step S4 further includes:

[0150] The prediction results are post-processed using a non-maximum suppression algorithm to obtain the final defect detection box.

[0151] Understandably, in object detection, detection models (such as three-scale detection heads) will generate multiple overlapping candidate predicted bounding boxes for the same defect target. This is because sliding windows, anchor points, or no-anchor-point mechanisms may make high-confidence predictions at multiple locations around the target. If all these boxes are directly output, the result will be chaotic, with the same defect surrounded by multiple boxes. Therefore, this embodiment performs post-processing on the prediction results to eliminate redundant boxes and improve detection accuracy.

[0152] For example, performing box quality fusion: detection head prediction intersection-over-union (IoU) quality. The resulting composite score is expressed as:

[0153] .

[0154] in, The final composite score represents the final rating of predicted bounding box j for the suspected defective target i. It is used to rank all predicted bounding boxes in the non-maximum suppression (NMS) step, with the highest-scoring box considered optimal. c represents different defect categories. For category confidence, To determine the quality score, It is a score that measures the accuracy of the position of the predicted box j.

[0155] In the post-processing step of the prediction results, the standard NMS, Soft-NMS, or DIoU-NMS algorithm can be selected, specifically as follows:

[0156] Based on the final overall score Descending candidate boxes; standard NMS threshold Soft-NMS can perform exponential decay on high IoU overlapping candidate executions. DIoU-NMS can further enhance the separation of adjacent defects.

[0157] It is understood that this embodiment comprehensively evaluates the classification confidence and localization quality of the predicted bounding box, and uses a non-maximum suppression algorithm to efficiently eliminate redundant detection results, ultimately ensuring that the output defect detection bounding box has both high accuracy and high reliability, which significantly improves the accuracy and usability of industrial quality inspection results.

[0158] To provide a more detailed explanation of the present invention, a brief introduction to the model training and inference involved in the present invention is given below.

[0159] 1. First, a sample set is constructed using the data acquisition and preprocessing methods in step S1 of the aforementioned embodiments, and positive and negative samples are assigned and tasks are aligned.

[0160] For example, using a center prior plus an IoU threshold to obtain a candidate set from the sample set, and using a task-aligned scoring function to select positive samples (keeping the top-k for each ground truth value), can be represented as follows:

[0161] .

[0162] Among them, B ij b is represented by the bounding box distance ij The decoded prediction box, The weighted hyperparameter (preferred range 0.5–2.0) For the true bounding box, IoU(B ij , ) indicates the calculation of prediction box B ij With real frame The degree of overlap, For classification confidence, represent the model's predicted bounding box B. ij The target in the box belongs to the true bounding box. The corresponding specific category The probability of this is calculated. This strategy exhibits higher stability in scenarios with a high density of small targets.

[0163] 2. Constructing the loss function and optimizer

[0164] (1) Construct the classification loss, using Focal Loss, expressed as:

[0165] ;

[0166] Where FL(p,y) is the focus loss value, i.e., the final loss value; p is the predicted probability, and y is the true label. As a weighting factor, is the modulation factor. Preferably, , .

[0167] This focus loss function guides the model to concentrate its limited "attention" on identifying the few, hard-to-judge real defects, thereby significantly improving the model's accuracy and robustness.

[0168] (2) Construct the regression loss, using CIoU, expressed as:

[0169] .

[0170] Where b represents the coordinates of the center point of the prediction box. Represents the center point coordinates of the ground truth bounding box; IoU is the intersection-union ratio, which represents the ratio of the intersection area of ​​the predicted bounding box and the ground truth bounding box to the union area. is the center-to-center distance, representing the Euclidean distance (straight-line distance) between the center points of the predicted bounding box and the ground truth bounding box; c represents the diagonal length of the minimum closure region, i.e., the diagonal length of the smallest rectangular region that can simultaneously enclose both the predicted and ground truth bounding boxes; w and h are the width and height of the predicted bounding box, respectively. h β represents the width and height of the true bounding box; β is the weighting coefficient.

[0171] By using CIoU Loss, the model can not only ensure that the defect is captured when regressing the bounding box of the defect, but also predict a more accurate bounding box with a better shape.

[0172] (3) Construct the distributed border loss, expressed as:

[0173] .

[0174] Among them, L DFL The loss function is the distribution focus loss, where N is the normalization factor, and ∑∑ is a double summation. The first summation iterates through all positions (i, j) of the bounding box that need to be regressed (e.g., each grid point on the feature map). The second summation iterates through the four edges e∈{l,t,r,b} of the bounding box (i.e., left, top, right, bottom); e∈{l,t,r,b} are the edges of the bounding box, and CE is the cross-entropy. For the predicted distribution, This represents the true distribution.

[0175] (4) Total loss, expressed as:

[0176] ;

[0177] in, , , These are the weighting coefficients.

[0178] (5) Training strategy:

[0179] The optimizer is selected using dynamic SGD; mixed-precision AMP and gradient clipping are enabled. The learning rate is set at warm-up time T. w Cosine annealing is applied after the wheel, as shown below:

[0180] .

[0181] in, The learning rate is represented by t, and the time / number of iterations is represented by t. This represents the minimum value. Indicates the initial value. This represents the warm-up period length / switching threshold, and T represents the total cycle length.

[0182] For example, the input size is preferred. Batch size Total rounds The mAP@0.5:0.95 was used as the basis for early termination and model selection.

[0183] Grad-CAM++ is used to weight the gradient and activation of the last convolutional layer to generate a heatmap and overlay it with the detection box. This is used to verify the consistency of the model's attention to weld lines and key defect areas. In particular, it can more finely characterize the attention distribution in small target and low contrast scenes, which can assist in acceptance and human-machine collaborative review.

[0184] Figure 2 A structural diagram of a defect detection system for X-ray weld images provided in an embodiment of the present invention is shown below. Figure 2 As shown, a defect detection system for X-ray weld images includes an acquisition and preprocessing module, a multi-scale feature extraction module, a feature fusion and enhancement module, and a result prediction module, wherein:

[0185] The acquisition and preprocessing module is used to acquire X-ray weld images and perform defect adaptation preprocessing.

[0186] The multi-scale feature extraction module is used to extract shared shallow features from the preprocessed image based on a multi-backbone shared network, and to extract heterogeneous features of different scales and different semantic levels based on the shared shallow features.

[0187] The feature fusion and enhancement module is used to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels through a hybrid attention fusion mechanism, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency.

[0188] The result prediction module is used to identify the category and location of defects based on the feature pyramid and the three-scale detection head, according to the fused and enhanced multi-scale features.

[0189] It is understood that the defect detection system for X-ray weld images provided by the present invention corresponds to the defect detection methods for X-ray weld images provided in the foregoing embodiments. The relevant technical features of the defect detection system for X-ray weld images can be referred to the relevant technical features of the defect detection methods for X-ray weld images, and will not be repeated here.

[0190] Please see Figure 3 , Figure 3 This is a schematic diagram illustrating an embodiment of the electronic device provided in this invention. For example... Figure 3 As shown, this embodiment of the invention provides an electronic device 300, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320. When the processor 320 executes the computer program 311, it performs the following steps:

[0191] S1, acquire X-ray weld images and perform defect adaptation preprocessing;

[0192] S2, based on a multi-backbone shared network, extracts shared shallow features from the preprocessed image, and extracts heterogeneous features of different scales and different semantic levels based on the shared shallow features;

[0193] S3 uses a hybrid attention fusion mechanism to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency.

[0194] S4, based on feature pyramids and a three-scale detection head, identifies the category and location prediction results of defects based on the fused and enhanced multi-scale features.

[0195] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating an embodiment of a computer-readable storage medium provided by the present invention. (See diagram below.) Figure 4 As shown, this embodiment provides a computer-readable storage medium 1400, on which a computer program 1411 is stored. When the computer program 1411 is executed by a processor, it performs the following steps:

[0196] S1, acquire X-ray weld images and perform defect adaptation preprocessing;

[0197] S2, based on a multi-backbone shared network, extracts shared shallow features from the preprocessed image, and extracts heterogeneous features of different scales and different semantic levels based on the shared shallow features;

[0198] S3 uses a hybrid attention fusion mechanism to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency.

[0199] S4, based on feature pyramids and a three-scale detection head, identifies the category and location prediction results of defects based on the fused and enhanced multi-scale features.

[0200] This invention provides a defect detection method, system, and storage medium for X-ray weld images. It achieves shallow multi-scale feature extraction through a dual-path parallel structure of the HGStem multi-backbone network (Multi-Backbone Network), and combines three functionally specialized parallel branches (texture enhancement, context awareness, and global semantic path) to achieve differentiated feature capture. A cross-branch feature caching mechanism significantly improves feature reuse efficiency. The invention utilizes a parallel architecture of local attention paths (dilution rate d=2) and global attention paths (dilution rate d=4) of the Hybrid Attention Fusion Block (HAFB), combined with linear projection and a three-path fusion mechanism, to achieve semantic alignment and adaptive weighting of cross-scale features. A multi-directional asymmetric padding and one-dimensional convolution parallel strategy using directional compression convolution (DSConv) are introduced to expand the effective receptive field in a lightweight manner. Finally, a collaborative architecture of the Feature Pyramid Network (FPN) and a three-scale detection head is used, combined with a task-aligned loss function (FocalLoss and CIoU with α and γ parameters). The model systematically improved the detection accuracy of multi-scale defects in X-ray weld images (mAP improvement of 5.2%-7.8%) by employing loss and defect-aware data augmentation strategies. It achieved an inference speed of 89 FPS while compressing the number of parameters by 12%, significantly enhancing its ability to detect small targets and low-contrast defects and its generalization performance under complex working conditions.

[0201] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0202] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0203] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0204] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0205] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0206] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0207] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.

Claims

1. A defect detection method based on X-ray weld images, characterized in that, include: S1, Acquire X-ray weld images and perform defect adaptation preprocessing; S2, Based on a multi-backbone shared network, shared shallow features are extracted from the preprocessed image, and heterogeneous features of different scales and different semantic levels are extracted based on the shared shallow features; S3 uses a hybrid attention fusion mechanism to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency. S4, based on feature pyramids and a three-scale detection head, identifies the category and location prediction results of defects based on the fused and enhanced multi-scale features; Step S2 includes: S201, based on the shared stem end with a dual-path parallel initial convolutional structure, extracts shared shallow features. The first path uses a 3×3 standard convolution to extract local edge details, and the second path uses a 5×5 depth-separable convolution to capture large-scale texture patterns. The two outputs are then concatenated by a 1×1 convolution to generate shared shallow features F0. S202, the shared shallow feature F0 is simultaneously input into three differentiated parallel backbone branches to extract heterogeneous features at different scales and semantic levels, wherein: The first backbone branch focuses on the surface texture details of the weld and the edge features of small targets, outputting a feature map at the first scale; The second backbone branch focuses on capturing the mesoscale weld structure and background context, and outputs a feature map at the second scale. The third backbone branch focuses on extracting large-scale weld contours and global semantic information, and outputs a feature map at the third scale. S203 reuses shallow features of each backbone branch through a cross-branch feature caching mechanism; The shared trunk adopts a dual-path parallel structure, including: The first path uses standard convolution to extract local edge details; The second approach uses depthwise separable convolution to capture large-scale texture patterns. The outputs of the first path and the second path are concatenated to generate the shared shallow feature.

2. The defect detection method for X-ray weld images according to claim 1, characterized in that, In the model training phase, step S1 includes the following defect adaptability preprocessing: S101, Adaptive grayscale normalization of the image, including: based on the grayscale distribution statistics of the weld area, mapping the image grayscale values ​​to a specific range to enhance the contrast between the weld and the background; S102, Perform multi-scale conformal scaling on the image, including: scaling the image to multiple preset sizes while maintaining the original aspect ratio of the weld seam, in order to generate multi-scale training samples; S103, the image is processed using a defect-aware enhancement combination strategy, the strategy including: a) Combine affine transformation with small target copying and pasting to increase the sample diversity of small target defects; b) Combine global brightness contrast perturbation with adaptive histogram equalization based on weld region characteristics to optimize the contrast of the weld region. c) Apply directional Gaussian blur along the X-ray scanning direction to simulate texture interference in a specific direction; d) Image stitching based on the continuity of weld structure.

3. The defect detection method based on X-ray weld images according to claim 1, characterized in that, In step S3, the step of performing cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels through a hybrid attention fusion mechanism includes: Linear projection is performed on heterogeneous features of different scales and semantic levels of the input to obtain basic features; The base features are fed into the local attention path and the global attention path in parallel. The local attention path uses a convolutional operation with a first dilation rate to capture local detail dependencies; The global attention path uses convolutional operations with a second dilation rate greater than the first dilation rate to capture global context dependencies; The outputs of the local attention path and the global attention path are fused with the base features, and after channel compression, local geometric enhancement is performed sequentially through group convolution or RepConv, and finally integrated output is obtained.

4. The defect detection method for X-ray weld images according to claim 1, characterized in that, Step S3, the directional compression convolution operation includes: Perform asymmetric zero-padding in multiple directions on the input feature map; One-dimensional convolution is applied to the features after padding in each direction to obtain multi-path one-dimensional convolution output features; Channel concatenation is performed on the output features of one-dimensional convolutions in multiple directions. Small kernel convolution is used to fuse and downsample the concatenated features.

5. The defect detection method based on X-ray weld images according to claim 1, characterized in that, Step S4 includes: The multi-scale features fused and enhanced in step S3 are input into the feature pyramid network for top-down and bottom-up feature fusion to generate an enhanced multi-scale feature pyramid. The feature pyramid is input into a three-scale detection head to predict the class probability and bounding box location of defects on feature maps of three different resolutions.

6. The defect detection method based on X-ray weld images according to claim 5, characterized in that, The three-scale detector also predicts the distribution values ​​of the bounding boxes, which are used for bounding box regression through distributed focus loss.

7. The defect detection method based on X-ray weld images according to claim 5, characterized in that, Step S4 also includes: The prediction results are post-processed using a non-maximum suppression algorithm to obtain the final defect detection box.

8. A defect detection system for X-ray weld images, characterized in that, include: The acquisition and preprocessing module is used to acquire X-ray weld images and perform defect adaptation preprocessing. The multi-scale feature extraction module is used to extract shared shallow features from the preprocessed image based on a multi-backbone shared network, and to extract heterogeneous features of different scales and different semantic levels based on the shared shallow features. feature The fusion and enhancement module is used to perform cross-branch semantic alignment and weighted fusion of heterogeneous features at different scales and semantic levels through a hybrid attention fusion mechanism, and introduces directional compression convolution operation to enhance the effective receptive field and optimize parameter efficiency. The result prediction module is used to identify the category and location of defects based on the feature pyramid and the three-scale detection head, according to the fused and enhanced multi-scale features. This method is used to extract shared shallow features from preprocessed images based on a multi-backbone shared network. The extraction of heterogeneous features at different scales and semantic levels based on these shared shallow features includes: Based on the shared stem of the dual-path parallel initial convolutional structure, shared shallow features are extracted. The first path uses a 3×3 standard convolution to extract local edge details, and the second path uses a 5×5 depth-separable convolution to capture large-scale texture patterns. The two outputs are then concatenated by a 1×1 convolution to generate the shared shallow feature F0. The shared shallow feature F0 is simultaneously input into three differentiated parallel backbone branches to extract heterogeneous features at different scales and semantic levels, wherein: The first backbone branch focuses on the surface texture details of the weld and the edge features of small targets, outputting a feature map at the first scale; The second backbone branch focuses on capturing the mesoscale weld structure and background context, and outputs a feature map at the second scale. The third backbone branch focuses on extracting large-scale weld contours and global semantic information, and outputs a feature map at the third scale. The shallow features of each backbone branch are reused through a cross-branch feature caching mechanism; The shared trunk adopts a dual-path parallel structure, including: The first path uses standard convolution to extract local edge details; The second approach uses depthwise separable convolution to capture large-scale texture patterns. The outputs of the first path and the second path are concatenated to generate the shared shallow feature.

Citation Information

Patent Citations

  • Industrial product surface defect detection method based on feature coupling

    CN120766047A

  • Commutator inner side image defect detection method based on fusible feature pyramid

    WO2024208100A1