An industrial defect weakly supervised detection and segmentation method based on progressive pseudo-label optimization

By using a progressive pseudo-label optimization method, the problems of weak generalization ability and high annotation cost of fully supervised models in industrial defect detection are solved, achieving high-precision defect segmentation that is applicable to various industrial scenarios.

CN122368030APending Publication Date: 2026-07-10苏州深视信息科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
苏州深视信息科技有限公司
Filing Date
2026-05-14
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

In existing industrial defect detection, fully supervised deep learning models have weak generalization ability for small and new samples, high annotation costs, lack of dynamic adjustment mechanism for pseudo-label generation, insufficient feature aggregation, and difficulty in removing noisy pseudo-labels, resulting in low segmentation accuracy and failing to meet the needs of industrial sites.

Method used

A progressive pseudo-label optimization method is adopted. By synchronously initializing teacher and student models, using progressively decreasing threshold filtering, a two-dimensional memory bank and a Gaussian distribution model, combined with triple rule processing, pure pseudo-labels are generated. Multiple rounds of closed-loop optimization are performed to improve the quality of pseudo-labels and the accuracy of feature modeling.

Benefits of technology

It significantly improves the segmentation accuracy of industrial defects, especially micro defects and defects with blurred edges, reduces the dependence on manually labeled data, and enhances the adaptability and feasibility of the model in industrial settings.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122368030A_ABST
    Figure CN122368030A_ABST
Patent Text Reader

Abstract

This invention relates to the field of industrial visual defect detection, and more particularly to a progressive pseudo-label optimization-based weakly supervised detection and segmentation method for industrial defects. The method includes the following steps: acquiring images of industrial surface defects; training a basic network and simultaneously initializing a teacher model and a student model; supervising the training of the student model; simultaneously inputting the industrial surface defect images into the teacher and student models to obtain initial pseudo-labels and feature maps; extracting feature centers and constructing a memory bank; constructing a contrastive learning loss; constructing a Gaussian distribution model to calculate pixel-level feature assignment probabilities; fusing these probabilities with the initial pseudo-labels to generate an enhanced pseudo-mask; and processing this to obtain a clean pseudo-label; training and updating the student model while simultaneously updating the teacher model; and outputting the optimized student and teacher models after multiple rounds of closed-loop optimization. This invention, through pseudo-label optimization and refined feature modeling, reduces the labeling cost of industrial defect detection and significantly improves detection and segmentation accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial visual defect detection, and more particularly to a progressive pseudo-label optimized weakly supervised detection and segmentation method for industrial defects. Background Technology

[0002] In the field of industrial defect detection, with the rapid increase in demand for intelligent manufacturing, the requirements for the accuracy and automation of defect detection are increasing. Traditional solutions mostly rely on fully supervised deep learning models, which require a large amount of instance labeled data containing complete pixel-level masks and detection boxes for training. Although they can achieve good detection results, in actual production, the labeling of defect images often requires repeated confirmation by professional technicians, which is time-consuming, labor-intensive, and extremely costly. At the same time, due to the diverse defect morphologies and complex backgrounds in industrial sites, fully supervised models have weak generalization ability for small samples and new samples.

[0003] To reduce annotation costs, weakly supervised learning techniques have been widely adopted. Current mainstream approaches include class activation mapping methods assisted by image-level labels, self-training methods that iteratively generate pseudo-labels using teacher-student models, and schemes that combine external memory banks or feature distributions to optimize pseudo-label quality. These approaches attempt to improve segmentation performance through model self-iteration without relying on complete pixel-level annotations, representing an important development direction in the field of industrial defect detection.

[0004] While existing weakly supervised defect segmentation schemes have made some progress, they still have significant shortcomings in practical engineering applications. First, pseudo-label generation often uses fixed confidence thresholds for filtering, lacking a mechanism for dynamic adjustment as training progresses. This easily introduces a large number of noisy pseudo-labels in the early stages of training, causing gradient oscillations in the model. In the later stages, the overly strict thresholds result in insufficient effective training data, making it difficult for the model to converge to its optimal state. Second, feature aggregation and representation capabilities are insufficient. Most schemes fail to clearly distinguish between the core defect and blurred edge regions when extracting defect region features, lacking refined modeling of regional features, leading to low segmentation accuracy for minor and blurred edge defects. Third, existing schemes rely on external memory banks or distribution models that often use single sample centers or limited sample statistics, failing to accurately represent the feature distribution of complex industrial scenarios, resulting in limited effectiveness of distribution-based pseudo-label correction. Finally, the removal of noisy pseudo-labels relies heavily on qualitative rules, lacking quantitative judgment criteria and standards. This makes it difficult to prevent noise contamination of the model at its source, leading to insignificant iterative optimization effects and ultimately failing to meet the actual requirements of industrial sites for defect segmentation accuracy and stability. Summary of the Invention

[0005] To address the technical deficiencies in the background technology, this invention proposes a progressive pseudo-label optimized weakly supervised detection and segmentation method for industrial defects, which solves the aforementioned technical problems and meets practical needs. The specific technical solution is as follows: A progressive pseudo-label optimized method for weakly supervised detection and segmentation of industrial defects includes the following steps: Industrial surface defect images are collected and divided into a small number of labeled subsets and a large number of unlabeled subsets. The labeled subsets are used to train the basic network, and the teacher model and student model are initialized simultaneously. The labeled subset is input into the student model for supervised training, and the unlabeled subset is input into both the teacher model and the student model simultaneously. The teacher model outputs initial pseudo-labels, and the student model extracts feature maps. Based on the initial pseudo-labels, a progressively decreasing threshold is used to filter and classify pixel types. Feature centers are extracted by combining feature maps and a memory bank is constructed. A contrastive learning loss is constructed based on the memory bank. A Gaussian distribution model is constructed based on a memory bank. The pixel-level feature assignment probability is calculated by inputting the feature map. The enhanced pseudo-mask is generated by fusing the initial pseudo-labels after screening. The pure pseudo-label is obtained after processing with three rules. Based on pure pseudo-labels, the student model is trained and updated while the teacher model is updated simultaneously. After multiple rounds of closed-loop optimization, the optimized student and teacher models are output.

[0006] Furthermore, the specific steps for synchronously initializing the teacher model and student model are as follows: Collect surface defect images from different industrial scenarios, perform standardized preprocessing, and obtain a unified set of industrial surface defect images; The industrial surface defect image set is divided into an annotated subset and an unannotated subset according to a preset ratio. The annotated subset consists of manually annotated instance-level defect images, which include defect category, detection box and pixel-level mask information. The unannotated subset consists of defect images that have not been manually annotated. The labeled subset is input into the base instance segmentation network for fully supervised pre-training. The network parameters of the base network are updated through backpropagation until the base network reaches the preset convergence condition on the validation set of the labeled subset, and the trained base network is obtained. The parameters of the backbone feature extraction module of the trained basic network are directly transferred to the corresponding modules of the teacher model and the student model. The parameters of the bounding box regression module and the mask generation module of the teacher model and the student model are initialized to complete the synchronous initialization of the teacher model and the student model.

[0007] Furthermore, the step of inputting the labeled subset into the student model for supervised training is achieved using a weighted combined loss function of classification loss, masking loss, and bounding box regression loss. The mathematical formula of the combined loss function is: , in, This represents the total loss value for supervised training of the student model. Cross-entropy classification loss is used to constrain the student model's prediction accuracy for defect categories. The mean squared error mask loss is used to constrain the pixel-level prediction accuracy of the student model for defect instance masks. The L1 bounding box regression loss is used to constrain the accuracy of the student model's coordinate prediction for defect instance detection boxes. The weighting coefficients for the classification loss are... The weighting coefficients for the mask loss are... The weighting coefficients for the box regression loss; The specific steps for inputting the labeled subset into the student model for supervised training are as follows: The labeled subset is used as supervised data input into the student model. The student model outputs defect prediction results. The loss value is calculated by combining the real labeled information with the loss function. The parameters of the student model are updated by backpropagation based on the loss value, thus completing the supervised training of the student model. An unlabeled subset is synchronously input into the supervised-trained student model and the initialized teacher model. The teacher model outputs initial pseudo-labels with pixel-level confidence after forward inference, while the student model outputs high-dimensional backbone feature maps and defect mask prediction results synchronously after complete forward inference.

[0008] Furthermore, the specific steps for using a progressively decreasing threshold to filter and classify pixel types are as follows: Using the initial pseudo-labels as input data, and based on the stage characteristics of model iteration, the initial pseudo-labels are filtered layer by layer using a progressively decreasing threshold to select pseudo-label data that meets the confidence requirements and remove invalid pseudo-label data with low confidence. Before filtering, the initial pseudo-labels are divided into different types of pixel regions according to pixel-level confidence features to complete the classification of pixel regions and obtain the classified pixel region mask. The feature map is multiplied by the filtered and classified pixel region mask by a pixel-wise tensor multiplication operation to obtain the weighted feature map of each pixel region. The weighted feature map of each pixel region is then averaged by pooling to obtain the feature center vector of each region. All extracted feature center vectors are classified and stored according to defect category and pixel region type to form a two-dimensional memory library; Based on the completed memory, a contrastive learning loss is constructed using the feature center data in the memory.

