Method, device, equipment, and medium for visual segmentation of defects in welding radiographs

By freezing the image encoder and prompt encoder, optimizing the mask decoder, and using Dice loss and cross-entropy loss functions, the accuracy problem of defect segmentation in welding radiographs is solved, and efficient defect segmentation in welding radiographs is achieved.

CN118397284BActive Publication Date: 2024-10-25WISON (NANTONG) HEAVY INDUSTRY CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410868341.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-10-25
Estimated Expiration
2044-07-01

Smart Images

  • Figure CN118397284B_ABST
    Figure CN118397284B_ABST
Patent Text Reader

Abstract

The present application relates to a method, device and equipment for visual segmentation of defects in welding radiographs, wherein the method comprises: freezing an image encoder and a prompt encoder in a defect visual segmentation model SAM; acquiring a data set of welding radiographs, extracting a true annotation mask in the data set, wherein the true annotation mask is used to indicate a region of interest; inputting the data set into the defect visual segmentation model SAM, generating an intermediate representation by the frozen image encoder and the prompt encoder, and generating a predicted segmentation mask based on the intermediate representation by a mask decoder in the defect visual segmentation model SAM; constructing a loss function of the true annotation mask and the predicted segmentation mask, and adjusting the mask decoder to minimize the loss function to obtain an optimized defect visual segmentation model SAM; and performing defect visual segmentation in welding radiographs based on the optimized defect visual segmentation model SAM.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of welding defect detection, and in particular to a method, device, computer equipment, storage medium and computer program product for visual segmentation of defects in welding radiographs. Background Art

[0002] Weld radiograph segmentation is a fundamental task in weld imaging analysis, which involves identifying and delineating regions of interest (ROIs) such as cracks, porosity, and lack of penetration in X-ray images. Accurate segmentation of weld defects is critical for downstream tasks such as classification of weld defects.

[0003] Traditional weld radiograph segmentation models mainly include segmentation-anything models, the most commonly used of which is SegmentAnything Model (SAM), which has been trained on more than 1 billion masks with hint-based (e.g., bounding boxes, points, text) or fully automatic approaches. The revolutionary capabilities of SAM are mainly based on its revolutionary architecture, which consists of three main components: image encoder, hint encoder, and mask decoder.

[0004] However, in practical applications, the applicability of conventional SAMs in welding radiograph segmentation is still limited due to the significant differences between natural images and welding radiographs. Studies have shown that these models may fail to achieve accurate defect visual segmentation in typical welding radiographs and other challenging scenarios. Therefore, there is an urgent need for a solution to accurately achieve defect segmentation in welding radiographs. Summary of the invention

[0005] Based on this, it is necessary to provide an accurate method, device, computer equipment, storage medium and computer program product for visual segmentation of defects in welding radiographs in response to the above technical problems.

[0006] In a first aspect, the present application provides a method for visually segmenting defects in welding radiographs. The method comprises:

[0007] The image encoder and cue encoder in the frozen defect visual segmentation model SAM;

[0008] Acquire a data set of welding radiographs, and extract a true annotation mask from the data set, wherein the true annotation mask is used to indicate a region of interest;

[0009] The data set is input into the defect visual segmentation model SAM, the frozen image encoder and the hint encoder generate an intermediate representation, and the mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation;

[0010] Compare the true annotation mask with the predicted segmentation mask, and calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask;

[0011] Obtaining a weighted sum of the Dice loss and the cross entropy loss, and constructing a loss function of the true annotation mask and the predicted segmentation mask;

[0012] Calculating a weight gradient of the loss function with respect to the mask decoder;

[0013] The Adam optimizer is used to adjust the weight gradient of the mask decoder to minimize the loss function, thereby obtaining an optimized defect visual segmentation model SAM;

[0014] Visual segmentation of defects in welding radiographs is performed based on the optimized defect visual segmentation model SAM.

[0015] In one embodiment, the data set of obtaining welding radiographs includes:

[0016] Obtain initial weld radiographs;

[0017] Performing intensity cropping, normalization and size adjustment processing on the initial welding radiograph in sequence to obtain a welding radiograph;

[0018] A real annotation mask is added to the welding radiograph to generate a data set of the welding radiograph.

[0019] In one embodiment, adding a real annotation mask to the welding radiograph to generate a data set of welding radiographs includes:

[0020] adding a true annotation mask to the welding radiograph;

[0021] Extracting the bounding box coordinates surrounding the region of interest from the ground-truth annotation mask;

[0022] adding controlled random variation to the bounding box coordinates to obtain enhanced bounding box coordinates;

[0023] generating a bounding box hint based on the enhanced bounding box coordinates;

[0024] The welding radiographs and the bounding box hints are combined to generate a dataset of welding radiographs.

