Small sample defect detection method based on class awareness prototype migration

By employing a small-sample defect detection method based on class-aware prototype transfer, and utilizing iterative optimization of student and teacher networks and pseudo-label scoring, the problem of cross-category transfer and missed detection of minor defects in industrial product defect detection is solved, achieving high-precision and real-time detection while reducing annotation costs.

CN121616602AActive Publication Date: 2026-03-06湖南工商大学
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202610149078.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-03
Publication Date
2026-03-06
Estimated Expiration
2046-02-03

AI Technical Summary

Technical Problem

Existing industrial product defect detection methods suffer from weak cross-category transferability in small sample defect detection, high missed detection rate of minute defects in complex backgrounds, and error propagation and overfitting problems caused by traditional pseudo-labeling technology.

Method used

A few-sample defect detection method based on class-aware prototype transfer is adopted. Through iterative optimization of student and teacher networks, using labeled and unlabeled datasets, the comprehensive credibility score of pseudo-labels is calculated to optimize the loss function. Combined with adaptive threshold and exponential moving average mechanism, the network parameters are updated to achieve high-precision defect detection.

Benefits of technology

While reducing annotation costs, it achieves high-precision, high-speed and strong generalization capabilities for industrial defect detection, applicable to cross-material and cross-workpiece scenarios, and has real-time detection capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121616602A_ABST
    Figure CN121616602A_ABST
Patent Text Reader

Abstract

The invention relates to a small sample defect detection method based on class awareness prototype migration, and the method comprises the steps: inputting a labeled image into a student network comprising a first CAM module, and outputting a corresponding first prediction result and first features corresponding to various truth value labels extracted by the first CAM module; calculating a first loss function based on the first prediction result to preliminarily optimize the student network, and updating prototypes of various truth value labels based on the first feature; inputting the label-free image into a teacher network comprising a second CAM module, calculating a comprehensive credibility score of a pseudo label based on a second feature output by the teacher network, a second prediction result and the updated prototype, and calculating a second loss function based on the comprehensive credibility score to secondarily optimize the student network; network parameters of the teacher network are updated based on the network parameters of the student network after secondary optimization; and the industrial product image to be detected is subjected to iterative optimization through the teacher network to obtain a final defect detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of industrial product defect detection technology, and in particular to a small-sample defect detection method based on class-aware prototype transfer. Background Technology

[0002] Existing industrial product defect detection methods face the following challenges in detecting defects in small samples: 1. The model has weak cross-category transfer ability, and semantic drift will occur when the model is transferred to heterogeneous materials or new workpieces; 2. High rate of missed detection of minute defects in complex industrial settings; 3. Traditional pseudo-labeling technology may lead to error propagation and overfitting problems due to improper threshold settings. Summary of the Invention

[0003] Therefore, it is necessary to provide a small-sample defect detection method based on class-aware prototype transfer, including: S1: Obtain a set of industrial product images for training, which includes an unlabeled dataset and a labeled dataset; S2: Input the labeled images in the labeled dataset into the student network containing the first CAM module, output the corresponding first prediction result and the first features corresponding to various ground truth labels extracted by the first CAM module; calculate the first loss function based on the ground truth labels of the labeled images and the first prediction result to preliminarily optimize the student network, and update the prototype of various ground truth labels based on the first features corresponding to various ground truth labels. S3: Input the unlabeled images in the unlabeled dataset into the teacher network containing the second CAM module, and output the corresponding second prediction result and the second features of each unlabeled image extracted by the second CAM module; calculate the comprehensive credibility score of the pseudo-label based on the second features, the updated prototype and the second prediction result; calculate the second loss function based on the comprehensive credibility score of the pseudo-label to optimize the student network for a second time; update the network parameters of the teacher network based on the network parameters of the student network after the second optimization. S4: Iterate through steps S2-S3 until the maximum preset number of rounds is reached to obtain the optimized teacher network; pass the image of the industrial product to be detected through the optimized teacher network to obtain the final defect detection result.

[0004] Preferably, a YOLOv8 model pre-trained on the ImageNet dataset is used as the backbone network of the teacher network or the student network, and the C2f module in the YOLOv8 model is replaced with a first CAM module or a second CAM module to obtain the teacher network or the student network.