[0009] Furthermore, the specific steps for obtaining pure pseudo-labels after processing with the triple rules are as follows: A multidimensional Gaussian distribution model is constructed based on the feature center data stored in the memory bank. The feature map is input into the Gaussian distribution model, and the pixel-level feature assignment probability of each pixel in the feature map is calculated through the Gaussian distribution model to obtain the pixel-level feature assignment probability map. The initial pseudo-labels, after being filtered by progressively decreasing thresholds, are fused with the pixel-level feature attribution probability map at the pixel level, and an enhanced pseudo-mask is generated through feature fusion. The generated enhanced pseudo-masks are subjected to noise removal processing. The enhanced pseudo-masks are judged one by one by a preset three-fold rule. Pseudo-mask data that meets the noise judgment conditions are removed, and valid pseudo-mask data that meets the requirements are retained, finally obtaining clean pseudo-labels.

[0010] Furthermore, the three rules are the teacher-student prediction consistency judgment rule, the pseudo-label confidence validity judgment rule, and the feature center distribution rationality judgment rule. The three rules are judged independently, and a pseudo-mask that satisfies any one of the rules is judged as a noise pseudo-mask and is removed. The teacher-student prediction consistency judgment rule determines the validity of the pseudo-mask by calculating the overlap between the mask prediction results of the student model and the teacher model for the same unlabeled image. The rule for determining the confidence and validity of the pseudo-label is to determine the overall validity of the pseudo-mask by calculating the overall confidence of the enhanced pseudo-mask. The rule for determining the rationality of the feature center distribution is to calculate the distance between the feature center corresponding to the enhanced pseudo-mask and the feature center of the corresponding category and region unit in the memory, and then determine whether the feature center corresponding to the pseudo-mask conforms to the feature distribution pattern of the memory.

[0011] Furthermore, the formula for the contrastive learning loss is as follows: , in, To compare the learning loss values, a smaller loss value indicates higher feature similarity within the same category and region, and lower feature similarity between different categories and different regions. The feature center vector to be computed is any feature center extracted from the memory. For memory bank and The feature center vectors belonging to the same defect category include both simple and difficult defect regions within that category. m represents the total number of corresponding positive sample feature center vectors in the memory, and M represents the total number of feature center vectors in the memory. Negative samples are the feature center vectors of all background regions in the memory, as well as the feature center vectors of all other defect categories. This is a vector similarity calculation function that uses the dot product method to calculate the similarity between two feature center vectors. This is a temperature coefficient used to adjust the discriminative power of feature similarity calculation, making the differences in similarity between features more significant. The contrastive learning loss is calculated independently for each pixel region type. The contrastive learning loss values ​​of each region are weighted and summed to obtain the total contrastive learning loss. The total contrastive learning loss is combined with other loss terms to jointly constrain the training and optimization of the model.

[0012] Furthermore, the method for setting the progressively decreasing threshold is as follows: The training process is divided into multiple stages based on the model's iteration rounds. A corresponding confidence threshold is set for each training stage. The confidence threshold of each stage gradually decreases as the model's iteration rounds increase, thus achieving a gradual transition of pseudo-labels from high-purity screening to high-utilization screening. The specific operation of threshold filtering is to compare the pixel-level confidence value of the initial pseudo-label with the confidence threshold of the corresponding stage, retain pseudo-label pixels with confidence values ​​greater than the threshold, and remove pseudo-label pixels with confidence values ​​less than or equal to the threshold. The filtered pseudo-labels maintain the same size as the original image.

[0013] Furthermore, the synchronously updated teacher model is implemented using an exponential moving average algorithm, the mathematical formula of which is as follows: , in, These are the network parameters of the teacher model after the k-th iteration. The network parameters of the teacher model before the k-th iteration are... These are the network parameters of the student model after training and updating with pure pseudo-labels in the k-th iteration. It is the exponential moving average coefficient, used to balance the weight ratio of the original parameters of the teacher model and the updated parameters of the student model; The specific steps for training and updating the student model while simultaneously updating the teacher model are as follows: Pure pseudo-labels are used as supervised data input into the supervised training student model. The student model is then trained end-to-end iteratively. The network parameters of the student model are updated through backpropagation to obtain the student model with updated parameters. Based on the exponential moving average algorithm, the network parameters of the teacher model are synchronously updated using the updated network parameters of the student model to obtain the updated teacher model. The updated teacher-student model is used as the new base model to form a closed-loop optimization process for model training. Through multiple rounds of closed-loop optimization, the defect detection and segmentation performance of the teacher-student model is continuously improved. When the model reaches the preset closed-loop optimization convergence condition, the iterative training terminates, and the final optimized student model and teacher model are output.

[0014] Furthermore, the closed-loop optimization convergence condition is determined by both the convergence of the model's performance index and the saturation of the iteration rounds; the closed-loop optimization terminates when either condition is met. The convergence of the model performance indicators refers to the fact that, in multiple rounds of closed-loop optimization, the changes in the crossover ratio, detection precision, and detection recall of the student model on the preset validation set are all less than the preset deviation values, indicating that the model's performance has become stable. The iteration saturation refers to the process where the number of closed-loop optimization iterations of the model reaches the preset maximum number of iterations. Even if the model performance has not reached full convergence, the iteration is terminated to avoid model overfitting.

[0015] Compared with existing technologies, the incremental pseudo-label optimized weakly supervised detection and segmentation method for industrial defects provided by this invention has the following advantages: This invention achieves a dynamic balance between pseudo-label purity and data utilization by constructing a progressively decreasing threshold screening strategy. Through a dual-dimensional category-region memory and a category-centric contrastive learning loss design, it not only achieves refined modeling of defect features but also ensures the continuity of features in different regions of the same defect, effectively improving the accuracy of feature distribution modeling and the completeness of defect segmentation. Combined with a quantified triple noise removal rule and a stable teacher-student model update mechanism, it significantly improves the segmentation accuracy of industrial defects, especially micro-defects and defects with blurred edges, while greatly reducing the dependence on manually labeled data and improving the engineering feasibility and industrial scenario adaptability of the solution. Attached Figure Description

[0016] Figure 1 This is a flowchart illustrating a progressive pseudo-label optimized weakly supervised detection and segmentation method for industrial defects according to the present invention. Detailed Implementation

[0017] In the description of this invention, it should be understood that the terms "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "middle," and "inner," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, features defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this invention, it should be noted that unless otherwise explicitly specified and limited, the terms "installed," "connected," and "joined" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention through specific circumstances.

[0018] The embodiments of the present invention will be described below with reference to the accompanying drawings and related examples. The embodiments of the present invention are not limited to the following examples, and the present invention relates to the relevant necessary components in this technical field, which should be regarded as well-known technology in this technical field and can be known and mastered by those skilled in this technical field.

[0019] See Figure 1 This invention provides a progressive pseudo-label optimized method for weakly supervised detection and segmentation of industrial defects, characterized by the following steps: Step S100: Collect images of industrial surface defects, divide them into a small number of labeled subsets and a large number of unlabeled subsets, train the basic network using the labeled subsets, and simultaneously initialize the teacher model and student model. Industrial surface defect images are digital images containing potential defects on product surfaces, collected during industrial production. They typically originate from production line visual inspection systems and are used to identify and segment abnormal surface regions. A small labeled subset is a subset of industrial surface defect images with pixel-level manual annotations, used to provide initial high-quality labeled data for supervised training, supporting the initialization of the base network and teacher / student models. A large unlabeled subset is a collection of industrial surface defect images that have not been manually annotated, used for pseudo-label generation and model iterative optimization, reducing overall annotation costs. The base network is a deep neural network architecture used to perform image semantic segmentation tasks, generating preliminary feature representation capabilities and serving as the source of initial weights for the teacher and student models. The teacher model is a copy of the model responsible for generating pseudo-labels within a weakly supervised learning framework, outputting initial pseudo-labels for the student model to learn, maintaining prediction stability to reduce noise propagation. The student model is the main training model that receives supervised signals and is continuously optimized within the weakly supervised learning framework, gradually improving segmentation performance, and ultimately outputting the optimized detection model.

[0020] Step S200: Input the labeled subset into the student model for supervised training, and simultaneously input the unlabeled subset into the teacher model and the student model. The teacher model outputs the initial pseudo-labels, and the student model extracts the feature maps. The initial pseudo-labels are virtual annotations generated by the model after reasoning over unlabeled data. In this scheme, they are generated by the teacher model and include pseudo-categories of defects, pseudo-detection boxes, pseudo-masks, and pixel-level confidence scores. These can be used as supervisory signals for iterative training of the student model. The feature map is a multi-channel feature response map output from the intermediate layer of the student model, reflecting the spatial semantic information of the input image. It is used for feature center extraction, contrastive learning loss calculation, and attribution probability inference.