[0025] In one embodiment, obtaining a data set of welding radiographs and extracting a true annotation mask from the data set comprises:

[0026] Acquire a dataset of welding radiographs;

[0027] Dividing the data set into a training set and a test set;

[0028] Eliminate the segmentation targets whose pixels in the training set are smaller than a preset pixel threshold to obtain a filtered training set;

[0029] Extract the true annotation mask in the filtered training set.

[0030] In one embodiment, the step of inputting the data set into the defect visual segmentation model SAM, generating an intermediate representation by the frozen image encoder and the hint encoder, and generating a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM comprises:

[0031] Inputting the data set into the defect visual segmentation model SAM;

[0032] Offline computing the image embedding corresponding to the data set;

[0033] An intermediate representation is generated by the frozen image encoder and the hint encoder based on the image embedding, and a predicted segmentation mask is generated by a mask decoder in a defect visual segmentation model SAM based on the intermediate representation.

[0034] In one embodiment, constructing a loss function of the true annotation mask and the predicted segmentation mask, and adjusting the mask decoder to minimize the loss function to obtain an optimized defect visual segmentation model SAM includes:

[0035] Compare the true annotation mask with the predicted segmentation mask, and calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask;

[0036] Obtaining a weighted sum of the Dice loss and the cross entropy loss, and constructing a loss function of the true annotation mask and the predicted segmentation mask;

[0037] Calculating a weight gradient of the loss function with respect to the mask decoder;

[0038] The Adam optimizer is used to adjust the weight gradient of the mask decoder to minimize the loss function, thereby obtaining an optimized defect visual segmentation model SAM;

[0039] Visual segmentation of defects in welding radiographs is performed based on the optimized defect visual segmentation model SAM.

[0040] In a second aspect, the present application also provides a device for visually segmenting defects in welding radiographs. The device comprises:

[0041] A freezing module, used to freeze the image encoder and hint encoder in the defect visual segmentation model SAM;

[0042] A label extraction module, used to obtain a data set of welding radiographs, and extract a true label mask from the data set, wherein the true label mask is used to indicate an area of ​​interest;

[0043] A prediction module, configured to input the data set into the defect visual segmentation model SAM, generate an intermediate representation by the frozen image encoder and the hint encoder, and generate a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM;

[0044] An optimization training module is used to compare the true annotation mask with the predicted segmentation mask, calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask; obtain the weighted sum of the Dice loss and the cross entropy loss, and construct a loss function of the true annotation mask and the predicted segmentation mask; calculate the weight gradient of the loss function relative to the mask decoder; use the Adam optimizer to adjust the weight gradient of the mask decoder to minimize the loss function, and obtain an optimized defect visual segmentation model SAM;

[0045] The segmentation module is used to perform visual segmentation of defects in welding radiographs based on the optimized defect visual segmentation model SAM.

[0046] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:

[0047] The image encoder and cue encoder in the frozen defect visual segmentation model SAM;

[0048] Acquire a data set of welding radiographs, and extract a true annotation mask from the data set, wherein the true annotation mask is used to indicate a region of interest;

[0049] The data set is input into the defect visual segmentation model SAM, the frozen image encoder and the hint encoder generate an intermediate representation, and the mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation;

[0050] Compare the true annotation mask with the predicted segmentation mask, and calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask;

[0051] Obtaining a weighted sum of the Dice loss and the cross entropy loss, and constructing a loss function of the true annotation mask and the predicted segmentation mask;

[0052] Calculating a weight gradient of the loss function with respect to the mask decoder;

[0053] The Adam optimizer is used to adjust the weight gradient of the mask decoder to minimize the loss function, thereby obtaining an optimized defect visual segmentation model SAM;

[0054] Visual segmentation of defects in welding radiographs is performed based on the optimized defect visual segmentation model SAM.

[0055] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0056] The image encoder and cue encoder in the frozen defect visual segmentation model SAM;

[0057] Acquire a data set of welding radiographs, and extract a true annotation mask from the data set, wherein the true annotation mask is used to indicate a region of interest;

[0058] The data set is input into the defect visual segmentation model SAM, the frozen image encoder and the hint encoder generate an intermediate representation, and the mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation;

[0059] Compare the true annotation mask with the predicted segmentation mask, and calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask;

[0060] Obtaining a weighted sum of the Dice loss and the cross entropy loss, and constructing a loss function of the true annotation mask and the predicted segmentation mask;

[0061] Calculating a weight gradient of the loss function with respect to the mask decoder;

[0062] The Adam optimizer is used to adjust the weight gradient of the mask decoder to minimize the loss function, thereby obtaining an optimized defect visual segmentation model SAM;