[0005] Preferably, the first prediction result includes a bounding box, a first category confidence score, and an object confidence score; a classification loss is calculated based on the first category confidence score and the ground truth label, a regression loss is calculated based on the bounding box, and a confidence loss is calculated based on the object confidence score; the classification loss, the regression loss, and the confidence loss are added together to obtain the first loss function; based on the first loss function, the network parameters of the student network are initially updated using a backpropagation algorithm.

[0006] Preferably, the method further includes pre-training the teacher network based on labeled images in the labeled dataset. The pre-trained teacher network outputs the second features corresponding to each type of ground truth label based on the labeled images, and calculates the mean of the second features corresponding to each type of ground truth label as the initial value of the prototype of the corresponding ground truth label.

[0007] Preferably, the prototype of the corresponding truth label is updated based on the first feature corresponding to the truth label, and the calculation formula is: ; in, This represents the prototype of the truth label of class c at the t-th iteration. This represents the momentum coefficient for prototype updates. This represents the prototype of the truth label of class c in the (t-1)th iteration. Let represent the set of labeled images that belong to the c-th truth label class at the t-th iteration. Describing the L1 norm, Represents a set Image with label The corresponding first feature.

[0008] Preferably, the comprehensive credibility score of the pseudo-label is calculated based on the second feature, the updated prototype, and the second prediction result, including: The second prediction result includes the prediction box and the second category confidence score for the pseudo-label; The predicted bounding boxes are filtered. For any filtered predicted bounding box, the cosine similarity between the predicted bounding box and the prototype is calculated based on the second feature of the corresponding unlabeled image and the ground value label corresponding to the pseudo label. The cosine similarity is normalized, and the second category confidence score is weighted and summed with the corresponding normalized cosine similarity to obtain the comprehensive credibility score of the pseudo-label.

[0009] Preferably, the second loss function is calculated based on the comprehensive credibility score of pseudo-labels to optimize the student network for a secondary purpose, including: Calculate the first average confidence level of the corresponding truth label based on the confidence level of each first category corresponding to any one type of truth label; Calculate the second average confidence level of the corresponding true value label based on the confidence levels of each second category corresponding to the same true value label; The standard deviation is calculated based on the second average confidence level, and the confidence difference of the corresponding true value labels is calculated based on the first average confidence level and the second average confidence level. The adaptive low threshold and adaptive high threshold are calculated based on the confidence difference and standard deviation of the corresponding truth labels, respectively, and the calculation formulas are as follows: ; ; ; in, This represents the adaptive high threshold for the truth label of class c. This represents the adaptive low threshold for the truth label of class c. This refers to the clip function. This represents the first average confidence level of the truth labels for class c. This represents the second average confidence level of the truth labels for class c. Indicates the first hyperparameter. This represents the second hyperparameter. This represents the third hyperparameter. This represents the difference in confidence level between the truth labels of class c. This represents the standard deviation of the second average confidence level of the true value labels for class c. Indicates the lower boundary of the threshold. Indicates the upper boundary of the threshold; The confidence interval of the pseudo-label is determined by comparing the overall confidence score with the adaptive low threshold and the adaptive high threshold. The corresponding distillation loss is selected based on the confidence interval of each pseudo-label, and the second loss function is calculated based on each distillation loss and the first loss function. Based on the second loss function, the network parameters of the initially optimized student network are updated a second time using the backpropagation algorithm.

[0010] Preferably, the process of constructing the second loss function includes: When the overall credibility score of the pseudo-label is greater than or equal to the adaptive high threshold, the sum of the second classification loss, the second regression loss and the second confidence loss during the teacher network pre-training is used as the distillation loss. When the overall credibility score of the pseudo-label is between the adaptive low threshold and the adaptive high threshold, the second regression loss or the second confidence loss during the pre-training of the teacher network is used as the distillation loss. When the overall credibility score of the pseudo-label is less than or equal to the adaptive low threshold, a background penalty is constructed as the distillation loss. Based on the distillation loss of the pseudo-labels corresponding to all unlabeled images, the semi-supervised loss is calculated as follows: ; in, Indicates semi-supervised loss. This represents an unlabeled dataset. Represents unlabeled images The corresponding partition weights, Represents unlabeled images Corresponding distillation losses; The second loss function is calculated based on the semi-supervised loss and the first loss function, and the formula is as follows: ; in, This represents the second loss function. Denotes the first loss function. This represents the weight of the semi-supervised loss.