[0021] Step S300: Based on the initial pseudo-labels, a progressively decreasing threshold is used to filter and classify pixel types. Feature centers are extracted by combining feature maps and a memory bank is constructed. A contrastive learning loss is constructed based on the memory bank. The progressively decreasing threshold is a pixel-level confidence screening threshold that gradually decreases with each iteration of the model. A high threshold is set in the early stages of training to ensure the purity of pseudo-labels, while a low threshold is set in later stages to improve the utilization of unlabeled data, achieving dynamic optimization of pseudo-label screening. Feature centers are one-dimensional feature vectors obtained by pooling and aggregating high-dimensional features of a region in an industrial defect image. In this scheme, they are extracted according to pixel region type and are key data representing the core characteristics of that region. The feature memory is a feature database that classifies and stores feature center vectors according to defect category and pixel region type. Each category-region unit stores multiple feature centers, accurately representing the feature distribution patterns of different defects and different regions. Contrastive learning loss is a self-supervised loss function based on inter-sample similarity measurement, used to enhance the model's ability to discriminate defect categories and promote the separability of the feature space.

[0022] Step S400: Construct a Gaussian distribution model based on the memory bank, calculate the pixel-level feature assignment probability by inputting the feature map, and combine it with the initial pseudo-labels after screening to generate an enhanced pseudo-mask. After processing with three rules, a pure pseudo-label is obtained. The Gaussian distribution model is a multidimensional probability distribution model built based on the mean and variance of feature centers in the memory. In this scheme, it is used to characterize the feature distribution characteristics of different category-region units, realizing the calculation of pixel-level feature assignment probabilities. The enhanced pseudomask is generated by fusing the initial pseudomask (after thresholding) with the pixel-level feature assignment probability map. It combines the segmentation information of the initial pseudo-label with the probability information of the feature distribution, resulting in higher accuracy compared to the initial pseudomask. The pixel-level feature assignment probability is the probability value of each pixel belonging to a certain defect category in the feature space, providing soft and interpretable probabilistic support for pseudo-labels and helping to correct hard label errors.

[0023] Step S500: Based on pure pseudo-labels, train and update the student model and simultaneously update the teacher model. After multiple rounds of closed-loop optimization, output the optimized student model and teacher model.

[0024] Closed-loop optimization is a training method that uses the updated teacher-student model as a basis to repeatedly execute the process of "dual-path inference - pseudo-label optimization - model update". Through multiple rounds of iteration, the model parameters are continuously optimized, so that the defect detection and segmentation performance of the model is gradually improved and tends to be stable.

[0025] Taking the detection of surface defects in metal sheets as an example, the application method of this invention is as follows: This solution was deployed on a steel rolling production line, collecting images of steel plate surfaces to form a dataset, with only 5% of the samples annotated by experts. This annotated subset was used to train a basic segmentation network and initialize teacher and student models. During iterative training, the teacher model generated initial pseudo-labels for unannotated steel plate images, while the student model extracted deep feature maps. A progressively decreasing threshold was used to filter high-confidence pixels for extracting feature centers for various defects such as rust and cracks, and a two-dimensional memory bank containing category centers and spatial distribution statistics was constructed. Based on this memory bank, a Gaussian distribution model was established to calculate the probability of each pixel's classification and fuse it with the selected labels to generate an enhanced pseudo-mask. This mask was then processed using a triple rule (confidence filtering, isolated region elimination, and edge closure verification) to obtain a clean pseudo-label. The student model was updated accordingly, and the teacher model synchronized via EMA. After 10 rounds of closed-loop optimization, the model's segmentation accuracy for minor scratches and blurred oxidation regions was significantly improved, meeting the requirements of automated quality inspection on the production line.

[0026] This invention achieves a dynamic balance between pseudo-label purity and data utilization by progressively decreasing thresholds. It uses a two-dimensional memory and Gaussian distribution model to refine defect feature modeling, and contrastive learning loss to enhance feature discriminativeness. It uses a three-weighting rule to block the pollution of the model by noisy pseudo-labels at the source. Then, it uses an exponential moving average algorithm and multiple rounds of closed-loop optimization to achieve stable iterative upgrades of the teacher-student model. The overall solution significantly reduces the dependence on manually labeled data and effectively solves the problems of low pseudo-label quality, coarse feature modeling, and unstable model iteration in traditional weakly supervised defect segmentation schemes. It significantly improves the detection and segmentation accuracy of industrial micro-defects and edge-blurred defects. At the same time, the steps of the solution are closely connected and highly feasible, adapting to the surface defect detection needs of various industrial scenarios such as metal, PCB, and glass, and enhancing the practical application value of the model in industrial fields.

[0027] In one embodiment of the present invention, the specific steps for synchronously initializing the teacher model and the student model are as follows: Step S101: Collect surface defect images from different industrial scenarios, perform standardized preprocessing, and obtain a set of industrial surface defect images of uniform specifications; Specifically, for the target industrial application scenario, surface images containing various typical defects (such as scratches, dents, cracks, stains, missing corners, etc.) are collected, while background images without defects are also collected to ensure that the defect types and background features of the image set cover the actual production scenario. Three core preprocessing operations are performed on the collected raw images in sequence to eliminate interference factors during the acquisition process and ensure image uniformity. The preprocessing operations include size normalization, pixel value normalization, and image denoising. All preprocessed images are stored in a standardized format to form a uniform industrial surface defect image set, which serves as the basis for subsequent dataset partitioning and model training.

[0028] Step S102: Divide the industrial surface defect image set into an annotated subset and an unannotated subset according to a preset ratio. The annotated subset consists of manually annotated instance-level defect images, including defect category, detection box and pixel-level mask information. The unannotated subset consists of defect images that have not been manually annotated. Specifically, based on the sample characteristics of weakly supervised learning, the ratio of labeled subsets to unlabeled subsets is set (labeled subsets typically account for 5%-20%, and unlabeled subsets account for 80%-95%). This reduces the cost of manual annotation while ensuring that the sample size of the labeled subsets is sufficient to support the pre-training of the basic network. Professional annotators in the field of industrial defect detection use specialized annotation tools to perform refined instance-level annotations on the labeled subsets. The annotation information must include three core elements, and the annotation accuracy must match the image resolution, including defect category, detection box, and pixel-level mask. The images of the labeled subsets are associated and stored with the corresponding annotation files, while the unlabeled subsets only store the preprocessed images, forming a weakly supervised dataset that can be directly used for model training.

[0029] Step S103: Input the labeled subset into the base instance segmentation network for fully supervised pre-training, and update the network parameters of the base network through backpropagation until the base network reaches the preset convergence condition on the validation set of the labeled subset, and obtain the trained base network. Specifically, the basic instance segmentation network adopts a lightweight / high-precision instance segmentation network architecture adapted to industrial defect detection (such as MaskR-CNN, YOLACT, SOLOv2). The network needs to include three core modules: backbone feature extraction, bounding box regression, and mask generation, adapting to the characteristics of small targets and blurred edges in industrial defects. 10%-20% of the samples are randomly selected from the labeled subset as a validation set, and the remaining samples are used as the training set to avoid overfitting of the basic network during pre-training. The training set of the labeled subset is input into the basic instance segmentation network and trained using a fully supervised learning method, with the labeled defect categories, bounding boxes, and pixel-level masks as the ground truth. The supervisory signal calculates the deviation between the predicted and true values ​​using a combined loss function (classification loss + bounding box regression loss + mask loss). Stochastic gradient descent (SGD) or adaptive moment estimation (Adam) optimizers are then used to continuously update all network parameters via backpropagation. During training, the performance of the base network is tested on a validation set after each iteration. When the defect segmentation intersection-over-union ratio, detection precision, and recall on the validation set show no significant improvement over multiple iterations (e.g., 20 iterations), and the loss value stabilizes, the preset convergence condition is met, training stops, and the trained base network is obtained. This network possesses basic capabilities for industrial defect feature recognition, localization, and segmentation.

[0030] Step S104: Directly transfer the parameters of the backbone feature extraction module of the trained basic network to the corresponding modules of the teacher model and student model, initialize the parameters of the bounding box regression module and mask generation module of the teacher model and student model, and complete the synchronous initialization of the teacher model and student model.

[0031] Specifically, the teacher model, student model, and base network adopt the same instance segmentation network architecture, ensuring a one-to-one correspondence between the backbone feature extraction module, bounding box regression module, and mask generation module of the three models, providing a foundation for parameter transfer and initialization. All training parameters of the backbone feature extraction module in the trained base network are directly copied and transferred to the corresponding backbone modules of the teacher and student models without additional modification. Utilizing the basic industrial defect features (such as edges, textures, and shapes) learned by the base network on labeled subsets, the backbone modules of the teacher and student models possess efficient feature extraction capabilities from the initial stage, avoiding slow feature learning caused by training from scratch. The bounding box regression module and mask generation module of the teacher and student models are initialized using a random normal distribution. This method ensures that parameter values ​​fluctuate slightly around 0, avoiding gradient explosion / vanishing during subsequent training due to excessively large or small initial parameters. After completing parameter transfer and initialization, the network parameters of the teacher and student models are verified to confirm that the backbone module parameters are consistent with the base network and that the initialization of the detection and mask module parameters is reasonable. This completes the synchronous initialization of the teacher and student models.

