A weld TOFD image defect intelligent identification method based on a diffusion model and contrast learning
By employing diffusion modeling and contrastive learning methods, a TOFD image recognition model for welds is constructed. This model is trained and sliced using normal weld image samples, thus solving the problem of relying on a large number of positive samples in existing technologies and improving the accuracy and efficiency of weld defect recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHONGQING JIAOTONG UNIV
- Filing Date
- 2026-03-23
- Publication Date
- 2026-06-19
AI Technical Summary
Existing deep learning-based methods for defect recognition in weld TOFD images rely on a large number of positive samples and have low efficiency in identifying background areas in weld TOFD images, resulting in insufficient recognition accuracy and efficiency.
A diffusion model and contrastive learning approach were used to construct a TOFD image ROI recognition model and an ROI slicing classification model for welds. The model was trained using normal weld image samples. The recognition accuracy was improved by slicing techniques and noise processing. The defect area was determined by combining L1 distance calculation.
It improves the accuracy and efficiency of weld defect identification using only normal samples, and can adapt to the identification of any unknown defects.
Smart Images

Figure CN122243965A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of nondestructive testing technology, and more specifically to an intelligent method for identifying defects in TOFD images of welds based on diffusion models and contrastive learning. Background Technology
[0002] Currently, non-destructive testing (NDT) technology is widely used for weld defect detection. Among them, Time-of-Flight Ultrasonic Diffraction (TOFD) is increasingly used for weld flaw detection due to its high detection accuracy and the fact that it does not harm operators during the acquisition of weld damage images. Existing mature methods generally involve operators first using TOFD equipment to image the weld, and then experienced experts evaluating the resulting weld images to determine the presence or absence of defects. Although some methods use artificial intelligence algorithms to automatically evaluate the resulting weld images, existing AI-based automatic identification methods for weld defect TOFD images heavily rely on training datasets. For some fields, obtaining a large number of defective weld TOFD images is extremely difficult. Therefore, existing deep learning methods based on large datasets are not suitable, and the accuracy of existing meta-learning and transfer learning methods that rely on a small number of samples, as well as anomaly detection algorithms, still needs improvement, failing to meet the application objectives.
[0003] To achieve intelligent and accurate identification of weld defects using perfectly normal TOFD image samples, a method different from conventional deep learning needs to be studied. Conventional deep learning models directly learn the feature patterns of positive samples to identify the test image; however, learning accurate feature patterns from positive samples requires a large number of positive samples as training data. While industrial anomaly detection algorithms can indirectly determine the presence of a target by learning the feature patterns of negative samples, their accuracy for TOFD images of welds needs further improvement. Furthermore, since only a portion of a TOFD image of a weld is the weld area, with the rest being useless background regions, these background areas not only create potential false positives but also reduce identification efficiency.
[0004] Therefore, how to intelligently and accurately identify TOFD images of weld defects using only normal samples is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] In view of this, the present invention provides an intelligent identification method for weld defects based on diffusion model and contrastive learning TOFD image, so as to achieve intelligent, efficient and accurate identification of weld defects.
[0006] To achieve the above objectives, the present invention adopts the following technical solution: A method for intelligent defect recognition of weld seam TOFD images based on diffusion model and contrastive learning includes: S1. Construct a dataset of potential defect regions (ROIs) for normal welds, as well as a slice dataset of the ROIs; S2. Construct a TOFD image ROI recognition model for welds and train the TOFD image ROI recognition model using a dataset of ROI images of potential defect areas in normal welds. S3. Construct a ROI slice classification model for weld seam images and train the ROI slice classification model using the ROI slice dataset. S4. The trained weld seam TOFD image ROI recognition model and weld seam image ROI slice classification model are fused together to obtain a weld seam defect intelligent and accurate recognition model; the weld seam defect intelligent and accurate recognition model is used to identify the TOFD image of the weld seam to be inspected to obtain the location of the defect in the original TOFD image.
[0007] Optionally, S1 specifically includes: Using a TOFD device, positive samples containing images of completely normal welds were collected. All collected image samples were labeled with Regions of Interest (ROIs) and a dataset of ROI images of potential defect areas of normal welds was created. At the same time, the ROIs were sliced and the slices were made into a dataset of ROI slices.
[0008] Optionally, the weld seam TOFD image ROI recognition model adopts the YOLO11 target detection network model, and uses the parameters trained on the ImageNet dataset as the pre-training parameters of the weld seam TOFD image ROI recognition model.
[0009] Optionally, the weld image ROI slicing classification model adopts a classification network based on diffusion model and contrastive learning, combined with slicing method, to finally form the weld image ROI slicing classification model.
[0010] Optionally, the specific structure of the classification network based on diffusion model and contrastive learning is as follows: The input layer consists of TOFD image ROI slice image block samples of weld seams. In addition, the input layer also includes a temporal embedding module composed of noise addition step size. This is followed by a convolutional layer; The convolutional layer is followed by the first DownBlock module, the second DownBlock module, and the third DownBlock module in sequence. A temporal embedding module is added to the input of each DownBlock module. The third DownBlock module is connected to the first MidBlock module and the second MidBlock module in sequence. A time embedding module is also added to the input of each MidBlock module. The second MidBlock module is connected sequentially to the first UpBlock module, the second UpBlock module, and the third UpBlock module. Each UpBlock module also has a time embedding module added to its input. Finally, the output of the third UpBlock module is fed into a deconvolution layer, resulting in a realistic slice image of the same size as the input.
[0011] Optionally, training the ROI slice classification model for weld images using the ROI slice dataset specifically includes: The ROI slice samples are fed in batches into the weld image ROI slice classification model. The weld image ROI slice classification model classifies the input slice samples. Perform T rounds of noise addition to obtain , … Based on the characteristics of the TOFD weld ROI slice image, the noise added each time is Gaussian noise. For any step t in the training process, The result at step t-1 Add a mean of 0 and a variance of 0 to the base. Gaussian noise get, The expression is as follows:
[0012] In the formula, This is obtained by linear interpolation from 0.0002 to 0.02, with T interpolation steps; where the added Gaussian noise... ; For the input slice image After t steps of noise addition, the resulting noisy image The expression is as follows:
[0013] In the formula,
[0014] The noisy image is then input into the weld seam image ROI slicing classification model, which outputs the predicted noise image. And calculate the output. and input The mean square error is then used to calculate the loss function of the ROI slice classification model for weld images.
[0015] Optionally, the expression for the loss function loss of the weld image ROI slice classification model is as follows: Optionally, testing of the weld image ROI slice classification model is also included, specifically: First, standard Gaussian noise is input into the trained weld image ROI slice classification model, which outputs a realistic slice generation image. The realistic slice generation image is used as a standard template for comparative learning and is compared with the generated image corresponding to the slice to be tested. Then, the slice to be tested is input into the trained weld image ROI slice classification model. Each slice generates a corresponding generated image. All these generated images are compared with the standard template one by one to calculate the L1 distance. If the calculated distance is greater than the set threshold, the slice to be tested corresponding to that distance is automatically judged to be a slice with defects; otherwise, it is a normal slice.
[0016] Optionally, the formula for calculating the L1 distance is:
[0017] In the formula, Generate images to produce realistic slices; For the test slice i The generated graph; n is the total number of slices to be tested.
[0018] As can be seen from the above technical solutions, compared with the prior art, the present invention discloses an intelligent identification method for weld seam TOFD images based on diffusion model and contrastive learning. Based on diffusion model theory and contrastive learning method, it proposes a new automatic identification method for weld seam defects to address the problems existing in the application of existing deep learning-based methods. This method not only avoids the disadvantage of relying on a large number of positive samples during deep learning model training, but also can adapt to any unknown defects, greatly improving the identification accuracy and efficiency of weld seam defects. Attached Figure Description
[0019] 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 embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0020] Figure 1 A schematic diagram of the method provided by the present invention; Figure 2 This is a sample example of dataset 1 provided by the present invention.
[0021] Figure 3This is a sample example of dataset 2 provided by the present invention.
[0022] Figure 4 A schematic diagram of the defect potential region identification model provided by the present invention.
[0023] Figure 5 This is a schematic diagram of the ROI slice provided by the present invention.
[0024] Figure 6 This is a schematic diagram of the network structure of the slice diffusion model provided by the present invention.
[0025] Figure 7 A schematic diagram of the slice diffusion model provided by this invention.
[0026] Figure 8 The flowchart shows the testing process for the slice classification model provided by this invention.
[0027] Figure 9 This is a general schematic diagram provided for the present invention. Detailed Implementation
[0028] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. 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.
[0029] This invention discloses an intelligent defect recognition method for TOFD images of welds based on a diffusion model and contrastive learning, such as... Figure 1 As shown, it includes: S1. Construct a dataset of potential defect regions (ROIs) for normal welds, as well as a slice dataset of the ROIs; S2. Construct a TOFD image ROI recognition model for welds and train the TOFD image ROI recognition model using a dataset of ROI images of potential defect areas in normal welds. S3. Construct a ROI slice classification model for weld seam images and train the ROI slice classification model using the ROI slice dataset. S4. The trained weld seam TOFD image ROI recognition model and weld seam image ROI slice classification model are fused together to obtain a weld seam defect intelligent and accurate recognition model; the weld seam defect intelligent and accurate recognition model is used to identify the TOFD image of the weld seam to be inspected to obtain the location of the defect in the original TOFD image.
[0030] The detailed principle is explained below: 1. Construction of two sample datasets The training sample data for the entire recognition model consists of two parts: the construction of the potential region of interest (ROI) dataset for weld defects (Dataset 1) and the construction of the slice dataset of the ROI (Dataset 2). Dataset 1 comprises weld images acquired using a TOFD device; these weld images are completely free of defects. Example samples are shown below. Figure 2 As shown; Dataset 2 was created based on the ROI samples in Dataset 1. The ROIs were sliced to obtain sliced patch samples of the weld seam image ROI. Example samples are shown below. Figure 3 As shown.
[0031] 2. Construction and Training of the ROI Recognition Model for Weld Seam Images
[0032] Since the potential area of weld defects is generally large, the existing YOLO11 target detection model is directly used as the weld defect potential area identification model of this invention, such as... Figure 4 As shown, the YOLO11 object detection model not only guarantees accuracy but also has excellent real-time performance, making it easy to deploy on embedded devices.
[0033] 3. Construction and Training of ROI Slicing Classification Model for Weld Seam Images
[0034] To address the issue of poor model generalization performance due to insufficient positive samples, this invention proposes a weld slice classification model that combines a slicing technique with a diffusion model and contrastive learning. The Region of Interest (ROI) detected by the weld defect potential region identification model is used as input to the weld defect identification model. The input weld image ROI is then sliced, and the trained model is used to classify each slice for defects. After comprehensively evaluating the classification results of each slice, the system ultimately determines whether the potential weld region contains a defect and displays the defect location.
[0035] 3.1 Slicing of the ROI in the weld image
[0036] Slicing the potential defect area of the weld can effectively improve the accuracy of identifying small defects, such as... Figure 5 As shown, the potential area of weld defects is divided into image blocks of fixed size. Preliminary experiments show that a 64×64 pixel size slice yields better results. Compared to not slicing, slicing effectively captures the detailed features of small defects.
[0037] 3.2 Weld seam image ROI slice classification model
[0038] To address the issue that conventional weld defect identification models overly rely on the number of positive samples and have insufficient accuracy, this invention proposes a method for automatic weld defect identification that relies solely on TOFD slice samples of normal, defect-free welds. Since normal, defect-free samples are readily available, the limitation of insufficient positive samples can be completely circumvented. The weld image ROI slice classification model is based on a diffusion model and contrastive learning theory.
[0039] like Figure 6 As shown, the main part of the diffusion model consists of a UNet network, and the specific network structure is as follows: The input layer consists of TOFD images of weld seams, ROI slices, and image blocks with 1 channel and a size of 64. 64. At the same time, the input network also includes temporal embedding modules consisting of noisy step sizes, which are composed of SiLU activation functions and fully connected layers. The next layer is a convolutional layer with 1 input channel and 32 output channels. The convolutional layer is followed by a first DownBlock module, a second DownBlock module, and a third DownBlock module. The feature map size output by the first DownBlock module is (64, 64, 32, 32), the feature map size output by the second DownBlock module is (64, 128, 16, 16), and the feature map size output by the third DownBlock module is (64, 256, 8, 8). A temporal embedding module is added to the input of each DownBlock module. The third DownBlock module is connected to the first MidBlock module and the second MidBlock module in sequence. The feature map size output by the first MidBlock module is (64,256,8,8), and the feature map size output by the second MidBlock module is (64,128,8,8). A temporal embedding module is also added to the input of each MidBlock module. The second MidBlock module is connected sequentially to the first UpBlock module, the second UpBlock module, and the third UpBlock module. The feature map size output by the first UpBlock module is (64, 64, 16, 16), the feature map size output by the second UpBlock module is (64, 32, 32, 32), and the feature map size output by the third UpBlock module is (64, 16, 64, 64). A temporal embedding module is also added to the input of each UpBlock module. Finally, the output of the third UpBlock module is fed into a deconvolution layer, resulting in a realistic slice image of the same size as the input.
[0040] 3.3 Training of the ROI Slice Classification Model for Weld Seam Images
[0041] The previously constructed dataset 2 was used to effectively train the weld seam image ROI slice classification model, such as... Figure 7 As shown, the training process is the process of adding noise to ROI slices, as detailed below.
[0042] The ROI slice samples are fed into the diffusion model in batches, and the model processes the input slice samples. Perform T rounds of noise addition to obtain , … Based on the characteristics of TOFD weld ROI slice images, this invention sets T=1000, and the noise added each time is Gaussian noise. For any t-th step in the training process, The result at step t-1 Add a mean of 0 and a variance of 0 to the base. Gaussian noise get, The expression is as follows:
[0043] In the above formula This is obtained through linear interpolation from 0.0002 to 0.02, with T interpolation steps. The added Gaussian noise... .
[0044] For the input slice image After t steps of noise addition, the resulting noisy image The expression is as follows:
[0045] In the above formula,
[0046] The noisy map is then input into the UNet network, which outputs the predicted noisy map. And calculate the output. and input The mean squared error, specifically, the expression for the loss function of this network is as follows: .
[0047] 3.4 Testing of the classification model for weld seam image ROI slices
[0048] The weld seam image ROI slicing classification model was tested using the previously constructed dataset 2. The specific testing process is as follows: Figure 8 As shown.
[0049] First, standard Gaussian noise is input into the pre-trained model, which outputs realistic slice generation images. These realistic slice generation images serve as the standard template for contrastive learning, used to compare with the generated images corresponding to the slice to be tested. Then, the slice to be tested is input into the pre-trained diffusion model, generating a corresponding image for each slice. The L1 distance between each of these generated images and the standard template is calculated. If the calculated distance is greater than a set threshold (determined based on the actual trained diffusion model), the slice to be tested corresponding to that distance is automatically identified as a defective slice; otherwise, it is considered a normal slice.
[0050] The formula for calculating L1 distance is:
[0051] In the formula, Generate images to produce realistic slices; For the test slice i The generated graph; n is the total number of slices to be tested.
[0052] 4. Construction and testing of the overall model
[0053] like Figure 9 As shown, the TOFD image of the weld to be inspected is used as the input to the weld TOFD image ROI recognition model, and its output ROI is used as the input to the weld image ROI slicing classification model. The output ROI includes the position of the ROI in the original image. Furthermore, the weld image ROI slicing classification model first slices the input ROI to obtain slices of a fixed size (64). The model uses 64 pixels as a pixel and records the position of each slice within the Region of Interest (ROI). Then, it inputs all slice image patches into a trained diffusion model to generate corresponding slice images for each slice. Simultaneously, standard Gaussian noise is input into the trained diffusion model to generate standard slice images. L1 distances are calculated between each of these generated images and the standard slice image. Slices with calculated distances greater than a set threshold are automatically identified as defective slices; otherwise, they are considered normal slices. For defective slices, their position within the ROI and the ROI's position in the original input TOFD image are used to automatically calculate the defective slice's position in the original TOFD image, thus completing defect relocation. Finally, the position of the defect in the original TOFD image is output. This completes the automatic defect identification of the entire weld seam TOFD image.
[0054] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.
[0055] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for intelligent defect recognition of weld seam TOFD images based on diffusion model and contrastive learning, characterized in that, include: S1. Construct a dataset of potential defect regions (ROIs) for normal welds, as well as a slice dataset of the ROIs; S2. Construct a TOFD image ROI recognition model for welds and train the TOFD image ROI recognition model using a dataset of ROI images of potential defect areas in normal welds. S3. Construct a ROI slice classification model for weld seam images and train the ROI slice classification model using the ROI slice dataset. S4. The trained weld seam TOFD image ROI recognition model and weld seam image ROI slice classification model are fused together to obtain a weld seam defect intelligent and accurate recognition model; the weld seam defect intelligent and accurate recognition model is used to identify the TOFD image of the weld seam to be inspected to obtain the location of the defect in the original TOFD image.
2. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 1, characterized in that, S1 specifically includes: Using a TOFD device, positive samples containing images of completely normal welds were collected. All collected image samples were labeled with Regions of Interest (ROIs) and a dataset of ROI images of potential defect areas of normal welds was created. At the same time, the ROIs were sliced and the slices were made into a dataset of ROI slices.
3. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 1, characterized in that, The weld seam TOFD image ROI recognition model adopts the YOLO11 target detection network model, and uses the parameters trained on the ImageNet dataset as the pre-training parameters of the weld seam TOFD image ROI recognition model.
4. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 1, characterized in that, The weld image ROI slicing classification model adopts a classification network based on diffusion model and contrastive learning, combined with slicing method, to finally form the weld image ROI slicing classification model.
5. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 4, characterized in that, The specific structure of the classification network based on diffusion model and contrastive learning is as follows: The input layer consists of TOFD image ROI slice image block samples of weld seams. In addition, the input layer also includes a temporal embedding module composed of noise addition step size. This is followed by a convolutional layer; The convolutional layer is followed by the first DownBlock module, the second DownBlock module, and the third DownBlock module in sequence. A temporal embedding module is added to the input of each DownBlock module. The third DownBlock module is connected to the first MidBlock module and the second MidBlock module in sequence. A time embedding module is also added to the input of each MidBlock module. The second MidBlock module is connected sequentially to the first UpBlock module, the second UpBlock module, and the third UpBlock module. Each UpBlock module also has a time embedding module added to its input. Finally, the output of the third UpBlock module is fed into a deconvolution layer, resulting in a realistic slice image of the same size as the input.
6. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 1, characterized in that, The training of the ROI slice classification model for weld seam images using the ROI slice dataset specifically includes: The ROI slice samples are fed in batches into the weld image ROI slice classification model. The weld image ROI slice classification model classifies the input slice samples. Perform T rounds of noise addition to obtain , … Based on the characteristics of the TOFD weld ROI slice image, the noise added each time is Gaussian noise. For any step t in the training process, The result at step t-1 Add a mean of 0 and a variance of 0 to the base. Gaussian noise get, The expression is as follows: In the formula, This is obtained by linear interpolation from 0.0002 to 0.02, with T interpolation steps; where the added Gaussian noise... ; For the input slice image After t steps of noise addition, the resulting noisy image The expression is as follows: In the formula, The noisy image is then input into the weld seam image ROI slicing classification model, which outputs the predicted noise image. And calculate the output. and input The mean square error is then used to calculate the loss function of the ROI slice classification model for weld images.
7. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 6, characterized in that, The loss function of the weld seam image ROI slice classification model is expressed as follows: 。 8. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 6, characterized in that, It also includes testing of the weld seam image ROI slicing classification model, specifically: First, standard Gaussian noise is input into the trained weld image ROI slice classification model, which outputs a realistic slice generation image. The realistic slice generation image is used as a standard template for comparative learning and is compared with the generated image corresponding to the slice to be tested. Then, the slice to be tested is input into the trained weld image ROI slice classification model. Each slice generates a corresponding generated image. All these generated images are compared with the standard template one by one to calculate the L1 distance. If the calculated distance is greater than the set threshold, the slice to be tested corresponding to that distance is automatically judged to be a slice with defects; otherwise, it is a normal slice.
9. The intelligent defect recognition method for weld seam TOFD images based on diffusion model and contrastive learning according to claim 8, characterized in that, The formula for calculating the L1 distance is: In the formula, Generate images to produce realistic slices; For the test slice i The generated graph; n is the total number of slices to be tested.