[0063] Visual segmentation of defects in welding radiographs is performed based on the optimized defect visual segmentation model SAM.

[0064] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0065] The image encoder and cue encoder in the frozen defect visual segmentation model SAM;

[0066] Acquire a data set of welding radiographs, and extract a true annotation mask from the data set, wherein the true annotation mask is used to indicate a region of interest;

[0067] The data set is input into the defect visual segmentation model SAM, the frozen image encoder and the hint encoder generate an intermediate representation, and the mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation;

[0068] Compare the true annotation mask with the predicted segmentation mask, and calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask;

[0069] Obtaining a weighted sum of the Dice loss and the cross entropy loss, and constructing a loss function of the true annotation mask and the predicted segmentation mask;

[0070] Calculating a weight gradient of the loss function with respect to the mask decoder;

[0071] The Adam optimizer is used to adjust the weight gradient of the mask decoder to minimize the loss function, thereby obtaining an optimized defect visual segmentation model SAM;

[0072] Visual segmentation of defects in welding radiographs is performed based on the optimized defect visual segmentation model SAM.

[0073] The above-mentioned method, device, computer equipment, storage medium and computer program product for visual segmentation of defects in welding radiographs freeze the image encoder and prompt encoder in the defect visual segmentation model SAM; obtain a data set of welding radiographs, extract the real annotation mask in the data set, and the real annotation mask is used to indicate the region of interest; input the data set into the defect visual segmentation model SAM, generate an intermediate representation by the frozen image encoder and prompt encoder, and generate a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM; construct a loss function of the real annotation mask and the predicted segmentation mask, and adjust the mask decoder to minimize the loss function to obtain the optimized defect visual segmentation model SAM, and perform defect visual segmentation in welding radiographs based on the optimized defect visual segmentation model SAM. In the whole process, on the one hand, the image encoder and prompt encoder in the defect visual segmentation model SAM are frozen to reduce the computing resources required for model training and maintain the spatial relationship learned in the model; on the other hand, the mask decoder is reasonably adjusted with the goal of minimizing the loss function, and finally the optimized defect visual segmentation model SAM can accurately realize the visual segmentation of defects in welding radiographs. BRIEF DESCRIPTION OF THE DRAWINGS

[0074] Figure 1 A diagram of an application environment of a method for visually segmenting defects in welding radiographs in one embodiment;

[0075] Figure 2 A schematic diagram of a flow chart of a method for visually segmenting defects in welding radiographs in one embodiment;

[0076] Figure 3 This is a schematic diagram of the architecture of the defect visual segmentation model SAM;

[0077] Figure 4 Schematic diagram of the data processing process after the image encoder and the prompt encoder in the frozen defect visual segmentation model SAM;

[0078] Figure 5 is a schematic diagram of a sub-process of S200 in one embodiment;

[0079] Figure 6 is a structural block diagram of a device for visually segmenting defects in welding radiographs in one embodiment;

[0080] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0081] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0082] The defect visual segmentation method in welding radiographs provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The terminal 102 sends a defect visual segmentation model optimization request to the server 104, and the server 104 responds to the request, freezes the image encoder and the prompt encoder in the defect visual segmentation model SAM; obtains a data set of welding radiographs, extracts the real annotation mask in the data set, and the real annotation mask is used to indicate the area of ​​interest; inputs the data set into the defect visual segmentation model SAM, generates an intermediate representation by the frozen image encoder and the prompt encoder, and generates a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM; constructs a loss function of the real annotation mask and the predicted segmentation mask, and adjusts the mask decoder to minimize the loss function to obtain the optimized defect visual segmentation model SAM; performs defect visual segmentation in welding radiographs based on the optimized defect visual segmentation model SAM to obtain a defect visual segmentation result. Further, the server 104 can feed back the defect visual segmentation result to the terminal 102. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster composed of multiple servers. It should be pointed out that the defect visual segmentation method in the welding radiograph of this application can also be directly applied to the terminal, and its specific implementation process is similar to the above, which will not be repeated here.

[0083] In one embodiment, Figure 2 As shown in the figure, a method for visual segmentation of defects in welding radiographs is provided. Figure 1 The server 104 in the example is used as an example to illustrate, and the following steps are included:

[0084] S100: Freezing the image encoder and hint encoder in the defect visual segmentation model SAM.

[0085] The Defect Visual Segmentation Model (SAM) uses a Transformer-based architecture that has been shown to be very effective in image recognition and natural language processing tasks. Specifically, SAM uses a visual transformer-based image encoder to extract image features and a prompt encoder to incorporate user interactions, and then uses a mask decoder to generate segmentation results and confidence scores based on the image embedding, prompt embedding, and output labeling.