[0032] It should be noted that the process of inputting the labeled subset into the student model for supervised training is implemented using a weighted combined loss function of classification loss, masking loss, and bounding box regression loss. The mathematical formula of the combined loss function is as follows: , in, The total loss value for supervised training of the student model measures the comprehensive deviation between the predicted results and the actual labeled information of the student model in three major tasks: industrial defect category determination, pixel-level mask segmentation, and detection box localization. The value is a non-negative floating-point number. The total loss of a single image is calculated according to the formula. The average of the total loss of all images in a batch is used to obtain the batch total loss value, which serves as the basis for parameter updates in this round. The batch total loss can better reflect the deviation of the model on the overall data, avoid parameter update oscillation caused by outliers in a single image, and adapt to the problem of uneven distribution of industrial defect image data. Cross-entropy is the classification loss used to constrain the student model's prediction accuracy for defect categories. It measures the deviation between the student model's predicted industrial defect categories and the true labeled categories. The value is a non-negative floating-point number; the smaller the value, the more accurate the category determination. It is obtained as follows: The student model outputs a probability distribution vector of defect categories (dimension equal to the number of defect categories); the true defect categories are converted into one-hot encoded vectors (with the same dimension as the predicted probability distribution vector); the cross-entropy value of the two vectors is calculated using the cross-entropy formula, which is the cross-entropy loss for a single image. If the image contains multiple defects, for all defects... Calculate the mean. Adapt to situations in industrial settings where a single image contains multiple different types of defects, ensuring the reasonableness of the category loss calculation.

[0033] The mean squared error (MSE) mask loss is used to constrain the pixel-level prediction accuracy of the student model for defect instance masks. It measures the pixel-by-pixel deviation between the pseudo-mask output by the student model and the real mask. The value is a non-negative floating-point number; the smaller the value, the more accurate the pixel-level segmentation. The method for obtaining the MSE is as follows: Normalize both the pseudo-mask and the real mask output by the student model to the 0-1 interval to ensure that their pixel value ranges are consistent; calculate the square of the difference between the two masks pixel by pixel to obtain the pixel-by-pixel MSE; and calculate the mean of the MSE of all pixels in the image, which is the mean squared error for a single image. It is highly adaptable to industrial scenarios with blurred defect edges and small targets, and can accurately quantify subtle pixel segmentation deviations.

[0034] The L1 bounding box regression loss is used to constrain the accuracy of the student model's coordinate prediction for defect instance detection boxes. It measures the deviation between the student model's output detection box coordinates and the true coordinates. The value is a non-negative floating-point number; the smaller the value, the more accurate the detection box localization. The method for obtaining this loss is as follows: normalize the center coordinates, width, and height of the detection box to the 0-1 interval to eliminate the influence of image scale; calculate the absolute error between the predicted and true coordinates, and average the absolute errors of the four coordinate values; if the image contains multiple defects, average the bounding box regression loss for all defects, which is the average value for a single image. It exhibits strong robustness to outliers in coordinate prediction caused by image noise and small defects in industrial scenarios, avoiding drastic fluctuations in parameter updates.

[0035] The weighting coefficient for classification loss is initially set to 0.2-0.4 for general industrial scenarios. If the defect categories are diverse and easily confused (such as scratches and fine lines on metal surfaces), the value will be increased to 0.4-0.5. If the accuracy of the validation set category is low during training, it will be gradually fine-tuned to improve it. The weighting coefficient for the mask loss is 0.4-0.6 for general industrial scenarios. If the defect edges are blurry or the proportion of small targets is high (such as microcracks in glass panels), the value is increased to 0.6-0.7. If the crossover ratio of the validation set is too low during training, it is gradually fine-tuned and improved. The weighting coefficient for the bounding box regression loss is 0.1-0.3. For general industrial scenarios, the initial value is taken as 0.1-0.3. If the defect locations are scattered and difficult to locate (such as solder joint defects on PCB boards), the value is increased to 0.3-0.4. If the average accuracy of the detection boxes on the validation set is low during training, it is gradually fine-tuned to improve it. The single adjustment range of fine-tuning shall not exceed 0.05 to avoid gradient oscillation during model training due to sudden changes in weights, and to ensure the stability of supervised training of student models.

[0036] The specific steps for inputting the labeled subset into the student model for supervised training are as follows: Step S201: The labeled subset is input as supervised data into the student model. The student model outputs the defect prediction result. The loss value is calculated by combining the real labeled information through the combined loss function. The parameters of the student model are updated by backpropagation based on the loss value, thus completing the supervised training of the student model. Specifically, using a subset of instance-level annotations as core supervised data, the images are first subjected to the same standardized preprocessing as before (size normalization, pixel value normalization). Lightweight random data augmentation is added for industrial small sample scenarios (horizontal flip only, ±10° small angle rotation to avoid losing defect features). At the same time, the annotation information (defect category, detection box, pixel-level mask) is converted from the annotation file into numerical tensors that the model can compute. The category is converted to one-hot encoding, the detection box coordinates are normalized to the 0-1 interval, and the mask is converted to a binary tensor. Then, the batch size is set according to the hardware computing power, and the image tensor and the annotation tensor are paired and packaged, and then input into the student model that has completed synchronous initialization in batches. The student model relies on a three-layer architecture of backbone feature extraction, feature fusion, and multi-task prediction to complete forward inference. It extracts multi-dimensional features of defects such as edges, textures, and semantics from the input image, and simultaneously outputs three types of defect prediction results corresponding to the annotation information: defect category probability distribution, normalized coordinates of detection boxes, and pixel-level mask prediction values. All prediction results are in tensor format matching the input batch, and after activation function processing, their numerical range is consistent with the annotation data. The model prediction results are matched one-to-one with the real annotation information by intersection-union of detection boxes, solving the problem of mismatched multiple defects in the same image. The single-sample values ​​of cross-entropy classification loss, mean squared error mask loss, and L1 box regression loss are calculated separately. After averaging the single losses of all samples in the batch, the total batch loss value is obtained by fusing them through a combined loss function with preset weighting coefficients. The loss value directly represents the comprehensive deviation between the prediction results and the real annotations. The Adam or SGD optimizer, adapted for small-sample industrial training, is selected. The total loss value is used as the optimization objective. An automatic differentiation framework is used to calculate the gradient values ​​of all trainable parameters inversely from the model's output layer to the input layer. To avoid gradient explosion, the gradients are clipped using the L2 norm. Then, gradient descent is used to apply the clipped gradients to the model parameters, completing a single batch parameter update. After each batch of training, the gradients are immediately cleared, and the next batch of data is loaded, repeating the above operation until a single round of training is complete. 10%-20% of the samples are extracted from the labeled subset as an independent validation set. After each round of training, the model performance is tested using the validation set, calculating the three core metrics: classification accuracy, segmentation intersection-over-union ratio, and average precision of detection boxes. When the validation set metrics show no significant improvement over several consecutive rounds and the loss value tends to stabilize, the training convergence condition is met, supervised training is terminated, and the student model parameters at this point are saved, resulting in a student model with basic industrial defect detection and segmentation capabilities.

[0037] Step S202: The unlabeled subset is synchronously input into the supervised training student model and the initialized teacher model. The teacher model outputs initial pseudo-labels with pixel-level confidence through forward inference. The student model outputs high-dimensional backbone feature maps and defect mask prediction results through complete forward inference.

[0038] Specifically, the unlabeled subset images undergo the same standardized preprocessing (size normalization, pixel value normalization) as the labeled subset, without any data augmentation, to ensure the feature authenticity of the inference data. The data is then batch-processed into tensor format and loaded onto the model training hardware (GPU / TPU) to ensure device compatibility between the data and model parameters. The preprocessed batch data of the unlabeled subset is simultaneously input into both the student model (completed basic supervised training) and the teacher model (completed synchronous initialization). Both models simultaneously perform forward inference computation, keeping the network parameters fixed during inference without any updates to ensure the stability of the inference results. The teacher model, relying on its initialized network parameters, performs defect detection, classification, and segmentation inference on the unlabeled images, outputting complete initial pseudo-labels. These pseudo-labels contain three core pieces of information: defect pseudo-category, pseudo-detection box normalized coordinates, and a pseudo-mask. Each pixel in the pseudo-mask is accompanied by a pixel-level confidence value in the 0-1 range (obtained by fusing the pixel probability value from the model mask generation module with the instance-level confidence value; a higher value indicates a more reliable pixel judgment). The tensor size of the initial pseudo-labels perfectly matches the input images. The student model completes full forward inference, simultaneously outputting a high-dimensional backbone feature map and defect mask prediction results. The backbone feature map is extracted from the intermediate layer of the backbone feature extraction module and used for subsequent feature center extraction and Gaussian distribution feature assignment probability calculation. The defect mask prediction results are output from the mask generation module and are only used for teacher-student prediction consistency determination; they do not participate in pseudo-label generation or model training. The backbone feature map is a [C,H,W]-dimensional tensor (C is the number of feature channels, H and W are the feature map height and width), containing multi-scale low-level and high-level feature information of industrial defects. It is the core feature data for subsequent pseudo-label screening and feature center extraction. After standardization, the feature map is directly used as input data for the pseudo-label optimization stage.