[0011] Preferably, updating the network parameters of the teacher network based on the network parameters after secondary optimization of the student network includes: An exponential moving average mechanism is used to update the network parameters of the teacher network based on the network parameters of the student network after secondary optimization.

[0012] Preferably, the defect detection results include defect category, defect location, and confidence level.

[0013] Beneficial effects: This method inputs labeled images into a student network containing a first CAM module, outputting the corresponding first prediction result and the first features corresponding to various ground truth labels extracted by the first CAM module; it then calculates a first loss function based on the first prediction result to initially optimize the student network, and updates the prototypes of various ground truth labels based on the first features; it inputs unlabeled images into a teacher network containing a second CAM module, calculates the comprehensive credibility score of pseudo-labels based on the second features output by the teacher network, the second prediction result, and the updated prototypes, and then calculates a second loss function based on the comprehensive credibility score to further optimize the student network; it updates the network parameters of the teacher network based on the network parameters after the secondary optimization of the student network; and iteratively optimizes the teacher network through the teacher network to obtain the final defect detection result. This method can make full use of a small amount of labeled data and a large amount of unlabeled data, significantly reducing labeling costs while achieving high-precision, high-speed, and strong generalization ability industrial defect detection. Attached Figure Description

[0014] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0015] Figure 1 This is a flowchart of a small-sample defect detection method based on class-aware prototype transfer in an embodiment of this application. Detailed Implementation

[0016] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the specific embodiments of this application are described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of this application. Therefore, this application is not limited to the specific embodiments disclosed below.

[0017] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0018] like Figure 1 As shown, this embodiment provides a small-sample defect detection method based on class-aware prototype transfer, including: S1: Obtain a set of industrial product images for training, which includes an unlabeled dataset and a labeled dataset.

[0019] The ratio of the labeled dataset to the unlabeled dataset is 1:1.

[0020] In this embodiment, the industrial product image set used for training is the PKU-Market-PCB dataset, which contains six typical PCB defects (short circuit, open circuit, excess copper, via, burr, and scratch). All images in the dataset are uniformly adjusted to 640×640 pixels before use.

[0021] S2: Input the labeled images in the labeled dataset into the student network containing the first CAM module, output the corresponding first prediction result and the first features corresponding to the ground truth labels extracted by the first CAM module; calculate the first loss function based on the ground truth labels of the labeled images and the first prediction result to initially optimize the student network, and update the prototype of each ground truth label based on the first features corresponding to each ground truth label.

[0022] Specifically, the first prediction result includes a bounding box, a first class confidence score, and an object confidence score. A classification loss is calculated based on the first class confidence score and the ground truth label; a regression loss is calculated based on the bounding box; and a confidence loss is calculated based on the object confidence score. The classification loss (e.g., Focal Loss, used to address class imbalance), the regression loss (e.g., CIoULoss, used to accurately locate the bounding box), and the confidence loss (e.g., binary cross-entropy loss, used to determine if there is an object within the box) are added together to obtain the first loss function. Based on the first loss function, the network parameters of the student network are initially updated using a backpropagation algorithm.

[0023] In this embodiment, the teacher network is pre-trained based on labeled images in the labeled dataset. The pre-trained teacher network outputs the second features corresponding to each type of ground truth label based on the labeled images, and calculates the mean of the second features corresponding to each type of ground truth label as the initial value of the prototype of the corresponding ground truth label.

[0024] Furthermore, the pre-training process of the teacher network is as follows: a small number of labeled images from the labeled dataset are used to conduct supervised training on the teacher network, and the initial network parameters of the teacher network are optimized by minimizing the pre-training loss function; the pre-training loss function includes: second classification loss (such as Focal Loss), second regression loss (such as CIoU Loss), and second confidence loss (such as binary cross-entropy loss).

[0025] Furthermore, the initial value of the truth label prototype is calculated as follows: ; in, This represents the initial value of the prototype of the truth label of class c. This represents the set of labeled images corresponding to the c-th class ground truth label in the labeled dataset. Represents a set The i-th labeled image The corresponding second feature, Indicates the modulus.