[0086] like Figure 3 As shown in FIG4 , the entire defect visual segmentation model SAM includes an image encoder, a hint encoder, and a mask decoder. In this application, in order to make the defect visual segmentation model SAM suitable for weld radiograph segmentation, the image encoder will be frozen to minimize the computational cost. The hint encoder encodes the position information of the bounding box and can be reused, so it can also be frozen. The remaining part that needs to be fine-tuned is the mask decoder, as shown in FIG4 .

[0087] Frozen Image Encoder: Visual Transformers have been pre-trained on large-scale datasets and are good at extracting common visual features. When the image encoder is frozen, it means that the weights of the self-attention layer and other components of the model are not updated during fine-tuning. This approach significantly reduces the required computational resources and shortens training time. However, the knowledge contained in the pre-trained visual transformer, including its ability to capture key visual features, is still utilized during fine-tuning, ensuring that SAM can effectively perform segmentation tasks.

[0088] Frozen Hint Encoder: The hint encoder is an integral part of SAM. It provides the model with spatial context, which is crucial for the segmentation process. By freezing the positional encodings, the learned spatial relationships within the model are maintained. This is particularly beneficial for tasks such as segmenting weld features in an image. The maintained spatial understanding helps the model accurately identify where these features are located in the image, leading to more accurate segmentation results.

[0089] S200: Acquire a data set of welding radiographs, extract a true annotation mask in the data set, and use the true annotation mask to indicate a region of interest.

[0090] The data set of welding radiographs can be a data set obtained after historical experience data collection, aggregation, and processing. The data set can be used as training data for subsequent optimization models. The welding radiographs in the data set are pre-annotated with a true annotation mask, which is used to indicate the region of interest. Specifically, the initial welding radiographs can be annotated with a true annotation mask based on expert experience.

[0091] S300: Input the data set into the defect visual segmentation model SAM, generate an intermediate representation by the frozen image encoder and the hint encoder, and generate a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM.

[0092] The data set obtained in S200 is input into the defect visual segmentation model SAM to optimize the defect visual segmentation model SAM. Specifically, the frozen image encoder and the hint encoder first generate an intermediate representation, and then the mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation.

[0093] Specifically, the intermediate representation is the combination of the output of the image encoder and the hint encoder. It contains the features of the input image as well as additional information from the hint. This intermediate representation is the basis for the mask decoder to make predictions. The mask decoder receives the intermediate representation as input and generates a predicted segmentation mask of the same size as the input image. The predicted segmentation mask is a binary image (or other multi-class image) where each pixel is labeled as belonging to the defect area or the background area. In this way, the model is able to accurately locate and segment defects in the image.

[0094] In the subsequent processing, the loss function of the real annotation mask and the predicted segmentation mask is constructed, and the mask decoder is adjusted to minimize the loss function to obtain the optimized defect visual segmentation model SAM. The real annotation mask is pre-annotated in the data set; S300 generates a predicted segmentation mask by the mask decoder, compares the difference between the real annotation mask and the predicted segmentation mask, constructs the loss function, and then continuously adjusts the mask decoder through iterative training to minimize the loss function, that is, the latest predicted segmentation mask is as close as possible to the real annotation mask, and obtains the optimized defect visual segmentation model SAM. It can be understood that the optimized defect visual segmentation model SAM can achieve accurate defect visual segmentation in welding radiographs.

[0095] S400: Compare the true annotation mask with the predicted segmentation mask, and calculate the Dice loss and cross entropy loss between the true annotation mask and the predicted segmentation mask.

[0096] Dice Coefficient Loss: Often used to evaluate the similarity of two samples, especially in image segmentation tasks. The Dice coefficient calculates the ratio of the overlapping area between the predicted segmentation mask and the true annotation mask to the total area of ​​the two. Dice loss is 1 minus the Dice coefficient, which is used to optimize the model during training. Cross-Entropy Loss: Measures the difference between the predicted probability distribution and the true probability distribution. In image segmentation, it is often used for multi-classification problems, especially when the target categories are unbalanced. Here, the pre-annotated true annotation mask and the predicted segmentation mask predicted by the mask decoder are compared, and the Dice loss and cross-entropy loss between the two are calculated.

[0097] S500: Obtain the weighted sum of the Dice loss and the cross entropy loss, and construct the loss function of the true annotation mask and the predicted segmentation mask.

[0098] The Dice loss and the cross entropy loss are weighted and summed to obtain a comprehensive loss function. The choice of this weight is usually determined according to the needs of the task and the characteristics of the data. For example, if the target category is severely unbalanced, a larger weight may be assigned to the cross entropy loss. Here, the loss calculation of the loss function is specifically selected for the weld defect visual segmentation task. It uses the Dice loss and the cross entropy loss to weight and determine the loss function, achieving a high accuracy effect that cannot be achieved by other methods in traditional technology. Further, the Dice loss focuses on the overlap between the predicted mask and the true mask, which is particularly important for unbalanced categories (for example, when the object of interest occupies only a small part of the image); the cross entropy loss helps to refine the classification of each pixel and ensure that the model can accurately distinguish different categories (for example, weld material and background); by combining these two loss functions, the model can make full use of the advantages of both, and finally the optimized model can support accurate visual segmentation of defects in welding radiographs.