[0039] In one embodiment of the present invention, the specific steps of using a progressively decreasing threshold to filter and classify pixel types are as follows: Step S301: Using the initial pseudo-labels as input data, based on the stage characteristics of model iteration, the initial pseudo-labels are filtered layer by layer using a progressively decreasing threshold to filter out pseudo-label data that meet the confidence requirements and remove invalid pseudo-label data with low confidence. Specifically, based on the total number of iterations for the overall closed-loop optimization of the model, the training process is divided into three stages: early, middle, and late. There is no fixed ratio of stages; it can be adjusted according to the size of the industrial defect dataset (e.g., in a total of 1000 stages, the early stage consists of 1-300 stages, the middle stage 301-700 stages, and the late stage 701-1000 stages). Following the principle of using a high threshold to maintain purity in the early stage, a medium threshold for a stable transition in the middle stage, and a low threshold to improve utilization in the late stage, a unique pixel-level confidence threshold is set for each stage. All thresholds are floating-point numbers in the range of 0-1, and are gradually increased as the stage progresses. Lowering the threshold (e.g., T=0.8 in the early stage, T=0.5 in the middle stage, and T=0.3 in the later stage) adapts to the gradual performance improvement during model training; comparing the confidence value of each pixel in the initial pseudo-labels output by the teacher model with the threshold of the current training stage, retaining pixels with confidence values ​​greater than the threshold, and setting pixels with confidence values ​​less than or equal to the threshold as background (confidence set to zero); maintaining the same size between the pseudo-labels and the original image during the selection process, and preserving the overall contour features of defective instances to avoid over-selection leading to the loss of effective defective pixels.

[0040] Step S302: Before filtering, the initial pseudo-labels are divided into different types of pixel regions according to the pixel-level confidence features to complete the classification of pixel regions and obtain the classified pixel region mask. Specifically, based on the actual characteristics of industrial defect detection, the screened pseudo-labels are divided into four types of pixel regions according to the range of pixel-level confidence scores. The range division conforms to the confidence distribution pattern between defects and background. There is no fixed value, which can be fine-tuned according to the scenario. The general division standard is: simple background region (confidence 0-T / 2, where T is the screening threshold in the current training stage, and the value range of T is 0-1), difficult background region (confidence T / 2-T), difficult defect region (confidence T-(T+1) / 2), and simple defect region (confidence (T+1) / 2-1.0). Binary pixel region masks are generated for the four types of pixel regions after division. The mask size is completely consistent with the initial pseudo-labels and backbone feature maps. In the mask, the pixel value of the target region is 1, and the pixel value of the non-target region is 0. Each type of region corresponds to an independent mask, forming a mask set composed of four types of masks, realizing regional filtering of the backbone feature map.

[0041] Step S303: Perform pixel-wise tensor multiplication on the feature map and the filtered and classified pixel region mask to obtain the weighted feature map of each pixel region. Perform average pooling on the weighted feature map of each pixel region to obtain the feature center vector of each region. Specifically, the high-dimensional backbone feature map extracted from the student model (dimensions [C,H,W], where C is the number of channels and H / W is the height / width of the feature map) is multiplied by a pixel-wise tensor (Hadamard product) with the generated mask for each type of pixel region. During the operation, the two-dimensional mask is automatically expanded into a three-dimensional mask [C,H,W] that matches the feature map. After the operation, only the target region features with a value of 1 in the mask are retained, and the non-target region features are set to 0, resulting in four types of weighted feature maps. Each type of weighted feature map contains only the effective features of the corresponding region. A global average pooling operation is performed on each type of weighted feature map to compress the three-dimensional region weighted feature map [C,H,W] into a one-dimensional feature vector [C]. This vector is the feature center vector of the corresponding pixel region. During the pooling process, the feature values ​​of all pixels in the region are averaged, which can effectively represent the overall feature distribution of the region and avoid the random influence of single pixel features.

[0042] Step S304: Classify and store all extracted feature center vectors according to defect category and pixel region type to form a two-dimensional memory library; Specifically, the two-dimensional classification criteria of the memory are determined to be defect category and pixel region type. The defect category is consistent with the defect classification criteria of the labeled subset (such as scratches, dents, cracks, etc.), and the pixel region type is the four types of regions. A two-dimensional index structure of category-region is established for the memory. The extracted feature center vectors are stored in the corresponding index units of the memory according to their corresponding defect instance category and pixel region type. Each index unit can store multiple feature center vectors, which are continuously accumulated as the model iterates and trains. The vectors in the same unit are all feature representations of the same category and region. The memory only stores the valid feature center vectors after threshold screening. Low-confidence feature vectors that fail the screening are not included in the storage. The storage capacity of the memory can be flexibly set according to hardware resources. When the capacity is exceeded, the earliest stored vector is removed according to the first-in-first-out principle to ensure the timeliness of the feature data in the memory.

[0043] Step S305: Based on the completed memory, construct a contrastive learning loss using the feature center data in the memory.

[0044] Specifically, using any feature center vector to be calculated in the memory as the query sample, other feature center vectors of the same defect category and pixel region type in the memory are set as positive samples, and all feature center vectors in the memory except those of the same category and region are set as negative samples. Both positive and negative samples are extracted from the corresponding index units in the memory. The contrastive learning loss is calculated independently for each of the four types of pixel regions. First, the feature similarity between the query sample and all positive and negative samples is calculated by vector inner product. Then, a temperature coefficient is introduced to adjust the discriminative power of the similarity. Finally, the loss value of a single region is calculated according to the classic formula of contrastive learning. The smaller the loss value, the higher the similarity of features of the same category and region and the stronger the discriminative power of features of different categories / regions. The contrastive learning loss of the single regions of the four types of regions is weighted and summed to obtain the total contrastive learning loss. The weighting coefficient is set according to the training importance of the region. The weighting coefficient of difficult defect regions and difficult background regions is higher than that of simple defect regions and simple background regions (e.g., the coefficient of difficult region is 0.3 and the coefficient of simple region is 0.2), highlighting the feature learning of difficult regions such as blurred edges and complex backgrounds. The total contrastive learning loss will be combined with the combined loss function to jointly constrain the iterative training of the subsequent student model.

[0045] In one embodiment of the present invention, the specific steps for obtaining pure pseudo-labels after processing with triple rules are as follows: Step S401: Construct a multidimensional Gaussian distribution model based on the feature center data stored in the memory bank, input the feature map into the Gaussian distribution model, calculate the pixel-level feature assignment probability of each pixel in the feature map through the Gaussian distribution model, and obtain the pixel-level feature assignment probability map. Specifically, for the constructed two-dimensional memory, the mean and variance of two core statistics are calculated for each feature center vector stored in each category-region index unit, channel by channel. The statistical calculation covers all channels of the feature center vector, ensuring that the distribution model can represent the overall distribution pattern of high-dimensional features. If the number of feature center vectors in a certain unit is insufficient, the average statistics from the early stages of model training are temporarily used as a substitute, and gradually updated with iterations. Based on the mean and variance of the feature channels of each category-region unit, a multidimensional Gaussian distribution model is independently constructed for each unit, with the model's dimension matching the number of channels in the feature center vector. This model can accurately represent the feature distribution pattern of the corresponding category-region, quantify the likelihood probability of a feature vector belonging to that unit, and provide a mathematical basis for pixel-level feature attribution determination. The output high-dimensional backbone feature map extracts feature vectors pixel by pixel. The feature vector of each pixel is input into the multidimensional Gaussian distribution model of all category-region units, and the Gaussian likelihood probability of the feature vector belonging to the corresponding unit is calculated. For each pixel, the likelihood probability of all units is normalized to obtain the pixel-level feature assignment probability of the pixel belonging to each category-region unit. Finally, a pixel-level feature assignment probability map that perfectly matches the size of the backbone feature map is generated. Each pixel in the probability map stores the assignment probability value of each category-region. The higher the value, the higher the feature matching degree of the pixel belonging to the corresponding unit.

[0046] Step S402: Perform pixel-level fusion processing on the initial pseudo-labels after progressively decreasing threshold filtering and the pixel-level feature attribution probability map to generate an enhanced pseudo-mask through feature fusion. Specifically, the pixel-level confidence values ​​of the initial pseudo-labels after progressively decreasing threshold filtering, and the probability values ​​of the pixel-level feature assignment probability map, are both normalized to the 0-1 range to ensure that the numerical ranges of the two types of data are consistent and to avoid information imbalance caused by differences in magnitude during fusion. A pixel-level dynamic weighted fusion operation is then performed on the normalized initial pseudo-labels and the pixel-level feature assignment probability map. The fusion weights are dynamically adjusted according to the confidence features of the pixels. The core principle is: for high-confidence areas of the defect core, the fusion weight of the initial pseudo-label is increased (weight ratio 0.6-0.8) to retain its accurate segmentation information; for defect edges and blurred low-confidence areas, the fusion weight of the pixel-level feature assignment probability map is increased (weight ratio 0.6-0.7) to correct segmentation deviations using feature distribution patterns; background areas are fused with equal weights (0.5 each) to ensure the stability of background determination. After fusion, a pixel-level enhanced confidence map is obtained. Adaptive binarization is performed on this confidence map. Based on the pseudo-label confidence threshold of the current training stage, pixels with confidence values ​​greater than the threshold are judged as defective pixels (value 1), and pixels with confidence values ​​less than or equal to the threshold are judged as background pixels (value 0). Finally, an enhanced pseudo-mask with the same size as the original image is generated. This mask combines the segmentation contour and feature distribution probability judgment of the initial pseudo-label, and has higher segmentation accuracy and completeness than the initial pseudo-label.

