Prototype contrast learning-based industrial ct image defect segmentation method and device
By using a prototype-based contrastive learning method, prototype feature vectors and attention feature maps of industrial CT images are extracted, which solves the problems of insufficient accuracy in detecting minute defects and limited accuracy in boundary segmentation in industrial CT images, and achieves defect segmentation results with high accuracy, low cost and flexible category expansion.
Patent Information
- Application Number
- CN202611357687.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-03
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies for defect segmentation in industrial CT images suffer from problems such as insufficient accuracy in detecting minute defects, weak model generalization ability, high cost of category expansion, and limited accuracy in defect boundary segmentation. In particular, they are difficult to meet the accuracy requirements of industrial inspection under small sample conditions.
A prototype-based contrastive learning approach is adopted. By acquiring support and training sets, prototype feature vectors for each category are extracted. An attention feature map is formed using a contrastive network and a segmentation network. Combined with edge extraction and fine segmentation sub-networks, the accurate localization and boundary correction of the defect segmentation prediction map are achieved.
It significantly improves defect detection accuracy under low-sample conditions, reduces annotation costs, enhances the ability to detect minute defects, enables flexible category expansion and high-precision boundary segmentation, adapts to the inspection of workpieces made of multiple materials, and meets the needs of industrial inspection.
Smart Images