[0099] S600: Calculate the weight gradient of the loss function with respect to the mask decoder.

[0100] The backpropagation algorithm is used to calculate the gradient of the loss function relative to the model parameters. Here, the gradient of the loss function relative to the mask decoder weights needs to be calculated first.

[0101] S700: The Adam optimizer is used to adjust the weight gradient of the mask decoder to minimize the loss function and obtain the optimized defect visual segmentation model SAM.

[0102] Adam (Adaptive Moment Estimation) is an adaptive learning rate optimization algorithm that dynamically adjusts the learning rate of each parameter by calculating the first-order moment estimate and the second-order moment estimate of the gradient. Using the Adam optimizer, the weights of the mask decoder can be updated according to these gradient information to minimize the loss function. After multiple iterations of training (i.e., multiple forward propagations, loss calculations, backpropagation, and weight updates), the model will gradually learn how to accurately segment the defect area from the input image, and finally obtain the optimized defect visual segmentation model SAM.

[0103] S800: Visual segmentation of defects in welding radiographs based on the optimized defect visual segmentation model SAM.

[0104] As an advanced image segmentation model, the SAM model provides an effective solution for the automatic identification and segmentation of defects in welding radiographs. Here, the defect visual segmentation of welding radiographs is performed by the optimized defect visual segmentation model SAM obtained by the above processing, which can achieve accurate defect visual segmentation.

[0105] The above-mentioned defect visual segmentation method in welding radiographs freezes the image encoder and the prompt encoder in the defect visual segmentation model SAM; obtains a data set of welding radiographs, extracts the real annotation mask in the data set, and the real annotation mask is used to indicate the region of interest; inputs the data set into the defect visual segmentation model SAM, generates an intermediate representation by the frozen image encoder and the prompt encoder, and generates a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM; constructs a loss function of the real annotation mask and the predicted segmentation mask, and adjusts the mask decoder to minimize the loss function, obtains the optimized defect visual segmentation model SAM, and performs defect visual segmentation in welding radiographs based on the optimized defect visual segmentation model SAM. In the whole process, on the one hand, the image encoder and the prompt encoder in the defect visual segmentation model SAM are frozen to reduce the computing resources required for model training and maintain the spatial relationship learned in the model; on the other hand, the mask decoder is reasonably adjusted with the goal of minimizing the loss function, and finally the optimized defect visual segmentation model SAM can accurately realize the defect visual segmentation in welding radiographs.

[0106] In one embodiment, acquiring a dataset of welding radiographs includes:

[0107] Acquire an initial welding radiograph; perform intensity cropping, normalization and size adjustment on the initial welding radiograph in sequence to obtain a welding radiograph; add a real annotation mask to the welding radiograph to generate a data set of the welding radiograph.

[0108] The initial welding radiograph refers to the welding radiograph obtained by direct collection. After obtaining the initial welding radiograph, the initial welding radiograph is preprocessed so as to be used as a data set for training and optimizing the defect visual segmentation model SAM. Specifically, the preprocessing here mainly includes intensity clipping, normalization and size adjustment processing. The following will introduce these three processings respectively.

[0109] Intensity Clipping: The intensity clipping step is necessary because welding radiographs can have a wide dynamic range, with some areas being very bright and others being very dark. Clipping the intensity to a narrow range (0.95th to 99.5th percentile) helps standardize the input data and prevents the model from being overwhelmed by extreme values ​​that could distort the learning process. Normalization: The clipped intensity values ​​are normalized to a preset pixel range (e.g., [0, 255]), ensuring that all pixel values ​​are on a scale that is compatible with most image processing libraries and frameworks. This normalization step is critical to maintaining numerical stability during training. Resizing: To ensure consistency of model input, images are standardized and resized to a uniform size (e.g., 256*256*3). This practice is critical for the mask decoder to effectively learn segmentations of images of uniform size. In addition, maintaining a consistent size simplifies the application of data augmentation strategies, thereby enhancing the generalization ability of the model. For SAM, the original input image size is generally 1024 * 1024 * 3; by reducing it to a certain size (e.g., 256 * 256 * 3), the computational efficiency and cost are significantly improved.

[0110] In one embodiment, adding a true annotation mask to a welding radiograph to generate a dataset of welding radiographs includes:

[0111] Adding a true annotation mask to the welding radiograph; extracting the bounding box coordinates surrounding the region of interest from the true annotation mask; adding controlled random changes to the bounding box coordinates to obtain enhanced bounding box coordinates; generating bounding box hints based on the enhanced bounding box coordinates; combining the welding radiographs and the bounding box hints to generate a dataset of welding radiographs.

[0112] In the dataset of welding radiographs, each welding radiograph has a corresponding ground-truth annotation mask indicating the area of ​​interest, such as the welding area. This mask is usually a binary image, where the pixels of interest (e.g., the welding part) are labeled as 1 and the background pixels are labeled as 0. Therefore, in the process of generating the dataset, the ground-truth annotation mask is first added to the welding radiograph; then the bounding box is extracted; then random perturbations are performed; and finally the data is combined to obtain the dataset of welding radiographs. The following will introduce each of the above processing stages.

[0113] Bounding box extraction: From the true annotation mask, extract the bounding box coordinates that enclose the region of interest. This bounding box is a rectangular frame that fits the non-zero pixels of the mask tightly, which can be defined by the minimum and maximum x and y coordinates of the non-zero pixels of the mask. Random perturbation: In order to enhance the generalization ability of the model, controlled random changes are added to the bounding box coordinates during training. This change range is carried out within a certain pixel range. Generally, the pixel range is small (for example, from 0 to 20 pixels), which slightly changes the position or size of the bounding box, simulates data enhancement and promotes robustness to small position changes. It also prevents over-reliance on the precise pixel details of the true annotation mask. Bounding box hint: The final bounding box, with random perturbations, is then used as a hint for SAM. The bounding box is encoded by encoding the points at its specific location (such as the points in the upper left corner and the lower right corner).

[0114] like Figure 5 As shown, in one embodiment, S200 includes:

[0115] S220: Acquire a data set of welding radiographs;

[0116] S240: Divide the data set into a training set and a test set;

[0117] S260: Eliminate the segmentation targets whose pixels in the training set are smaller than a preset pixel threshold to obtain a filtered training set;

[0118] S280: Extract the true annotation mask in the filtered training set.

[0119] The acquired welding radiographs are divided into a data set, specifically, the data set is randomly divided into a training set and a test set, where the training set can be much larger than the test set, for example, the training set can account for 80% and the test set can account for 20%. The division into training and test sets helps to evaluate the performance of the model on unseen data and ensure that the model does not overfit the training data. It should be noted that the distribution of different types of welding radiographs in the two groups should be maintained during the division. In addition, further data screening is required for the training set to exclude small segmentation targets. Specifically, the data corresponding to the segmentation targets with smaller pixels can be excluded, where the segmentation targets with smaller pixels refer to the segmentation targets with pixels less than the preset pixel threshold, for example, the segmentation targets with less than 100 pixels can be excluded, so that the learning of the model can be focused on more important features. Furthermore, small targets may be noise and have low relevance in practical applications, and excluding them can lead to a more efficient and accurate model.

[0120] In one embodiment, a data set is input into a defect visual segmentation model SAM, an intermediate representation is generated by a frozen image encoder and a hint encoder, and a mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation, including:

[0121] The dataset is input into the defect visual segmentation model SAM; the image embedding corresponding to the dataset is calculated offline; the frozen image encoder and the hint encoder generate an intermediate representation based on the image embedding, and the mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation.

[0122] Image embedding is a vector representation of image data that captures key information in the image for subsequent processing by the model. Here, image embeddings are calculated offline, meaning that this process does not need to be done in real time and can be done before model training or in the preprocessing stage of model inference. Specifically, calculating image embeddings offline is a preprocessing step. By calculating these image embeddings in advance, time can be saved during training because the model does not need to recalculate them in each training iteration. These embeddings serve as a rich representation of the image content and are subsequently used by the mask decoder to learn the segmentation task.

[0123] In general, the fine-tuning process involves updating the weights of the mask encoder to minimize the loss function on the training data. The entire optimization process consists of the following stages:

[0124] Forward propagation: During training, the model receives weld radiographs and their corresponding ground-truth annotated masks. The image encoder and hint encoder process the images and generate intermediate representations. The mask decoder then uses these representations to generate predicted segmentation masks.

[0125] Loss Calculation: The predicted mask is compared to the ground-truth mask. The loss is calculated between the two mask encodings. For image segmentation, the weighted sum of Dice loss and cross entropy loss has proven to be a powerful function. Dice loss focuses on the overlap between the predicted mask and the ground-truth mask, which is particularly important for imbalanced classes (e.g., the object of interest occupies a small portion of the image). Cross entropy loss helps refine the classification of each pixel, ensuring that the model can accurately distinguish between different classes (e.g., welding material and background). By combining these two loss functions, the model benefits from the strengths of both.