[0047] Step S403: Perform noise removal processing on the generated enhanced pseudo-mask. The enhanced pseudo-mask is judged one by one by a preset triple rule. Pseudo-mask data that meets the noise judgment conditions is removed, and valid pseudo-mask data that meets the requirements is retained, and finally a clean pseudo-label is obtained.

[0048] Specifically, the generated enhanced pseudomasks undergo an edge-adaptive refinement process. Morphological closing operations are used to fill tiny holes in the defect area, and morphological opening operations are used to remove isolated noise pixels in the background area. Simultaneously, an edge smoothing algorithm optimizes the contours of the defect edges to ensure the morphological integrity of the pseudomask, laying the foundation for subsequent noise removal. A triple rule system is employed: consistency of teacher-student predictions, validity of pseudo-label confidence, and rationality of feature center distribution. Each instance of the refined enhanced pseudomask is quantitatively evaluated. The three rules are used independently but in combination; satisfying any one rule results in a noisy pseudomask that is directly removed. All indicators are quantitatively calculated during the evaluation process to avoid ambiguity in qualitative judgments. After removing all pseudomask instances that meet the noise criteria, valid enhanced pseudomasks that meet the triple rule requirements are retained. Each valid pseudomask is matched with its corresponding defect category and detection box information, integrating them to form a complete and clean pseudo-label containing the defect category, detection box coordinates, and pixel-level mask.

[0049] It should be noted that the three rules are the teacher-student prediction consistency judgment rule, the pseudo-label confidence validity judgment rule, and the feature center distribution rationality judgment rule. The three rules are judged independently, and a pseudo-mask that satisfies any one of the rules is judged as a noise pseudo-mask and is removed. The teacher-student prediction consistency judgment rule determines the validity of the pseudo-mask by calculating the overlap between the mask prediction results of the student model and the teacher model for the same unlabeled image. Specifically, the defect mask from the initial pseudo-label output by the teacher model and the predicted defect mask from the modified student model are extracted separately. Both are binary masks with the same size as the original image. The Intersection over Union (IoU) ratio is used as a quantification of the overlap. The ratio of the number of intersection pixels to the number of union pixels in the binary masks of the teacher and student models is calculated. The result is a floating-point number between 0 and 1. A higher value indicates a higher overlap between the predictions of the teacher and student models, and a stronger reliability of the pseudo-mask. A preset threshold for the IoU ratio is set (empirical values ​​of 0.5~0.7 for industrial defect scenarios), and the threshold is dynamically adjusted according to the model training stage—in the early stage of training, when model performance is low, the threshold is set to 0.5~0.6, and the judgment criteria are appropriately relaxed; in the later stage of training, when model performance tends to stabilize, the threshold is increased to 0.6~0.7 to strictly control the quality of the pseudo-mask; if the calculated IoU value is lower than the preset threshold for the corresponding stage, the defect instance is determined to meet the noise condition of this rule.

[0050] The rule for determining the confidence and validity of the pseudo-label is to determine the overall validity of the pseudo-mask by calculating the overall confidence of the enhanced pseudo-mask. Specifically, pixel-level confidence values ​​are extracted from all pixels (excluding background pixels) of the target defect instance in the enhanced pseudomask. The confidence value is a floating-point number between 0 and 1, which is the enhanced confidence obtained after dynamic weighted fusion in the early stage, representing the reliability of the model's determination that the pixel is a defect. The arithmetic mean of the confidence values ​​of all pixels of the extracted defect instance is calculated as the overall confidence of the enhanced pseudomask. The mean calculation can comprehensively reflect the confidence level of the entire defect instance and avoid the random influence of high / low confidence of a single pixel. A preset threshold for the overall confidence is set (empirical value of 0.4~0.6 for industrial defect scenarios). The threshold is dynamically adjusted with the training stage—in the early stage of training, the overall quality of pseudo labels is low, so the threshold is set to 0.4~0.5; in the later stage of training, the quality of pseudo labels improves, so the threshold is increased to 0.5~0.6. If the calculated average of the overall confidence is lower than the preset threshold of the corresponding stage, the defect instance is determined to meet the noise condition of this rule.

[0051] The rule for determining the rationality of the feature center distribution is to calculate the distance between the feature center corresponding to the enhanced pseudo-mask and the feature center of the corresponding category and region unit in the memory, and then determine whether the feature center corresponding to the pseudo-mask conforms to the feature distribution pattern of the memory.

[0052] Specifically, the defect feature center vector corresponding to the current enhanced pseudomask is extracted using the same extraction method as the feature center extraction logic, resulting in a one-dimensional high-dimensional feature vector after region filtering and average pooling. From the two-dimensional memory, the average feature center vector of the category-region unit to which the defect instance belongs is extracted, i.e., the average of all feature center vectors stored in that unit is calculated channel-by-channel to obtain a vector that characterizes the standard feature distribution of that category-region, ensuring that its dimension is completely consistent with the feature center vector to be determined. Euclidean distance is used as a quantitative indicator of feature distribution deviation to calculate the difference between the defect feature center vector to be determined and the corresponding average feature center vector in the memory. The Euclidean distance between the feature center vectors is a non-negative floating-point number. The smaller the value, the closer the feature distributions of the two vectors are, and the stronger the rationality of the pseudo-mask features. A preset threshold for the Euclidean distance is set according to the channel dimension of the feature center vector (e.g., the empirical threshold is 5-8 for 256-dimensional feature vectors and 8-12 for 512-dimensional feature vectors). The threshold is dynamically adjusted with the training stage—in the early stage of training, when the feature data accumulation in the memory bank is insufficient, the threshold is appropriately relaxed; in the later stage of training, when the feature distribution in the memory bank tends to stabilize, the threshold is strictly tightened. If the calculated Euclidean distance exceeds the preset threshold for the corresponding stage, the defective instance is determined to meet the noise condition of this rule.

[0053] It should be noted that the formula for the contrastive learning loss is as follows: , in, To compare the learning loss values, a smaller loss value indicates higher feature similarity within the same category and region, and lower feature similarity between different categories and different regions. The feature center vector to be computed is any feature center extracted from the memory. For memory bank and The feature center vectors belonging to the same defect category include both simple and difficult defect regions within that category. m represents the total number of corresponding positive sample feature center vectors in the memory, and M represents the total number of feature center vectors in the memory. Negative samples are the feature center vectors of all background regions in the memory, as well as the feature center vectors of all other defect categories. This is a vector similarity calculation function that uses the dot product method to calculate the similarity between two feature center vectors. This is a temperature coefficient used to adjust the discriminative power of feature similarity calculation, making the differences in similarity between features more significant. In industrial defect detection scenarios, an empirical fixed value is used, with a general range of 0.1-0.2. If the defect features are highly similar (such as scratches and fine lines on metal surfaces), 0.1 can be used to further amplify the feature differences; if the feature differences are significant, 0.2 can be used.

[0054] This invention employs a contrastive learning loss method that uses defect category as the core dimension to divide positive and negative samples. All pixel regions within the same defect category (including the core region of simple defects and the edge region of difficult defects) are designated as positive samples, while all background regions and other defect categories are designated as negative samples. This design not only enhances the feature discrimination capability between different defect categories but also narrows the feature distance between the core and edge regions of the same defect through positive sample constraints, achieving feature alignment from the edge region to the core region. This effectively improves the continuity and completeness of defect segmentation, and is particularly suitable for the characteristics of industrial defects with blurred edges and diverse shapes.

[0055] The contrastive learning loss is calculated independently for each pixel region type. The contrastive learning loss values ​​of each region are weighted and summed to obtain the total contrastive learning loss. The total contrastive learning loss is combined with other loss terms to jointly constrain the training and optimization of the model.

[0056] It should be noted that the method for setting the progressively decreasing threshold is as follows: The training process is divided into multiple stages based on the model's iteration rounds. A corresponding confidence threshold is set for each training stage. The confidence threshold of each stage gradually decreases as the model's iteration rounds increase, thus achieving a gradual transition of pseudo-labels from high-purity screening to high-utilization screening. Specifically, based on the iteration rounds of model closed-loop optimization, the overall training process is divided into three stages: early, middle, and late. A unique pixel-level confidence threshold is matched for each stage, following a step-by-step decreasing principle. The core principle is to set the threshold according to the following: "high threshold in the early stage to maintain purity, medium threshold in the middle stage to stabilize the transition, and low threshold in the late stage to improve utilization." In general scenarios, the threshold is set to 0.7-0.9 in the early stage, 0.4-0.6 in the middle stage, and 0.2-0.3 in the late stage. It can also be fine-tuned according to the actual characteristics of industrial defects. For scenarios with blurred edges and a high proportion of small targets, the threshold in the early stage can be appropriately increased and the threshold in the late stage can be decreased. For scenarios with clear defect outlines, the threshold in the early stage can be appropriately relaxed. The threshold remains fixed within the same stage and is only updated when switching stages to avoid frequent changes in the threshold that cause gradient oscillations in model training and to adapt to the iterative improvement pattern of the model from low performance to high performance.

[0057] The specific operation of threshold filtering is to compare the pixel-level confidence value of the initial pseudo-label with the confidence threshold of the corresponding stage, retain pseudo-label pixels with confidence values ​​greater than the threshold, and remove pseudo-label pixels with confidence values ​​less than or equal to the threshold. The filtered pseudo-labels maintain the same size as the original image.