[0026] Optionally, the prototype of the corresponding truth label is updated based on the first feature corresponding to the truth label, calculated as follows: ; in, This represents the prototype of the truth label of class c at the t-th iteration. This represents the momentum coefficient for prototype updates. , This represents the prototype of the truth label of class c in the (t-1)th iteration. Let represent the set of labeled images that belong to the c-th truth label class at the t-th iteration. Describing the L1 norm, Represents a set Image with label The corresponding first feature. If the set in the current iteration When empty, The original remains unchanged.

[0027] S3: Input the unlabeled images in the unlabeled dataset into the teacher network containing the second CAM module, and output the corresponding second prediction result and the second features of each unlabeled image extracted by the second CAM module; calculate the comprehensive credibility score of the pseudo-label based on the second features, the updated prototype and the second prediction result; calculate the second loss function based on the comprehensive credibility score of the pseudo-label to optimize the student network for a second time; update the network parameters of the teacher network based on the network parameters of the student network after the second optimization.

[0028] In this embodiment, a YOLOv8 model pre-trained on the ImageNet dataset is used as the backbone network of the teacher network or the student network. The C2f module in the YOLOv8 model is replaced with the first CAM module or the second CAM module to obtain the teacher network or the student network.

[0029] Furthermore, the first CAM module and the second CAM module have the same structure and workflow. The input to the CAM module is a feature map. C represents the number of channels, H represents the height of the image, and W represents the width of the image; Output: Enhanced feature map ; Its internal processing flow is as follows: 1. Convolutional branch (the cornerstone of local feature extraction); Objective: To capture local details and spatial information of features.

[0030] Operation: F conv =SiLU(BatchNorm(Conv k1×k1 (F))); Among them, F conv This represents convolutional features, SiLU(·) represents the SiLU function, and BatchNorm(·) represents batch normalization. It is usually a 1x1 or 3x3 convolution.

[0031] 2. Attention feature branch (global dependency modeling); Objective: To model the global channel and spatial dependencies of features. Channel attention must be performed first, followed by spatial attention.

[0032] a. Channel Attention Submodule: ; ; ; ; ; in, Represents the global max pooling feature of the channel. This represents the global average pooling characteristic of the channel. Indicates global max pooling. Indicates global average pooling. Indicates attention, This represents a multilayer perceptron. This represents the sigmoid function. Indicates channel attention. This indicates element-wise multiplication. This indicates the characteristics of channel fusion.

[0033] b. Spatial Attention Submodule: ; ; ; ; ; in, Represents the global max pooling feature in space. This represents the spatial global average pooling feature. Indicates splicing characteristics, , This represents a 7×7 convolution. This represents the sigmoid function. Indicates spatial attention. This indicates element-wise multiplication. Indicates spatial integration characteristics, This indicates that max pooling is performed along the channel dimension to highlight the most salient features of each spatial location across all channels. This indicates that average pooling is performed along the channel dimension to capture the average feature of each spatial location across all channels.

[0034] c. Multi-scale enhancement mechanism (linked with category information): (1). Scale Attention Weight Matrix (SAAM): Input: Original features F and class prediction vectors from the network's classifier head .

[0035] Calculate the weights of each scale s: ; Multi-scale convolution: ; in, The weights of scale s are represented. The weighting coefficients for scale s are represented. The weighting coefficients representing scale s' are... Represents multi-scale convolutional features. Indicates the use of size Convolution operations are performed using convolution kernels, with different scales s corresponding to different... , The value can be 1, 3, 5, etc., to capture features at different scales.

[0036] (2). Dynamic Category Adaptation (DCA): Core inputs: raw features F and prototype vectors of various truth labels maintained by the class-aware prototype EMA module. .

[0037] calculate: Similarity chart: ; Category-enhanced fusion: ; in, This represents the similarity between the feature map F and the prototype vector. This indicates element-wise multiplication. This indicates a category-enhanced feature.

[0038] (3). Sparse attentional inhibition (SIA): Function: As a regularization loss, it facilitates attention graph processing. and The sparsity and uniformity of the data help prevent overfitting of background noise.

[0039] formula: ;in, Describing the L1 norm, Represents variance. Indicates the suppression weight coefficient; integrated: As an additional term added to the total loss function, the weights The recommended value is 0.0001.