[0126] Backpropagation: Compute the gradients of the loss function with respect to the mask decoder weights. These gradients indicate how the weights should be adjusted to minimize the loss.

[0127] Optimization: We use the Adam optimizer, a stochastic gradient descent variant that adapts the learning rate of each parameter, to update the weights of the mask encoder. The optimizer helps to efficiently search the parameter space to find the weights that minimize the loss function. The initial learning rate for the fine-tuning process is set to 1e -5 .

[0128] Iteration: This process is repeated many times (3-10 epochs) on the training data, gradually improving the performance of the model.

[0129] By fine-tuning to minimize the loss function, the mask encoder learns to generate more accurate segmentation masks for welding radiographs. The resulting model is able to generalize better to unseen welding radiographs and produce more reliable segmentation results.

[0130] In general, in the above embodiments, the defect visual segmentation method in welding radiographs of the present application has the following significant effects.

[0131] 1. WeldSAM was developed by fine-tuning SAM on a selected welding radiography dataset with defect annotation masks, which addresses these limitations and allows the model to learn specific features and patterns associated with welding defects. This targeted training process enhances the model's generalization and performance across various types of welding and imaging conditions, resulting in improved segmentation accuracy, better defect identification, and efficiency of the analysis process.

[0132] 2. WeldSAM’s targeted training is not only computationally efficient because it builds on existing knowledge of SAM’s pre-trained weights, but it also enables the model to quickly adapt to the specific task at hand, requiring less data than training the model from scratch. This efficiency reduces computational costs and training time, making the process more resource-efficient.

[0133] 3. The ability to regularly update the model with new annotation data facilitates the continuous improvement of WeldSAM, ensuring it stays in sync with the latest advances in welding methods. This ongoing refinement process is critical to maintaining the performance and relevance of the model in the face of changing industry standards and technologies.

[0134] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0135] Based on the same inventive concept, the embodiment of the present application also provides a device for visual segmentation of defects in welding radiographs for implementing the above-mentioned method for visual segmentation of defects in welding radiographs. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more embodiments of the device for visual segmentation of defects in welding radiographs provided below can refer to the limitations of the method for visual segmentation of defects in welding radiographs above, and will not be repeated here.

[0136] In one embodiment, Figure 6 As shown, a device for visual segmentation of defects in welding radiographs is provided, comprising:

[0137] A freezing module 200, used for freezing an image encoder and a hint encoder in a defect visual segmentation model SAM;

[0138] Annotation extraction module 400, used to obtain a data set of welding radiographs, extract a true annotation mask in the data set, and the true annotation mask is used to indicate a region of interest;

[0139] A prediction module 600 is used to input the data set into the defect visual segmentation model SAM, generate an intermediate representation by the frozen image encoder and the hint encoder, and generate a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM;

[0140] The optimization training module 800 is used to compare the real annotation mask with the predicted segmentation mask, calculate the Dice loss and the cross entropy loss between the real annotation mask and the predicted segmentation mask; obtain the weighted sum of the Dice loss and the cross entropy loss, and construct the loss function of the real annotation mask and the predicted segmentation mask; calculate the weight gradient of the loss function relative to the mask decoder; use the Adam optimizer to adjust the weight gradient of the mask decoder to minimize the loss function, and obtain the optimized defect visual segmentation model SAM;

[0141] The segmentation module 900 is used to perform visual segmentation of defects in welding radiographs based on the optimized defect visual segmentation model SAM.

[0142] In one embodiment, the annotation extraction module 400 is also used to obtain an initial welding radiograph; perform intensity cropping, normalization and size adjustment on the initial welding radiograph in sequence to obtain a welding radiograph; add a real annotation mask to the welding radiograph to generate a data set of the welding radiograph.

[0143] In one embodiment, the annotation extraction module 400 is also used to add a real annotation mask to the welding radiograph; extract the bounding box coordinates surrounding the area of ​​interest from the real annotation mask; add controlled random changes to the bounding box coordinates to obtain enhanced bounding box coordinates; generate a bounding box prompt based on the enhanced bounding box coordinates; and combine the welding radiograph and the bounding box prompt to generate a data set of the welding radiograph.

[0144] In one embodiment, the annotation extraction module 400 is also used to obtain a data set of welding radiographs; divide the data set into a training set and a test set; eliminate segmentation targets in the training set whose pixels are less than a preset pixel threshold to obtain a filtered training set; and extract the true annotation mask from the filtered training set.

[0145] In one embodiment, the prediction module 600 is also used to input the data set into the defect visual segmentation model SAM; offline calculate the image embedding corresponding to the data set; generate an intermediate representation based on the image embedding by the frozen image encoder and the hint encoder, and generate a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM.