[0058] Specifically, the initial pseudo-label pixel-level confidence score output by the teacher model is used as the sole criterion. The confidence score of each pixel in the confidence score map is compared pixel by pixel with the current stage threshold. Valid pseudo-label pixels with confidence scores greater than the threshold are retained, while invalid pixels with confidence scores less than or equal to the threshold are set to background and their confidence scores are set to zero. The entire screening process only modifies the pixel and confidence scores of the pseudo-labels without performing any spatial transformations such as cropping, scaling, or translation. This strictly ensures that the screened pseudo-labels are completely consistent in size with the original industrial defect image and the backbone feature map extracted by the student model. This provides a precise spatial alignment basis for subsequent pixel type classification and pixel-by-pixel tensor multiplication operations of feature maps and region masks, ensuring the effectiveness of the data source in subsequent pseudo-label optimization stages.

[0059] It should be noted that the synchronously updated teacher model is implemented using the exponential moving average algorithm, the mathematical formula of which is as follows: , in, These are the network parameters of the teacher model after the k-th iteration. The network parameters of the teacher model before the k-th iteration are... These are the network parameters of the student model after training and updating with pure pseudo-labels in the k-th iteration. This is the exponential moving average coefficient, used to balance the weight ratio of the original parameters of the teacher model and the updated parameters of the student model. In industrial defect detection scenarios, it is taken as an empirical fixed value, with a general range of 0.99-0.999, which does not need to be dynamically adjusted with each iteration. If the defect features are complex and the model is prone to overfitting, 0.999 can be used to further improve the stability of the teacher model parameters. If the dataset is large and the defect features are clear, 0.99 can be used to moderately improve the update efficiency of the teacher model parameters. The specific steps for training and updating the student model while simultaneously updating the teacher model are as follows: Step S501: Input the clean pseudo-labels as supervised data into the supervised training student model, perform end-to-end iterative training on the student model, update the network parameters of the student model through backpropagation, and obtain the student model with updated parameters. Specifically, pure pseudo-labels are matched one-to-one with their corresponding unlabeled images. A reasonable batch size is set according to the hardware computing power for industrial defect training (e.g., batch size of 8-16 for 512×512 resolution images), constructing training batch data. Only standardization preprocessing is performed on the images; no data augmentation is done to ensure consistency with features from the inference stage. The batch data is then input into the supervised-trained student model to perform forward inference, outputting the predicted defect category, detection box, and mask. Combined with the real supervision information from the pure pseudo-labels, a combined loss function (classification + mask + bounding box regression loss) is used to... The learning loss is compared and the total loss value of the training batch is calculated to achieve dual constraints on detection and segmentation performance and feature discriminativeness. The Adam or SGD optimizer is selected with the total loss value as the optimization objective. The gradient of the parameters of each layer of the model is calculated through backpropagation. After the gradient is clipped by L2 norm to avoid gradient explosion, all trainable parameters of the student model are updated by gradient descent to complete the single batch training. The single training round covers all unlabeled data corresponding to pure pseudo-labels. During the training process, the model performance is tested with a validation set at regular intervals. The convergence status of the model is monitored in real time to ensure that the model is not overfitting.

[0060] Step S502: Based on the exponential moving average algorithm, the network parameters of the teacher model are synchronously updated using the network parameters of the updated student model to obtain the updated teacher model. Specifically, before performing the update, the original network parameters of the teacher model before the k-th iteration are extracted. The latest network parameters of the student model after training with pure pseudo-labels. To ensure complete consistency in network structure and parameter dimensions between the two models, eliminating any dimension mismatch issues, an exponential moving average coefficient is set (0.99-0.999 for industrial defect scenarios). The two parameter sets are then weighted element-wise according to the EMA algorithm formula: first, the original parameters of the teacher model are multiplied by θ, and the new parameters of the student model are multiplied by (1-θ). Then, the two weighted parameter sets are summed element-wise to obtain the new parameters of the teacher model after the (k+1)th iteration. The newly calculated parameter set is directly assigned to the teacher model, overwriting the original parameters and completing a synchronous update of the teacher model. During the update, the network structure of the teacher model remains unchanged, and only the trainable parameters are replaced to ensure the consistency of the model's inference logic. After the update is completed, the parameters of the teacher model are verified to confirm that there are no missing parameters or abnormal values, ensuring the stability of subsequent pseudo-label generation.

[0061] Step S503: Use the updated teacher-student model as the new base model to form a closed-loop optimization process for model training. Through multiple rounds of closed-loop optimization, continuously improve the defect detection and segmentation performance of the teacher-student model. Specifically, the updated student and teacher models are used as new base models. All steps, including unlabeled subset dual-path inference, pseudo-label selection and memory construction, pseudo-label enhancement and noise removal, model training and synchronous updates, are re-executed to form a complete "inference-pseudo-label optimization-model update" closed loop. Each complete iteration of the entire process is recorded as a closed-loop optimization round. During the iteration, newly extracted feature center vectors are continuously stored in a two-dimensional memory, and the memory data is updated according to the first-in-first-out principle to ensure the timeliness of the memory features. At the same time, the progressively decreasing threshold of pseudo-label selection is dynamically adjusted. During the closed-loop iteration, the parameters of the teacher and student models in each round are retained, and the performance indicators of the models in each round on the validation set are recorded to facilitate the selection of the optimal model and avoid the degradation of model performance due to overfitting in the later stages.

[0062] Step S504: When the model reaches the preset closed-loop optimization convergence condition, terminate the iterative training and output the final optimized student model and teacher model.

[0063] It should be noted that the closed-loop optimization convergence condition is determined by both the convergence of the model's performance index and the saturation of the iteration rounds. The closed-loop optimization will terminate when either condition is met. The convergence of the model performance indicators refers to the fact that, in multiple rounds of closed-loop optimization, the changes in the crossover ratio, detection precision, and detection recall of the student model on the preset validation set are all less than the preset deviation values, indicating that the model's performance has become stable. Specifically, after each round of closed-loop optimization, a preset independent validation set is input into the student model to calculate the three core performance indicators: defect segmentation intersection-union ratio, detection precision, and detection recall. If the change range of the indicators is less than the preset deviation value (e.g., 0.001) for several consecutive rounds (20-30 rounds in industrial scenarios), and the validation set loss value tends to be stable without significant fluctuations, it is determined that the performance indicators have converged.

[0064] Iteration saturation refers to the process where the number of closed-loop optimization iterations of the model reaches the preset maximum number of iterations. Even if the model performance has not reached full convergence, the iteration is terminated to avoid overfitting.

[0065] Pre-set the maximum number of iterations for closed-loop optimization of the model (e.g., 500-1000 iterations, adjusted according to the size of the dataset). If the number of iterations for closed-loop optimization of the model reaches this maximum value, even if the performance index has not fully converged, it is determined that the number of iterations has saturated, and training is terminated immediately to avoid overfitting caused by excessive model iteration.

[0066] This method addresses the problems of high manual annotation costs and low-quality pseudo-labels and coarse feature modeling in traditional weakly supervised schemes for industrial defect detection. It achieves accurate initialization of the teacher-student model using a small amount of labeled data, dynamically balances pseudo-label purity and data utilization through a progressively decreasing threshold, and refines defect feature modeling by combining a dual-dimensional memory for categories and regions with a Gaussian distribution model. Simultaneously, it constructs a contrastive learning loss to enhance the discriminative power of different categories and regions, eliminates noisy pseudo-labels at the source through a three-fold weighting rule, and utilizes an exponential moving average algorithm to achieve stable, interconnected updates and multi-round closed-loop optimization of the teacher-student model. This effectively solves the problems of rigid pseudo-label selection, insufficient feature discriminative power, and unstable model iteration in traditional schemes, significantly improving the detection and segmentation accuracy of minor industrial defects and defects with blurred edges, and significantly reducing the dependence on manually labeled data. This makes the method more adaptable to industrial scenarios and more feasible for engineering implementation. The output optimized model can be stably applied to high-precision detection and segmentation of various industrial surface defects, meeting the practical needs of intelligent manufacturing for automated and precise defect detection.

[0067] The above description is only a preferred embodiment of the present invention. It should be noted that those skilled in the art can make several improvements and modifications without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A progressive pseudo-label optimized method for weakly supervised detection and segmentation of industrial defects, characterized in that, Includes the following steps: Industrial surface defect images are collected and divided into a small number of labeled subsets and a large number of unlabeled subsets. The labeled subsets are used to train the basic network, and the teacher model and student model are initialized simultaneously. The labeled subset is input into the student model for supervised training, and the unlabeled subset is input into both the teacher model and the student model simultaneously. The teacher model outputs initial pseudo-labels, and the student model extracts feature maps. Based on the initial pseudo-labels, a progressively decreasing threshold is used to filter and classify pixel types. Feature centers are extracted by combining feature maps and a memory bank is constructed. A contrastive learning loss is constructed based on the memory bank. A Gaussian distribution model is constructed based on a memory bank. The pixel-level feature assignment probability is calculated by inputting the feature map. The enhanced pseudo-mask is generated by fusing the initial pseudo-labels after screening. The pure pseudo-label is obtained after processing with three rules. Based on pure pseudo-labels, the student model is trained and updated while the teacher model is updated simultaneously. After multiple rounds of closed-loop optimization, the optimized student and teacher models are output.