Figure CN123181471A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method and computing device for defect segmentation of industrial CT images based on prototype contrastive learning. Background Technology
[0002] Industrial CT defect segmentation is a core step in achieving quantitative defect detection and grade assessment. Accurate defect contour extraction provides crucial information for subsequent dimensional measurement and mechanical performance evaluation. With the development of deep learning technology, segmentation methods based on fully supervised convolutional neural networks have been widely applied in CT image analysis. However, several technical bottlenecks remain insurmountable in real-world industrial scenarios, resulting in insufficient accuracy in detecting minute defects. In industrial CT, defects such as microcracks and micropores typically occupy only a fraction of the image size, exhibiting low grayscale contrast and blurred boundaries. Conventional segmentation models like U-Net and DeepLab easily lose detail information about small targets during downsampling, leading to high false negative rates and significant deviations between the segmented contour and the actual defect. Summary of the Invention
[0003] To address the existing technical problems, this invention provides a method and computing device for defect segmentation of industrial CT images based on prototype contrastive learning, which can improve the accuracy of defect detection.
[0004] A first aspect provides a method for defect segmentation of industrial CT images based on prototype contrastive learning, comprising: acquiring a support set, the support set including multiple support sample images, each support sample image being labeled with a category mask of at least one category, the category including at least one of the following: defect category and background category; performing feature extraction based on the support set to determine the prototype feature vector of each category; acquiring a training set, the training set including multiple training sample images, each training sample image being labeled with a category label and a category mask label; forming the input of the feature extraction network in the defect segmentation model based on the training sample images to determine the initial feature map of the training sample images; the defect segmentation model further including a contrastive network and a segmentation network; comparing the initial feature map and the prototype feature vector of each category through the contrastive network to determine an attention feature map; forming the input of the segmentation network based on the attention feature map to determine a defect segmentation prediction map; determining the current loss value based on the defect segmentation prediction map and the defect mask label; and backpropagating based on the current loss value to continue training the defect segmentation model.
[0005] In a second aspect, a computing device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the industrial CT image defect segmentation method based on prototype contrastive learning as provided in the first aspect of this application.
[0006] This application first performs feature extraction based on the support set to determine the prototype feature vectors of each category. Based on the training sample images, it forms the input to the feature extraction network in the defect segmentation model, determines the initial feature map of the training sample images, and compares the initial feature map and the prototype feature vectors of each category through the comparison network to determine the attention feature map. This can enhance the feature response of the defect area, suppress background noise interference, and achieve accurate defect localization under conditions of few samples. Based on the attention feature map, it forms the input to the segmentation network to determine the defect segmentation prediction map. Based on the defect segmentation prediction map and the defect mask label, it determines the current loss value. Based on the current loss value, it backpropagates and continues to train the defect segmentation model. Since the attention feature map can enhance the feature response of the defect area, the limited computing resources can be automatically focused on sparse but critical defect areas such as microcracks and pores during training. The attention feature map output by the comparison network can provide spatial prior knowledge for model training, making it easier for the model to learn defect knowledge better, so as to improve the defect detection accuracy in the future. Attached Figure Description
[0007] Figure 1 This is an application environment diagram of an industrial CT image defect segmentation method based on prototype contrastive learning in one embodiment; Figure 2 This is a flowchart of an industrial CT image defect segmentation method based on prototype contrastive learning in one embodiment; Figure 3 This is a network structure diagram of a defect segmentation model in one embodiment; Figure 4 This is a schematic diagram of a segmentation network in one embodiment; Figure 5 This is a schematic diagram of an industrial CT image defect segmentation device based on prototype contrastive learning in one embodiment. Figure 6 This is a schematic diagram of a computing device in one embodiment. Detailed Implementation
[0008] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0009] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the specification of this invention is for the purpose of describing particular embodiments only and is not intended to limit the scope of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0010] In the following description, the expression “some embodiments” refers to a subset of all possible embodiments. However, it should be understood that “some embodiments” can be the same subset or different subsets of all possible embodiments and can be combined with each other without conflict.
[0011] See Figure 1 This diagram illustrates the application environment of an industrial CT image defect segmentation method based on prototype contrastive learning in one embodiment. The method is applied in a computing device 10, which acquires a support set and a training set. The support set is used to extract prototype feature vectors for each category. The training set is used to train the defect segmentation model.
[0012] In practical industrial applications, existing technologies still face several insurmountable technical bottlenecks: First, labeled data is scarce and labeling costs are extremely high. Labeling defects in industrial CT requires personnel with professional non-destructive testing knowledge to delineate each pixel, and labeling a single high-precision CT slice can take several hours. Furthermore, the number of samples of minute and rare defects is scarce, making it difficult to build a large-scale labeled dataset and support fully supervised training of segmentation models with a large number of parameters.
[0013] Secondly, the detection accuracy of minute defects is insufficient. In industrial CT, defects such as microcracks and micropores typically account for only a few thousandths of the image size, have low grayscale contrast, and blurred boundaries. Conventional segmentation models such as U-Net and DeepLab are prone to losing detailed information of small targets during downsampling, resulting in a high false negative rate and a large deviation between the segmented contour and the actual defect.
[0014] Third, the model has weak generalization ability and high cost for category expansion. The defect morphology of workpieces with different materials and processes varies significantly. When a model trained for a single workpiece is transferred to a new category of workpieces, the accuracy drops sharply. Adding new defect categories requires collecting a large amount of data and training the model again. The iteration cycle is long and the implementation cost is high, making it unsuitable for the industrial inspection needs of multiple categories and small batches.
[0015] Fourth, the accuracy of defect boundary segmentation is limited. Existing methods focus more on the overall segmentation accuracy and do not adequately constrain the pixels at the defect edges. However, in industrial inspection, the perimeter, area, and contour shape of defects are key indicators for defect level assessment. Blurred boundaries will directly lead to excessive quantitative detection errors.
[0016] Existing small-sample segmentation methods are mostly designed for natural images, and there is a problem of poor adaptability when directly transferred to industrial CT grayscale images: CT images have little single-channel grayscale information, low contrast between defects and background, and strong noise interference. Small-sample algorithms for natural images cannot effectively capture the subtle features of defects and are difficult to meet the accuracy requirements of industrial inspection.
[0017] Existing few-sample segmentation methods are mostly designed for natural images, and their adaptability is poor when directly transferred to industrial CT grayscale images: CT images have limited single-channel grayscale information, low contrast between defects and background, and strong noise interference. Few-sample algorithms for natural images cannot effectively capture the subtle features of defects, making it difficult to meet the accuracy requirements of industrial inspection. Therefore, the industry urgently needs an intelligent segmentation method specifically designed for industrial CT scenarios, adapted to few-sample conditions, with strong perception of minute defects, high boundary segmentation accuracy, and flexible category expansion.
[0018] Please see Figure 2 This is a flowchart illustrating a prototype-based comparative learning-based defect segmentation method for industrial CT images, provided in an embodiment of this application. The prototype-based comparative learning-based defect segmentation method for industrial CT images is applied in a computing device and includes the following steps: S11. Obtain a support set, which includes multiple support sample images. Each support sample image is labeled with a category mask of at least one category, including at least one of the following: defect category and background category.
[0019] In this embodiment, the categories include, but are not limited to, at least one of the following: porosity, cracks, inclusions, and background. Industrial CT slice images containing typical defects such as porosity, cracks, and inclusions, along with corresponding pixel-level labeled masks, are collected to construct a small-sample dataset. The images undergo grayscale normalization, adaptive median denoising, and block cropping preprocessing to eliminate the influence of quantum noise and size differences. Only 5-10 labeled samples are retained for each type of defect to simulate the limited-sample conditions in real-world scenarios. The small-sample dataset is divided into a support set and a training set. The category mask represents the region of the category to which the mask belongs on the support samples. For example, if a support sample has a porosity category and a crack category, then the porosity category corresponds to a porosity mask, and the crack category corresponds to a crack mask. The porosity mask represents the region of that porosity category in the support samples.
[0020] For example, the CT slice dataset of aviation aluminum castings includes three typical defects: porosity, microcracks, and inclusions. Eight labeled samples are selected as the support set for each type of defect, and 100 samples are selected as the training set for training. The original resolution of the images is 512×512, and the gray level is 16 bits.
[0021] The collected samples are preprocessed by normalizing the grayscale of the original 16-bit CT images to the [0,1] range and using a 3×3 adaptive median filter to suppress CT quantum noise. The images are cropped into 256×256 pixel sub-blocks, and sub-blocks containing defects are selected to form a dataset. The support set contains 8 images of each of the three types of defects.
[0022] S12. Based on the support set, perform feature extraction to determine the prototype feature vectors for each category.
[0023] In this embodiment, the prototype feature vector of the category is a feature vector used as a reference for comparison with the feature map extracted during training.
[0024] S13. Obtain the training set, which includes multiple training sample images. Each training sample image is labeled with a category label and a category mask label.
[0025] In this embodiment, the category mask label of the training sample image represents the region where the corresponding category is located. The category label and category mask label are used for subsequent supervised training.
[0026] S14. Based on the training sample images, form the input of the feature extraction network in the defect segmentation model, and determine the initial feature map of the training sample images.
[0027] In this embodiment, the defect segmentation model further includes a contrast network and a segmentation network. The initial feature map is the feature map output by the feature extraction network. For example... Figure 3 As shown, Figure 3 The diagram shows the network structure of a defect segmentation model in one embodiment. The contrast network and feature extraction network are cascaded, as are the segmentation network and contrast network. The contrast network compares the initial feature map with the prototype feature vectors of each category, reducing parameter learning. The result of comparing the initial feature map with the prototype feature vectors of each category is equivalent to a classification weight. The higher the similarity between the pixel feature and the category's prototype feature vector, the higher the weight is assigned. This is a metric-based classification, better suited for small sample sizes, and requires no additional training of classifier parameters. The feature extraction network can also be the same as the multi-scale feature extraction network used to extract features from supporting sample images. The initial feature map can include multi-scale feature maps.
[0028] S15. By comparing the initial feature map and the prototype feature vectors of each category through the comparison network, the attention feature map is determined.
[0029] In this embodiment, the attention feature map is an enhanced feature representation obtained by spatial domain weighted fusion after comparing the initial feature map with the prototype feature vectors of each category. Comparing the prototype feature vectors with the initial feature map facilitates the subsequent discovery of smaller defective features.
[0030] S16. Based on the attention feature map, form the input of the segmentation network and determine the defect segmentation prediction map.
[0031] In this embodiment, the defect segmentation prediction map represents the defect segmentation data corresponding to the training sample images in the current iteration.
[0032] S17. Based on the defect segmentation prediction map and defect mask label, determine the current loss value, and backpropagate based on the current loss value to continue training the defect segmentation model.
[0033] In this embodiment, when the current loss value is greater than the preset loss value, training samples are continuously obtained from the training set, backpropagation is performed, and model parameters are updated. The defect segmentation model is then trained until the iteration termination condition is met. The iteration condition includes, but is not limited to, the current loss value being less than the preset loss value, the number of iterations being greater than the preset number of iterations, etc.
[0034] In the above embodiment, feature extraction is first performed based on the support set to determine the prototype feature vectors of each category. Based on the training sample images, the input of the feature extraction network in the defect segmentation model is formed, and the initial feature map of the training sample images is determined. By comparing the initial feature map and the prototype feature vectors of each category through the comparison network, the attention feature map is determined, which can enhance the feature response of the defect area and suppress background noise interference, so as to achieve accurate defect localization under the condition of few samples. Based on the attention feature map, the input of the segmentation network is formed to determine the defect segmentation prediction map. Based on the defect segmentation prediction map and the defect mask label, the current loss value is determined. Based on the current loss value, backpropagation is performed to continue training the defect segmentation model. Since the attention feature map can enhance the feature response of the defect area, the limited computing resources can be automatically focused on sparse but critical defect areas such as microcracks and pores during training. The attention feature map output by the comparison network can provide spatial prior knowledge for model training, so that the model can better learn defect knowledge, thereby improving the defect detection accuracy in the future.
[0035] In some embodiments, feature extraction is performed based on the support set to determine the prototype feature vectors for each category, including: The support sample images are used as input to the multi-scale feature extraction network, which includes multiple downsampling layers at different scales, and the multi-scale reference feature maps output by each downsampling layer are determined. Based on the category mask of the supporting sample image, extract the reference feature map of each category from the multi-scale reference feature map; For any category, global average pooling and weighted aggregation are performed on the reference feature maps of the corresponding category in all supporting sample images to obtain the prototype feature vector of the category.
[0036] In this embodiment, the multi-scale feature extraction network may include multiple cascaded downsampling residual units. Reference feature maps at different scales are extracted progressively through these cascaded downsampling residual units. Each downsampling residual unit consists of two 3×3 parallel convolutional layers, avoiding gradient vanishing and preserving detailed information. The multi-scale feature extraction network outputs multi-scale reference feature maps at different resolutions. Shallow high-resolution features capture defect edge textures, while deep low-resolution features extract semantic information about defects, comprehensively enhancing the feature representation capability of minute defects. The multi-scale reference feature maps include feature maps at different scales.
[0037] For example, a multi-scale feature extraction network can include four cascaded downsampling residual units. The first downsampling residual unit takes a 256×256 image as input, outputs a 128×128×32 feature map after passing through two residual blocks, and captures edge texture details; the second downsampling residual unit downsamples and outputs a 64×64×64 feature map; The third downsampling residual unit outputs a 32×32×128 feature map; the fourth downsampling residual unit outputs a 16×16×256 feature map, extracting deep semantic information. These four levels of feature maps together constitute a multi-scale feature output, preserving defect information at different scales.
[0038] For the same category, global average pooling and weighted aggregation are performed on the reference feature maps of the same category in all supporting sample images to obtain the prototype feature vector of the same category. For example, based on the labeled pore mask, pore reference feature maps are extracted from various multi-scale reference feature maps. Global average pooling and weighted aggregation are performed on the pore reference feature maps of all samples of the same category to generate the prototype feature vector of that pore category. The prototype feature vectors of all defect categories and background categories are stored by category index to construct a dynamically updatable prototype feature library, which serves as the discrimination criterion for few-shot segmentation.
[0039] In the above embodiments, feature maps of the same category in multiple support sample images of each category are aggregated into a single standard prototype vector of that category to form a prototype feature library. This prototype feature library not only provides a clear and robust discrimination reference for subsequent comparison and alignment, effectively suppressing the bias caused by noise or abnormal grayscale fluctuations in a single sample, but also decouples category knowledge from the network weights and stores it externally. This allows the model to expand its capabilities instantly without retraining the feature extraction network when adding new defect types, simply by supplementing the new class prototype. Thus, while ensuring high-precision defect discrimination under conditions of few samples, it also gives the model the flexibility to continuously evolve for dynamic industrial production lines and extremely low maintenance and iteration costs.
[0040] In some embodiments, the attention feature map is determined by comparing the initial feature map and the prototype feature vectors of each category through a comparison network, including: By comparing the initial feature map and the prototype feature vectors of each category through the comparison network, the category probability map is determined. The category probability map is multiplied along the channel dimension with multiple feature maps of different scales in the initial feature map to obtain the preliminary attention map corresponding to each scale. The preliminary attention maps corresponding to each scale are then fused to obtain the attention feature map.
[0041] Optionally, by comparing the initial feature map and the prototype feature vectors of each category through a comparison network, the category probability map is determined, including: The cosine similarity is calculated by comparing the feature vectors corresponding to each pixel in the initial feature map with the prototype feature vectors of each category to obtain a similarity heatmap. The similarity heatmap includes the similarity between each pixel and each category. The similarity heatmap is normalized along the channel dimension to obtain the category probability map.
[0042] In this embodiment, the initial feature map includes multiple feature maps of different scales. The cosine similarity between the feature vector of each pixel in the smallest scale feature map of the initial feature map and the prototype feature vector of each category is calculated using a comparison network. The specific formula for calculating the cosine similarity is as follows: ,in In the initial feature map at pixel coordinates The feature vector at that location, For the prototype feature library The prototype feature vector of the class, where · represents the vector dot product and ||·|| represents the L2 norm; calculate all features for each pixel position. Similarity values for each category are used to generate a similarity heatmap. The similarity heatmap is then normalized along the channel dimension using the Softmax function to obtain a category probability map. This category probability map represents the initial defect segmentation confidence and is a graph formed by the C-dimensional probability vectors of each pixel.
[0043] The normalization formula is: Each component Represents pixels Belongs to the The probability value of a defect or background is in the range of [0,1] and the sum of its components is 1.
[0044] Multiply the category probability map by the initial feature map along the channel dimension, i.e., multiply the probability vector of each pixel. Its eigenvectors Element-wise weighting generates a prototype-guided attention feature map, which enhances the feature response of the defect region and suppresses background noise interference, achieving accurate defect localization under limited sample conditions. The attention feature map facilitates the subsequent determination of more precise defect category boundaries and refinement of those boundaries; it can also be used for subsequent loss function calculations.
[0045] The initial feature map includes multiple feature maps at different scales, for example, four feature maps at different scales. The cosine similarity between each pixel vector in the initial feature map and the prototype feature vectors of the four classes is calculated to generate a four-channel similarity heatmap; this is then normalized using the Softmax function to obtain the class probability map. First, the class probability map is multiplied channel-by-channel with the fourth-scale feature map to apply prototype attention to the deep semantic features (both feature maps have a spatial resolution of 16×16). The category probability map is then bilinearly upsampled to 32×32 resolution and multiplied channel-by-channel with the feature map at the third scale. Prototype attention is then applied to the mid-level texture features. This multi-scale attention strategy allows the probability map to simultaneously act on deep semantic features and mid-level texture features, taking into account both global semantic discrimination of defects and local edge detail representation. The reason for using both the third-scale and fourth-scale feature maps is that the category probability map is calculated from the fourth-scale feature map and the prototype feature vectors of each category, naturally adapting to the resolution of the fourth scale; while the third-scale feature map has a higher resolution (32×32), retaining richer defect edge texture information. Multiplying the upsampled probability map with it can enhance the attention response of the edge region. A prototype attention feature map is generated to highlight the features of the defect region and suppress background noise.
[0046] In some embodiments, the segmentation network includes an edge extraction subnetwork, a fusion subnetwork, and a fine segmentation subnetwork; Based on the attention feature map, the input to the segmentation network is formed, and the defect segmentation prediction map is determined, including: The training sample images are used as input to the edge extraction sub-network to perform edge feature extraction and obtain the edge feature map. Upsample the attention feature map to obtain the upsampled feature map; The upsampled feature map and the edge feature map are used as inputs to the fusion sub-network to obtain the fused feature map; The fused feature map is used as input to the fine segmentation subnetwork to perform segmentation and determine the defect segmentation prediction map.
[0047] In this embodiment, as Figure 4As shown, the segmentation network includes an edge extraction subnetwork and a fusion subnetwork. The edge extraction subnetwork uses a multi-directional Sobel operator to extract horizontal, vertical, and diagonal gradient features from the training sample images to generate edge feature maps. The fusion subnetwork concatenates the upsampled feature map with the edge feature map and then fuses them. The upsampled feature map and the edge feature map have the same resolution. The fusion subnetwork includes two convolutional layers. The fused feature map represents the classification probability of each pixel for each category. This classification probability is the basis for the classification decision of pixel-level segmentation. The higher the value, the higher the confidence that the pixel belongs to the corresponding category. For pixels in the defect edge region, the fusion subnetwork uses the Sobel edge gradient response value to apply a weighted correction to the classification probability of pixels in that region, improving the sensitivity of edge pixel judgment, correcting the segmentation boundary pixel by pixel, and finally outputting a refined defect segmentation mask, i.e., a defect segmentation prediction map, through a fine segmentation subnetwork.
[0048] For example, the attention feature map is upsampled to the original image resolution, and the edge features are extracted from the training sample image using the four-direction Sobel operator to generate an edge feature map. The attention feature map and the edge feature map are concatenated and then fused through two layers of 3×3 convolution. The classification probability of the edge pixels is weighted and corrected, and finally a refined segmentation mask of 256×256 is output.
[0049] In some embodiments, determining the current loss value based on the defect segmentation prediction map and the defect mask label includes: Based on the feature vectors corresponding to each defect pixel in the initial feature map and the prototype feature vectors of each category, the prototype contrast loss is determined. Based on the defect segmentation prediction map and defect mask label, the boundary weighted cross-entropy loss is determined; The prototype contrast loss and the boundary-weighted cross-entropy loss are weighted to determine the current loss value.
[0050] Optionally, based on the feature vectors corresponding to each pixel in the initial feature map and the prototype feature vectors of each category, the prototype contrastive loss is determined, including: For any defective pixel, calculate the first loss value between the feature vector corresponding to the defective pixel and the prototype feature vector of the category to which the defective pixel belongs, and calculate the second loss value between the feature vector corresponding to the defective pixel and the prototype feature vector of the category to which the defective pixel does not belong; based on the first loss value and the second loss value, calculate the contrast loss of the current pixel corresponding to the defective pixel. The prototype contrast loss is obtained by summing the contrast loss of the current pixel corresponding to each defective pixel.
[0051] In this embodiment, the first loss value represents the loss for belonging to the same category as the pixel, and the second loss represents the loss for belonging to a different category. The formula for calculating the prototype contrast loss is as follows: in The number of defective pixels sampled in the training sample image; For the initial feature map, the first The feature vector of each defective pixel To and Prototype feature vectors of the same category To and Prototype feature vectors of different categories; The preset interval hyperparameter is configured to 0.5. This loss optimizes the intra-class aggregation and inter-class discriminative power of feature embedding space by moving similar feature vectors closer to the prototype and distancing dissimilar feature vectors from it. This represents the contrast loss for the current pixel. The first loss value, This is the second loss value.
[0052] By bringing similar features closer together and pushing away dissimilar features, the network is forced to learn the essential semantic discriminativeness of defects. In small-sample scenarios, the prototype contrast loss only needs to calculate the relative distance for a small number of sampled defective pixels, without relying on dense annotations across the entire image, greatly alleviating the training degradation caused by insufficient annotations. The prototype contrast loss is a triplet constraint loss function based on metric learning. Its core lies in constructing the relative distance constraint relationship between the feature vectors of the training sample images in the embedding space and the prototype feature vectors of each category. Through the prototype contrast loss, the feature extraction network is driven to cluster similar defective features toward the corresponding prototype anchor points in the embedding space and dissipate dissimilar defective features, thereby optimizing the intra-class compactness and inter-class separability of the feature space, providing a feature embedding foundation with high semantic purity for subsequent small-sample classification based on similarity metrics. This loss function operates in a non-parametric manner, without introducing additional trainable classification parameters, fundamentally avoiding the technical defect of traditional parametric classifiers being prone to overfitting in small-sample scenarios.
[0053] Optionally, based on the defect segmentation prediction map and defect mask labels, the boundary-weighted cross-entropy loss is determined to include: The boundary-weighted cross-entropy loss is determined using a formula based on the defect segmentation prediction map and defect mask labels. The formula for determining the boundary-weighted cross-entropy loss is as follows: in The total number of pixels in the training sample images. The total number of categories, For the pixels in the category mask label The true label; Pixels in the defect segmentation prediction image Belongs to the The predicted probability of a class; For boundary weights, ,in For pixels in the edge feature map The corresponding value, This is the preset boundary magnification factor.
[0054] Boundary-weighted cross-entropy loss is a supervised loss function that superimposes spatially sensitive weights on the standard pixel-level cross-entropy loss. It addresses the severe imbalance between positive and negative samples caused by the absolute dominance of background pixels in industrial defect segmentation, as well as the segmentation boundary drift caused by CT image blurring in defect edge regions. Differential supervision is achieved by multiplying the loss contribution of each pixel by a preset boundary weight factor. The weight factor is dynamically assigned based on the spatial distance between the pixel location and the true defect boundary. Pixels within a preset neighborhood of the defect boundary are given a higher penalty coefficient than those in the background region, resulting in a stronger gradient response to the classification error of edge pixels during backpropagation. This boundary-weighted cross-entropy loss guides the model to prioritize the limited feature representation capabilities on the defect edge regions, which are crucial for segmentation quality, effectively improving the boundary fitting accuracy between the predicted mask and the true annotation. Simultaneously, edge-enhanced supervision indirectly constrains the network's classification consistency within the defect's internal regions, serving as a key supervisory signal to ensure the geometric integrity of the segmentation from a pixel-space perspective.
[0055] Prototype contrastive loss, starting from the global structure of the embedding space, forces the aggregation of similar defect features and the separation of dissimilar ones, providing a semantic basis for category classification in segmentation. Boundary-weighted cross-entropy loss, starting from the spatial location in the pixel space, applies enhanced supervision to edge regions, providing fine-tuning constraints on geometric boundaries for segmentation. These two loss functions do not overlap in their optimization objectives and complement each other at the functional level, together forming a complete supervision link from identifying defect categories to determining defect boundaries. This fundamentally overcomes the technical limitation that a single loss function cannot simultaneously guarantee inter-class discriminability and boundary integrity.
[0056] During backpropagation, the gradient flow of the prototype contrastive loss primarily acts on the deep structure of the feature extraction network, driving the spatial orientation adjustment of the feature vectors; while the gradient flow of the boundary-weighted cross-entropy loss primarily acts on the shallow convolutional layers and the boundary-aware refinement module, driving the sensitivity calibration of the edge detection response. These two gradients act on different layers and feature spaces of the network, with their gradient directions and magnitudes independent of each other. They are indirectly coupled by sharing the weights of the underlying feature extraction network. The edge error feedback from the boundary loss guides the contrastive loss, making edge region features more discriminative. Furthermore, the high-confidence semantic prior optimized by the contrastive loss provides the boundary loss with a precise focusing region, forming a virtuous cycle of co-evolutionary mechanisms.
[0057] In some embodiments, the prototype feature library includes prototype feature vectors for each category, and the method further includes: Retrieve the newly added category and the corresponding newly supported sample images for that category; Based on the newly added support sample images, feature extraction is performed to determine the prototype feature vector of the new category.
[0058] In existing technologies, in the actual production environment of industrial CT defect detection, the types of defects are often not fully known in advance. With product process iteration, the introduction of new materials, or the upgrading of detection standards, new defect morphologies (such as stress corrosion cracking, slag inclusions, and porosity) will continue to emerge. Traditional fully supervised segmentation models based on deep learning encode the class discrimination ability in the weight matrix of the trainable classification layer (such as a fully connected layer or a 1×1 convolutional layer) at the end of the network, and the number of classes is strongly bound to the network parameter dimension. Therefore, adding a new defect category not only requires redesigning the output dimension of the classification layer based on the labeled samples of the new class, but more seriously, since the feature extraction layer of the network has been solidified on the old class distribution during the original training, without complete retraining with full data merging, the generalization ability on the new class is also significantly insufficient due to the lack of sufficient joint optimization.
[0059] When a new defect category needs to be added, only the prototype feature library needs to be updated. During the inference stage, the comparison network automatically includes the prototype feature vector of the new category into the cosine similarity calculation channel. It can achieve the ability to segment new categories with zero latency without any parameter updates or iterative optimization.
[0060] In one application scenario, on the same aluminum casting dataset, the segmentation performance of the proposed method and the benchmark U-Net model was tested with different numbers of support set samples. The results are as follows: As can be seen from the data, the method provided in this application has a significant performance advantage under small sample conditions. It can achieve the accuracy of a fully supervised U-Net with 50 samples with only 10 samples, which fully verifies the technical advantage in small sample scenarios.
[0061] One or more embodiments of this application have at least the following characteristics: 1. Significantly reduced annotation costs: Only 5-10 labeled samples per class are needed to achieve segmentation accuracy close to that of a fully supervised model, reducing the annotation workload by more than 90% and significantly reducing data acquisition costs and time.
[0062] 2. Significantly improved detection capability for minute defects: Multi-scale feature fusion and prototype attention mechanism enhance the feature representation of small targets. The recall rate of micropores and microcracks below 10μm is 22% higher than that of traditional U-Net, and the false negative rate is significantly reduced.
[0063] 3. Flexible and efficient category expansion: Adding new defect categories does not require full retraining. Only a small number of samples are needed to update the prototype feature library to complete the category expansion. The model iteration cycle is shortened from several weeks to several hours, making it suitable for multi-category small-batch detection scenarios.
[0064] 4. Higher boundary segmentation accuracy: The boundary perception refinement module optimizes edge pixel classification, improves the defect contour intersection-union ratio by 8.5%, and controls the measurement error of quantitative parameters such as perimeter and area within 5%, meeting the requirements of high-precision industrial inspection.
[0065] 5. Strong scene adaptability and robustness: Specifically optimized for industrial CT grayscale images, it has strong resistance to quantum noise and can maintain stable segmentation results even in low-contrast and low signal-to-noise ratio images. It can be widely adapted to the inspection of workpieces made of various materials such as metals, ceramics, and composite materials.
[0066] 6. Lightweight deployment: The network structure is simple, with only 18M parameters, and can be deployed on various hardware platforms such as industrial control computers and embedded devices. The inference speed meets the real-time requirements of online detection.
[0067] In another aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the prototype-based contrastive learning-based industrial CT image defect segmentation method of any embodiment of this application.
[0068] Among them, in the computer program product, the optional implementation form of the program module architecture of the computer program that implements each step of the target recognition method can be an industrial CT image defect segmentation device based on prototype contrastive learning.
[0069] Please see Figure 5This application provides an embodiment of an industrial CT image defect segmentation device based on prototype contrastive learning, comprising: an acquisition module 51, configured to acquire a support set, the support set including multiple support sample images, each of the support sample images being labeled with a category mask of at least one category, the category including at least one of the following: defect category and background category; a feature extraction module 52, configured to perform feature extraction based on the support set to determine the prototype feature vector of each category; the acquisition module 51 is further configured to acquire a training set, the training set including multiple training sample images, each of the training sample images being labeled with a category label and a category mask label; and a segmentation module 53, configured to segment based on... The training sample images form the input to the feature extraction network in the defect segmentation model, determining the initial feature map of the training sample images. The defect segmentation model also includes a contrast network and a segmentation network. The segmentation module 53 is further used to compare the initial feature map and the prototype feature vectors of each category through the contrast network to determine the attention feature map. The segmentation module 53 is further used to form the input of the segmentation network based on the attention feature map to determine the defect segmentation prediction map. The segmentation module 53 is further used to determine the current loss value based on the defect segmentation prediction map and the defect mask label, and to backpropagate based on the current loss value to continue training the defect segmentation model.
[0070] Please see Figure 6 In another aspect of this application, a computing device 10 is also provided, including a memory 3011 and a processor 3012. The memory 3011 stores a computer program, and when the computer program is executed by the processor, the processor 3012 performs the steps of the industrial CT image defect segmentation method based on prototype contrastive learning provided in any of the above embodiments of this application. The computing device 10 can be (e.g., a desktop computer, laptop computer, tablet computer, handheld computer, smart speaker, server, etc.), a mobile phone (e.g., a smartphone, cordless phone, etc.), a wearable device (e.g., a pair of smart glasses or a smartwatch), or a similar device.
[0071] The processor 3012 is the control center, connecting various parts of the computer device via various interfaces and lines. It executes software programs and / or modules stored in the memory 3011, and calls data stored in the memory 3011 to perform various functions and process data. Optionally, the processor 3012 may include one or more processing cores; preferably, the processor 3012 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user page, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 3012.
[0072] The memory 3011 can be used to store software programs and modules. The processor 3012 executes various functional applications and data processing by running the software programs and modules stored in the memory 3011. The memory 3011 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 3011 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 3011 may also include a memory controller to provide the processor 3012 with access to the memory 3011.
[0073] In another aspect, this application also provides a storage medium storing a computer program, which, when executed by a processor, causes the processor to perform the steps of the industrial CT image defect segmentation method based on prototype contrastive learning provided in any of the above embodiments of this application.
[0074] Those skilled in the art will understand that all or part of the processes in the methods provided in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0075] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. The scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A defect segmentation method for industrial CT images based on prototype contrastive learning, characterized in that, include: Obtain a support set, which includes multiple support sample images. Each support sample image is labeled with a category mask of at least one category, which includes at least one of the following categories: defect category and background category. Based on the support set, feature extraction is performed to determine the prototype feature vectors for each category; Obtain a training set, which includes multiple training sample images, each of which is labeled with a category label and a category mask label; Based on the training sample images, the input to the feature extraction network in the defect segmentation model is formed, and the initial feature map of the training sample images is determined. The defect segmentation model also includes a comparison network and a segmentation network; The initial feature map and the prototype feature vectors of each category are compared using the comparison network to determine the attention feature map. Based on the attention feature map, the input to the segmentation network is formed to determine the defect segmentation prediction map; Based on the defect segmentation prediction map and the defect mask label, the current loss value is determined, and the defect segmentation model is trained by backpropagation based on the current loss value.
2. The industrial CT image defect segmentation method based on prototype contrastive learning as described in claim 1, characterized in that, The step of performing feature extraction based on the support set to determine the prototype feature vector for each category includes: The supporting sample image is used as the input to a multi-scale feature extraction network, which includes multiple downsampling layers of different scales, and the multi-scale reference feature map output by each downsampling layer is determined. Based on the category mask of the supporting sample image, extract the reference feature map of each category from each of the multi-scale reference feature maps; For any of the categories, global average pooling and weighted aggregation are performed on the reference feature maps corresponding to the category in all the supporting sample images to obtain the prototype feature vector of the category.
3. The industrial CT image defect segmentation method based on prototype contrastive learning as described in claim 1, characterized in that, The step of comparing the initial feature map and the prototype feature vectors of each category through the comparison network to determine the attention feature map includes: The comparison network is used to compare the initial feature map and the prototype feature vectors of each category to determine the category probability map. The category probability map is multiplied along the channel dimension by multiple feature maps of different scales in the initial feature map to obtain the preliminary attention map corresponding to each scale. The preliminary attention maps corresponding to each scale are then fused to obtain the attention feature map.
4. The industrial CT image defect segmentation method based on prototype contrastive learning as described in claim 3, characterized in that, The step of comparing the initial feature map and the prototype feature vectors of each category through the comparison network to determine the category probability map includes: The cosine similarity calculation is performed between the feature vectors corresponding to each pixel in the initial feature map and the prototype feature vectors of each category to obtain a similarity heatmap, which includes the similarity between each pixel and each category. The similarity heatmap is normalized along the channel dimension to obtain the category probability map.
5. The industrial CT image defect segmentation method based on prototype contrastive learning as described in claim 4, characterized in that, The segmentation network includes an edge extraction subnetwork, a fusion subnetwork, and a fine segmentation subnetwork; The step of forming the input of the segmentation network based on the attention feature map and determining the defect segmentation prediction map includes: The training sample image is used as the input to the edge extraction sub-network to perform edge feature extraction and obtain an edge feature map. The attention feature map is upsampled to obtain an upsampled feature map; The upsampled feature map and the edge feature map are used as inputs to the fusion sub-network to obtain the fusion feature map; The fused feature map is used as input to the fine segmentation sub-network to perform segmentation and determine the defect segmentation prediction map.
6. The industrial CT image defect segmentation method based on prototype contrastive learning as described in claim 5, characterized in that, The step of determining the current loss value based on the defect segmentation prediction map and the defect mask label includes: Based on the feature vectors corresponding to each defect pixel in the initial feature map and the prototype feature vectors of each category, the prototype contrast loss is determined. Based on the defect segmentation prediction map and the defect mask label, the boundary weighted cross-entropy loss is determined. The prototype contrast loss and the boundary-weighted cross-entropy loss are weighted to determine the current loss value.
7. The industrial CT image defect segmentation method based on prototype contrastive learning as described in claim 6, characterized in that, The determination of the prototype contrast loss based on the feature vectors corresponding to each pixel in the initial feature map and the prototype feature vectors of each category includes: For any defective pixel, calculate a first loss value between the feature vector corresponding to the defective pixel and the prototype feature vector of the category to which the defective pixel belongs; calculate a second loss value between the feature vector corresponding to the defective pixel and the prototype feature vector of the category to which the defective pixel does not belong; and calculate the current pixel contrast loss corresponding to the defective pixel based on the first loss value and the second loss value. The prototype contrast loss is obtained by summing the current pixel contrast loss corresponding to each defective pixel.
8. The industrial CT image defect segmentation method based on prototype contrastive learning as described in claim 6, characterized in that, The determination of the boundary-weighted cross-entropy loss based on the defect segmentation prediction map and the defect mask label includes: The boundary-weighted cross-entropy loss is determined using a formula based on the defect segmentation prediction map and the defect mask label. The formula for determining the boundary-weighted cross-entropy loss is as follows: in The total number of pixels in the training sample images. The total number of categories, For the pixels in the category mask label The true label; For the pixels in the defect segmentation prediction image Belongs to the The predicted probability of a class; For boundary weights, ,in For the pixels in the edge feature map The corresponding value, This is the preset boundary magnification factor.
9. The industrial CT image defect segmentation method based on prototype contrastive learning as described in any one of claims 1 to 8, characterized in that, The prototype feature library includes prototype feature vectors for each category, and the method further includes: Obtain the newly added category and the newly added supporting sample images corresponding to the newly added category; Based on the newly added support sample images, feature extraction is performed to determine the prototype feature vector of the newly added category.
10. A computing device, characterized in that, It includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the industrial CT image defect segmentation method based on prototype contrastive learning as described in any one of claims 1 to 9.