[0146] Each module in the above-mentioned device for visually segmenting defects in welding radiographs can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules.

[0147] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store preset data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for visual segmentation of defects in welding radiographs is implemented.

[0148] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0149] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the above-mentioned method for visual segmentation of defects in welding radiographs when executing the computer program.

[0150] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned method for visual segmentation of defects in welding radiographs is implemented.

[0151] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the above-mentioned method for visual segmentation of defects in welding radiographs.

[0152] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0153] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0154] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for visual segmentation of defects in welding radiographs, characterized in that: The method comprises: The image encoder and cue encoder in the frozen defect visual segmentation model SAM; Acquire a data set of welding radiographs, and extract a true annotation mask from the data set, wherein the true annotation mask is used to indicate a region of interest; The data set is input into the defect visual segmentation model SAM, the frozen image encoder and the hint encoder generate an intermediate representation, and the mask decoder in the defect visual segmentation model SAM generates a predicted segmentation mask based on the intermediate representation; Compare the true annotation mask with the predicted segmentation mask, and calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask; Obtaining a weighted sum of the Dice loss and the cross entropy loss, and constructing a loss function of the true annotation mask and the predicted segmentation mask; Calculating a weight gradient of the loss function with respect to the mask decoder; The Adam optimizer is used to adjust the weight gradient of the mask decoder to minimize the loss function, thereby obtaining an optimized defect visual segmentation model SAM; Visual segmentation of defects in welding radiographs is performed based on the optimized defect visual segmentation model SAM.

2. The method according to claim 1, characterized in that The data set for obtaining welding radiographs includes: Obtain initial weld radiographs; Performing intensity cropping, normalization and size adjustment processing on the initial welding radiograph in sequence to obtain a welding radiograph; A real annotation mask is added to the welding radiograph to generate a data set of the welding radiograph.

3. The method according to claim 2, characterized in that The step of adding a real annotation mask to the welding radiograph to generate a data set of welding radiographs includes: adding a true annotation mask to the welding radiograph; Extracting the bounding box coordinates surrounding the region of interest from the ground-truth annotation mask; adding controlled random variation to the bounding box coordinates to obtain enhanced bounding box coordinates; generating a bounding box hint based on the enhanced bounding box coordinates; The welding radiographs and the bounding box hints are combined to generate a dataset of welding radiographs.

4. The method according to claim 1, characterized in that: The step of obtaining a data set of welding radiographs and extracting a true annotation mask from the data set comprises: Acquire a dataset of welding radiographs; Dividing the data set into a training set and a test set; Eliminate the segmentation targets whose pixels in the training set are smaller than a preset pixel threshold to obtain a filtered training set; Extract the true annotation mask in the filtered training set.

5. The method according to claim 1, characterized in that The step of inputting the data set into the defect vision segmentation model SAM, generating an intermediate representation by the frozen image encoder and the hint encoder, and generating a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect vision segmentation model SAM comprises: Inputting the data set into the defect visual segmentation model SAM; Offline computing the image embedding corresponding to the data set; An intermediate representation is generated by the frozen image encoder and the hint encoder based on the image embedding, and a predicted segmentation mask is generated by a mask decoder in a defect visual segmentation model SAM based on the intermediate representation.

6. A device for visually segmenting defects in welding radiographs, characterized in that: The device comprises: A freezing module, used to freeze the image encoder and hint encoder in the defect visual segmentation model SAM; A label extraction module, used to obtain a data set of welding radiographs, and extract a true label mask from the data set, wherein the true label mask is used to indicate an area of ​​interest; A prediction module, configured to input the data set into the defect visual segmentation model SAM, generate an intermediate representation by the frozen image encoder and the hint encoder, and generate a predicted segmentation mask based on the intermediate representation by the mask decoder in the defect visual segmentation model SAM; An optimization training module is used to compare the true annotation mask with the predicted segmentation mask, calculate the Dice loss and the cross entropy loss between the true annotation mask and the predicted segmentation mask; obtain the weighted sum of the Dice loss and the cross entropy loss, and construct a loss function of the true annotation mask and the predicted segmentation mask; calculate the weight gradient of the loss function relative to the mask decoder; use the Adam optimizer to adjust the weight gradient of the mask decoder to minimize the loss function, and obtain an optimized defect visual segmentation model SAM; The segmentation module is used to perform visual segmentation of defects in welding radiographs based on the optimized defect visual segmentation model SAM.

7. The device according to claim 6, characterized in that The annotation extraction module is also used to obtain initial welding radiographs; the initial welding radiographs are subjected to intensity cropping, normalization and size adjustment in sequence to obtain welding radiographs; and real annotation masks are added to the welding radiographs to generate a data set of welding radiographs.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.