[0040] d. Final Fusion: Combine the outputs of all the above branches using element-wise addition: F CAM =F conv +F att +F scale +F DCA ; It will serve as a feature input for subsequent processes, and its quality directly determines the performance of the entire system.

[0041] Specifically, the comprehensive credibility score of the pseudo-label is calculated based on the second feature, the updated prototype, and the second prediction result, including: The second prediction result includes the prediction box and the second category confidence score for the pseudo-label; The predicted bounding boxes are filtered, for example using Gaussian weighting, to provide a cleaner and more accurate candidate set; specifically: ;in, This represents the score of the i-th predicted box after the update. This represents the score of the i-th prediction box. Indicates the attenuation parameter. Represents the IoU function. The prediction box that represents the current highest score. This represents the i-th prediction box to be suppressed, when A value greater than or equal to the intersection-union ratio (IU) threshold indicates high overlap, with a small exponent value (close to 0), thus significantly reducing the score. When the value is less than the intersection-union ratio threshold, it indicates low overlap, the value of the exponent term is relatively large (close to 1), and the score remains basically unchanged. Optionally, the screening process includes: Step 1: Sort all prediction boxes in descending order of score; Step 2: Select the prediction box with the highest score And iterate through other prediction boxes to be suppressed. ; Step 3: For each Calculate its relationship with the IoU function The intersection-union ratio is calculated, and the corresponding score is updated based on the Gaussian weighted formula; Step 4: Repeat steps 2-3 until all prediction boxes have been processed. Compare the scores of all processed prediction boxes with a preset score threshold (e.g., 0.01). Filter out prediction boxes with scores lower than the preset score threshold to obtain the filtered prediction boxes.

[0042] By continuously reducing the scores of overlapping boxes, soft suppression of dense detection boxes is achieved, while retaining some potentially effective predicted boxes with reduced scores, thus improving the recall rate of detection.

[0043] For any filtered predicted bounding box, based on the second feature of the corresponding unlabeled image and the ground truth label corresponding to the pseudo label, the cosine similarity between the predicted bounding box and the prototype is calculated as follows: ; in, Represents unlabeled labeled images The obtained prediction box and the first Cosine similarity between prototypes after truth label updates. Represents unlabeled images The corresponding second feature, Indicates the first The prototype after the truth value label is updated. Represents the L2 norm; The cosine similarity is normalized, and the second category confidence score is weighted and summed with the corresponding normalized cosine similarity to obtain the comprehensive credibility score of the pseudo-label. The calculation formula is as follows: ; ; in, The overall credibility score of pseudo-labels. , These represent the first weighting coefficient and the second weighting coefficient, respectively. Normalization , Indicates the first The second category confidence level of the truth label.

[0044] Furthermore, a second loss function is calculated based on the comprehensive credibility score of pseudo-labels to optimize the student network for a secondary purpose, including: Calculate the first average confidence level of the corresponding truth label based on the confidence level of each first category corresponding to any one type of truth label; Calculate the second average confidence level of the corresponding true value label based on the confidence levels of each second category corresponding to the same true value label; The standard deviation is calculated based on the second average confidence level, and the confidence difference of the corresponding true value labels is calculated based on the first average confidence level and the second average confidence level. The adaptive low threshold and adaptive high threshold are calculated based on the confidence difference and standard deviation of the corresponding truth labels, respectively, and the calculation formulas are as follows: ; ; ; in, This represents the adaptive high threshold for the truth label of class c. This represents the adaptive low threshold for the truth label of class c. This refers to the clip function. This represents the first average confidence level of the truth labels for class c. This represents the second average confidence level of the truth labels for class c. Indicates the first hyperparameter. This represents the second hyperparameter. This represents the third hyperparameter. This represents the difference in confidence level between the truth labels of class c. This represents the standard deviation of the second average confidence level of the true value labels for class c. Indicates the lower boundary of the threshold. Indicates the upper boundary of the threshold; The confidence interval of the pseudo-label is determined by comparing the overall confidence score with the adaptive low threshold and the adaptive high threshold. The corresponding distillation loss is selected based on the confidence interval of each pseudo-label, and the second loss function is calculated based on each distillation loss and the first loss function. Based on the second loss function, the network parameters of the initially optimized student network are updated a second time using the backpropagation algorithm.