2. The method for weakly supervised detection and segmentation of industrial defects with progressive pseudo-label optimization according to claim 1, characterized in that, The specific steps for synchronously initializing the teacher and student models are as follows: Collect surface defect images from different industrial scenarios, perform standardized preprocessing, and obtain a unified set of industrial surface defect images; The industrial surface defect image set is divided into an annotated subset and an unannotated subset according to a preset ratio. The annotated subset consists of manually annotated instance-level defect images, which include defect category, detection box and pixel-level mask information. The unannotated subset consists of defect images that have not been manually annotated. The labeled subset is input into the base instance segmentation network for fully supervised pre-training. The network parameters of the base network are updated through backpropagation until the base network reaches the preset convergence condition on the validation set of the labeled subset, and the trained base network is obtained. The parameters of the backbone feature extraction module of the trained basic network are directly transferred to the corresponding modules of the teacher model and the student model. The parameters of the bounding box regression module and the mask generation module of the teacher model and the student model are initialized to complete the synchronous initialization of the teacher model and the student model.

3. The method for weakly supervised detection and segmentation of industrial defects with progressive pseudo-label optimization according to claim 1, characterized in that, The process of inputting the labeled subset into the student model for supervised training is achieved using a weighted combination loss function that combines classification loss, masking loss, and bounding box regression loss. The mathematical formula for this combination loss function is: , in, This represents the total loss value for supervised training of the student model. Cross-entropy classification loss is used to constrain the student model's prediction accuracy for defect categories. The mean squared error mask loss is used to constrain the pixel-level prediction accuracy of the student model for defect instance masks. The L1 bounding box regression loss is used to constrain the accuracy of the student model's coordinate prediction for defect instance detection boxes. The weighting coefficients for the classification loss are... The weighting coefficients for the mask loss are... The weighting coefficients for the box regression loss; The specific steps for inputting the labeled subset into the student model for supervised training are as follows: The labeled subset is used as supervised data input into the student model. The student model outputs defect prediction results. The loss value is calculated by combining the real labeled information with the loss function. The parameters of the student model are updated by backpropagation based on the loss value, thus completing the supervised training of the student model. An unlabeled subset is synchronously input into the supervised-trained student model and the initialized teacher model. The teacher model outputs initial pseudo-labels with pixel-level confidence after forward inference, while the student model outputs high-dimensional backbone feature maps and defect mask prediction results synchronously after complete forward inference.

4. The method for weakly supervised detection and segmentation of industrial defects with progressive pseudo-label optimization according to claim 1, characterized in that, The specific steps for filtering and classifying pixel types using a progressively decreasing threshold are as follows: Using the initial pseudo-labels as input data, and based on the stage characteristics of model iteration, the initial pseudo-labels are filtered layer by layer using a progressively decreasing threshold to select pseudo-label data that meets the confidence requirements and remove invalid pseudo-label data with low confidence. Before filtering, the initial pseudo-labels are divided into different types of pixel regions according to pixel-level confidence features to complete the classification of pixel regions and obtain the classified pixel region mask. The feature map is multiplied by the filtered and classified pixel region mask by a pixel-wise tensor multiplication operation to obtain the weighted feature map of each pixel region. The weighted feature map of each pixel region is then averaged by pooling to obtain the feature center vector of each region. All extracted feature center vectors are classified and stored according to defect category and pixel region type to form a two-dimensional memory library; Based on the completed memory, a contrastive learning loss is constructed using the feature center data in the memory.

5. The method for weakly supervised detection and segmentation of industrial defects with progressive pseudo-label optimization according to claim 1, characterized in that, The specific steps for obtaining pure pseudo-labels after processing with triple rules are as follows: A multidimensional Gaussian distribution model is constructed based on the feature center data stored in the memory bank. The feature map is input into the Gaussian distribution model, and the pixel-level feature assignment probability of each pixel in the feature map is calculated through the Gaussian distribution model to obtain the pixel-level feature assignment probability map. The initial pseudo-labels, after being filtered by progressively decreasing thresholds, are fused with the pixel-level feature attribution probability map at the pixel level, and an enhanced pseudo-mask is generated through feature fusion. The generated enhanced pseudo-masks are subjected to noise removal processing. The enhanced pseudo-masks are judged one by one by a preset three-fold rule. Pseudo-mask data that meets the noise judgment conditions are removed, and valid pseudo-mask data that meets the requirements are retained, finally obtaining clean pseudo-labels.

6. The progressive pseudo-label optimized weakly supervised detection and segmentation method for industrial defects according to claim 5, characterized in that, The three rules are the teacher-student prediction consistency judgment rule, the pseudo-label confidence validity judgment rule, and the feature center distribution rationality judgment rule. The three rules are judged independently. A pseudo-mask that satisfies any one of the rules is judged as a noise pseudo-mask and is removed. The teacher-student prediction consistency judgment rule determines the validity of the pseudo-mask by calculating the overlap between the mask prediction results of the student model and the teacher model for the same unlabeled image. The rule for determining the confidence and validity of the pseudo-label is to determine the overall validity of the pseudo-mask by calculating the overall confidence of the enhanced pseudo-mask. The rule for determining the rationality of the feature center distribution is to calculate the distance between the feature center corresponding to the enhanced pseudo-mask and the feature center of the corresponding category and region unit in the memory, and then determine whether the feature center corresponding to the pseudo-mask conforms to the feature distribution pattern of the memory.

7. The method for weakly supervised detection and segmentation of industrial defects with progressive pseudo-label optimization according to claim 4, characterized in that, The formula for the contrastive learning loss is as follows: , in, To compare the learning loss values, a smaller loss value indicates higher feature similarity within the same category and region, and lower feature similarity between different categories and different regions. The feature center vector to be calculated is any feature center extracted from the memory. For memory bank and The feature center vectors belonging to the same defect category include both simple and difficult defect regions within that category. m represents the total number of corresponding positive sample feature center vectors in the memory, and M represents the total number of feature center vectors in the memory. Negative samples are the feature center vectors of all background regions in the memory, as well as the feature center vectors of all other defect categories. This is a vector similarity calculation function that uses the dot product method to calculate the similarity between two feature center vectors. This is a temperature coefficient used to adjust the discriminative power of feature similarity calculation, making the differences in similarity between features more significant. The contrastive learning loss is calculated independently for each pixel region type. The contrastive learning loss values ​​of each region are weighted and summed to obtain the total contrastive learning loss. The total contrastive learning loss is combined with other loss terms to jointly constrain the training and optimization of the model.

8. The method for weakly supervised detection and segmentation of industrial defects with progressive pseudo-label optimization according to claim 4, characterized in that, The method for setting the progressively decreasing threshold is as follows: The training process is divided into multiple stages based on the model's iteration rounds. A corresponding confidence threshold is set for each training stage. The confidence threshold of each stage gradually decreases as the model's iteration rounds increase, thus achieving a gradual transition of pseudo-labels from high-purity screening to high-utilization screening. The specific operation of threshold filtering is to compare the pixel-level confidence value of the initial pseudo-label with the confidence threshold of the corresponding stage, retain pseudo-label pixels with confidence values ​​greater than the threshold, and remove pseudo-label pixels with confidence values ​​less than or equal to the threshold. The filtered pseudo-labels maintain the same size as the original image.

9. The method for weakly supervised detection and segmentation of industrial defects with progressive pseudo-label optimization according to claim 1, characterized in that, The synchronously updated teacher model is implemented using the exponential moving average algorithm, the mathematical formula of which is as follows: , in, These are the network parameters of the teacher model after the k-th iteration. The network parameters of the teacher model before the k-th iteration are... These are the network parameters of the student model after training and updating with pure pseudo-labels in the k-th iteration. It is the exponential moving average coefficient, used to balance the weight ratio of the original parameters of the teacher model and the updated parameters of the student model; The specific steps for training and updating the student model while simultaneously updating the teacher model are as follows: Pure pseudo-labels are used as supervised data input into the supervised training student model. The student model is then trained end-to-end iteratively. The network parameters of the student model are updated through backpropagation to obtain the student model with updated parameters. Based on the exponential moving average algorithm, the network parameters of the teacher model are synchronously updated using the updated network parameters of the student model to obtain the updated teacher model. The updated teacher-student model is used as the new base model to form a closed-loop optimization process for model training. Through multiple rounds of closed-loop optimization, the defect detection and segmentation performance of the teacher-student model is continuously improved. When the model reaches the preset closed-loop optimization convergence condition, the iterative training terminates, and the final optimized student model and teacher model are output.

10. A progressive pseudo-label optimized method for weakly supervised detection and segmentation of industrial defects, as described in claim 9, is characterized in that... The closed-loop optimization convergence condition is determined by both the convergence of the model's performance index and the saturation of the iteration rounds. The closed-loop optimization is terminated when either condition is met. The convergence of the model performance indicators refers to the fact that, in multiple rounds of closed-loop optimization, the changes in the crossover ratio, detection precision, and detection recall of the student model on the preset validation set are all less than the preset deviation values, indicating that the model's performance has become stable. The iteration saturation refers to the process where the number of closed-loop optimization iterations of the model reaches the preset maximum number of iterations. Even if the model performance has not reached full convergence, the iteration is terminated to avoid model overfitting.