[0045] Furthermore, the process of constructing the second loss function includes: In the high confidence interval, when the overall confidence score of the pseudo-label is greater than or equal to the adaptive high threshold, the sum of the second classification loss, the second regression loss, and the second confidence loss during the teacher network pre-training is used as the distillation loss. In the medium confidence interval, when the overall confidence score of the pseudo-label is between the adaptive low threshold and the adaptive high threshold, the second regression loss or the second confidence loss during the pre-training of the teacher network is used as the distillation loss. In the low-confidence interval, when the overall credibility score of the pseudo-label is less than or equal to the adaptive low threshold, the pseudo-label is determined to be background, and a background penalty is constructed as the distillation loss; the expression for the distillation loss is: ; in, Represents unlabeled images The corresponding distillation loss, This represents the third category loss (e.g., Focal Loss). This indicates the student network's response to unlabeled images. The predicted probability of the category. Indicates the background category (usually corresponding to category index 0). This represents the distillation weighting coefficient. This represents the third confidence level loss (such as binary cross-entropy loss). This indicates the student network's response to unlabeled images. The prediction confidence level This represents the target value without objects; distillation loss can be achieved using only the third-class loss. Based on the distillation loss of the pseudo-labels corresponding to all unlabeled images, the semi-supervised loss is calculated as follows: ; in, Indicates semi-supervised loss. This represents an unlabeled dataset. Represents unlabeled images Corresponding partition weights (high confidence intervals) Distillation loss is a positive loss term; medium confidence interval. Low confidence interval Distillation loss is not effective. When the distillation loss is negative, the network parameters will be updated in reverse. Represents unlabeled images The corresponding distillation loss, in this embodiment, tends to treat the pseudo-label as background and apply a positive loss term; The second loss function is calculated based on the semi-supervised loss and the first loss function, and the formula is as follows: ; in, This represents the second loss function. Denotes the first loss function. This represents the weight of the semi-supervised loss.

[0046] In this embodiment, updating the network parameters of the teacher network based on the network parameters after secondary optimization of the student network includes: The network parameters of the teacher network are updated using an exponential moving average mechanism based on the network parameters of the student network after secondary optimization. The update formula is as follows: ; in, This represents the network parameters of the teacher network at the (t+1)th iteration. This represents the network parameters of the teacher network at the t-th iteration. This represents the network parameters of the student network after secondary optimization in the t-th iteration. This represents the second momentum coefficient, which is usually close to 1 (e.g., 0.996, which can be adjusted from 0.996 to 1.0 using cosine tuning).

[0047] Optionally, for both labeled and unlabeled images, a dual-path data augmentation mechanism can be used to expand the decision boundary between normal and abnormal samples in the feature space.

[0048] Teacher network path (weak enhancement): Apply basic geometric transformations (such as random horizontal flip, p=0.5) and slight color jitter to the input image to maintain the stability of feature prediction.

[0049] Student network path (strong enhancement): applies a more drastic combination of transformations to the input image, including: ColorJitter: Adjust brightness, contrast, saturation, and hue within a range of 0.4.

[0050] RandomGrayscale: Converts to grayscale with a probability of 0.2.

[0051] RandomAffine: Random rotation (±10 degrees), shearing (±5 degrees).

[0052] Cutout: Randomly occludes a rectangular area with a maximum side length of 20%.

[0053] S4: Iterate through steps S2-S3 until the maximum preset number of rounds is reached to obtain the optimized teacher network; pass the optimized teacher network through the industrial product image to be detected to obtain the final defect detection result, including defect category, defect location and confidence level.

[0054] Specifically, after training, only the optimized teacher network is used for defect detection inference.

[0055] 1. Input: The image to be detected is weakly enhanced (or directly scaled) to a uniform size (e.g., 640x640 pixels).

[0056] 2. Forward propagation: The image is input into the teacher network, passes through the backbone network containing the CAM module and the detection head, and the prediction result is obtained.

[0057] 3. Post-processing: Use standard NMS (not Soft-NMS) to filter the predicted bounding boxes and output the final defect category, location, and confidence level.

[0058] Deployment: Because it is based on the efficient YOLOv8 architecture and has been optimized, the model is small in size and fast, and can be directly deployed on edge computing devices or servers in the factory to achieve real-time quality inspection.

[0059] Optionally, to prevent the accumulation of erroneous labels and improve training stability, an iterative error label tracing process is performed, including: For each sample that is judged as an "erroneous label" (i.e., the overall credibility score of the pseudo-label is less than or equal to the adaptive low threshold), its defect feature vector is extracted, stored in the "dynamic error feature library", and the iteration round is marked.

[0060] After generating pseudo-labels in the next round, calculate the cosine similarity between the second feature and the features in the database. If the similarity... Even if its confidence level is slightly higher than the adaptive low threshold, it is still forcibly classified as an "incorrect label" and discarded.

[0061] Clean up the "Dynamic Error Feature Library" regularly (e.g., every 100 rounds) and delete old features that have been marked for more than 50 rounds and have not reappeared.

[0062] Optionally, the method can also perform general object detection based on images from the COCO2017 data.

[0063] The small-sample defect detection method based on class-aware prototype transfer provided in this embodiment has the following beneficial effects: 1. High detection accuracy and strong generalization: By stabilizing the feature space through prototypes of ground truth labels and refining the use of unlabeled data through adaptive thresholding, the model achieves leading detection accuracy (mAP) on datasets such as COCO2017 and PCB, especially performing well in cross-material and cross-workpiece scenarios.

[0064] 2. High training efficiency and stability: The teacher-student network is updated smoothly through EMA (exponential moving average) and combined with a dynamic threshold strategy to accelerate model convergence, suppress training oscillations, and make the training process more stable.

[0065] 3. Low annotation cost: This semi-supervised framework only requires a small amount of labeled data (such as 5% or 10%) to achieve performance close to that of fully supervised learning, which greatly reduces the annotation cost of industrial quality inspection.

[0066] 4. Real-time detection capability: Based on an optimized single-stage detector, the number of model parameters and computational load are effectively controlled, meeting the needs of real-time detection in industrial settings.

[0067] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0068] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A small sample defect detection method based on class perception prototype migration, characterized in that, The method comprises the following steps: S1: obtaining an industrial product image set for training, the industrial product image set comprising an unlabeled data set and a labeled data set; S2: inputting a labeled image in the labeled data set into a student network comprising a first CAM module, outputting a corresponding first prediction result and first features corresponding to each true value label extracted by the first CAM module, and preliminarily optimizing the student network based on a true value label of the labeled image and the first prediction result, and updating a prototype of each true value label based on the first features corresponding to each true value label; S3: inputting an unlabeled image in the unlabeled data set into a teacher network comprising a second CAM module, outputting a corresponding second prediction result and second features of each unlabeled image extracted by the second CAM module, calculating a comprehensive confidence score of a pseudo label based on the second features, the updated prototype and the second prediction result, and secondarily optimizing the student network based on a second loss function calculated based on the comprehensive confidence score of the pseudo label, and updating network parameters of the teacher network based on network parameters of the student network after secondary optimization; S4: iterating steps S2-S3 until a maximum preset round is reached, and obtaining an optimized teacher network; and obtaining a final defect detection result by passing an industrial product image to be detected through the optimized teacher network. A YOLOv8 model pre-trained on an ImageNet data set is used as a backbone network of the teacher network or the student network, and a C2f module in the YOLOv8 model is replaced by the first CAM module or the second CAM module to obtain the teacher network or the student network.

2. The small sample defect detection method of claim 1, wherein, The first prediction result comprises a bounding box, a first class confidence and an object confidence; a classification loss is calculated based on the first class confidence and the true value label, a regression loss is calculated based on the bounding box, and a confidence loss is calculated based on the object confidence; the first loss function is obtained by adding the classification loss, the regression loss and the confidence loss; and the network parameters of the student network are preliminarily updated based on the first loss function and through a back propagation algorithm.

3. The small sample defect detection method of claim 1, wherein, The method further comprises pre-training the teacher network based on the labeled images in the labeled data set; the pre-trained teacher network outputs second features corresponding to each true value label based on the labeled images, and calculates a mean value of the second features corresponding to each true value label as an initial value of the prototype of the corresponding true value label.

4. The small sample defect detection method of claim 3, wherein, The prototype of the corresponding true value label is updated based on the first features corresponding to the true value label, and the calculation formula is:

5. The small sample defect detection method of claim 1, wherein The comprehensive confidence score of the pseudo label is calculated based on the second features, the updated prototype and the second prediction result, and comprises: ; in, This represents the prototype of the truth label of class c at the t-th iteration. This represents the momentum coefficient for prototype updates. This represents the prototype of the truth label of class c in the (t-1)th iteration. Let represent the set of labeled images that belong to the c-th truth label class at the t-th iteration. Describing the L1 norm, Represents a set Image with label The corresponding first feature.

6. The small sample defect detection method of claim 4, wherein, The second prediction result comprises a prediction box and a second class confidence of the pseudo label; The prediction box is screened, and for any screened prediction box, a cosine similarity between the prediction box and the updated prototype of the true value label corresponding to the pseudo label is calculated based on the second features of the corresponding unlabeled image and the updated prototype; The cosine similarity is normalized, and the second class confidence and the corresponding normalized cosine similarity are weighted and summed to obtain the comprehensive confidence score of the pseudo label. ​ 7. The small sample defect detection method of claim 6, wherein, The second loss function is calculated based on the comprehensive confidence score of the pseudo label to secondarily optimize the student network, including: The first average confidence of the corresponding true value label is calculated based on each first-class confidence corresponding to any one true value label; The second average confidence of the corresponding true value label is calculated based on each second-class confidence corresponding to the same true value label; The standard deviation is calculated based on the second average confidence, and the confidence difference of the corresponding true value label is calculated based on the first average confidence and the second average confidence; The adaptive low threshold and the adaptive high threshold are calculated based on the confidence difference and the standard deviation of the corresponding true value label, and the calculation formulae are: ; ; ; wherein, denotes an adaptive high threshold for the c-th true label, denotes an adaptive low threshold for the c-th true label, denotes a clip function, denotes a first average confidence for the c-th true label, denotes a second average confidence for the c-th true label, denotes a first hyperparameter, denotes a second hyperparameter, denotes a third hyperparameter, denotes a confidence difference for the c-th true label, denotes a standard deviation of the second average confidence for the c-th true label, denotes a threshold lower bound, denotes a threshold upper bound; The confidence interval of the pseudo label is determined by comparing the comprehensive confidence score with the adaptive low threshold and the adaptive high threshold; The corresponding distillation loss of each pseudo label is selected based on the confidence interval, and the second loss function is calculated based on each distillation loss and the first loss function; The network parameters of the initially optimized student network are secondarily updated based on the second loss function and through the back propagation algorithm.

8. The small sample defect detection method of claim 7, wherein, The process of constructing the second loss function includes: When the comprehensive confidence score of the pseudo label is greater than or equal to the adaptive high threshold, the sum of the second classification loss, the second regression loss and the second confidence loss during the pre-training of the teacher network is used as the distillation loss; When the comprehensive confidence score of the pseudo label is between the adaptive low threshold and the adaptive high threshold, the second regression loss or the second confidence loss during the pre-training of the teacher network is used as the distillation loss; When the comprehensive confidence score of the pseudo label is less than or equal to the adaptive low threshold, the background penalty is constructed as the distillation loss; The semi-supervised loss is calculated based on the distillation loss of the pseudo label corresponding to all unlabeled images, and the calculation formula is: ; wherein, denotes the semi-supervised loss, denotes the unlabeled dataset, denotes the unlabeled image the corresponding partition weight, denotes the unlabeled image the corresponding distillation loss; The second loss function is calculated based on the semi-supervised loss and the first loss function, and the calculation formula is: ; wherein, represents a second loss function, represents a first loss function, represents a semi-supervised loss weight.

9. The small sample defect detection method of claim 1, wherein, The network parameters of the teacher network are updated based on the secondarily optimized network parameters of the student network, including: The network parameters of the teacher network are updated based on the secondarily optimized network parameters of the student network by using the exponential moving average mechanism.

10. The small sample defect detection method of claim 1, wherein, The defect detection result includes a defect category, a defect position and a confidence.

Citation Information

Patent Citations

  • Passive field adaptive target detection model generation method based on class prototype alignment and target detection method

    CN120147606A

  • Semi-supervised remote sensing target detection method and system based on spatial resolution guidance, medium and equipment

    CN121010889A

  • Semi-supervised target detection method and device based on active label selection and global consistency loss

    CN121147724A

  • Multi-domain object detection method and apparatus

    US20250245954A1