Defect sample screening method
By calculating the model ensemble difference and prediction entropy of unlabeled defect samples, samples that are difficult for the model to identify are screened out for labeling, which solves the problem of large labeling volume and low efficiency in industrial visual inspection, and achieves efficient defect sample screening and model performance optimization.
Patent Information
- Application Number
- CN202611192365.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-07
- Publication Date
- 2026-11-27
AI Technical Summary
In industrial visual inspection, existing technologies require pixel-level contour annotation for each defect instance image, resulting in a huge amount of annotation work and low efficiency. This is especially true in the inspection of semiconductor wafers, LED chips for display panels, and new energy power battery cells, where defect shapes are diverse, backgrounds are complex, and manual annotation takes a long time.
By calculating the model ensemble difference and prediction entropy of unlabeled defect samples, the uncertainty score of each unlabeled defect sample is quantified, and samples that are difficult for the model to identify are selected for labeling. By combining dynamic thresholds and historical samples, the labeling strategy is optimized to reduce the amount of labeling.
It effectively reduces the amount of labeled defective samples, takes into account the performance of deep learning models, and improves labeling efficiency and model detection accuracy.
Smart Images

Figure CN123181306A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of industrial visual inspection technology, and in particular to a defect sample screening method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Technology
[0002] Industrial visual inspection is a core component of quality control in modern intelligent manufacturing. With the continuous development of high-end manufacturing technologies, the requirements for defect detection in the production process are constantly increasing. Defects in semiconductor wafers, LED chips in display panels, and microcracks and flaws in new energy power battery cells are showing characteristics of developing towards the micro-nano scale and diversifying the types of defects. At the same time, the inspection environment and background are also becoming more complex and changeable with the evolution of production processes.
[0003] Industrial defect detection methods based on deep learning instance segmentation technology, such as YOLOv8-seg and Mask R-CNN, provide a technical path for upgrading industrial defect detection from "coarse-grained localization" to "pixel-level analysis". They can output precise pixel-level masks of defects and extract the true contours of defects, which is crucial for judging the type and severity of defects.
[0004] However, instance segmentation tasks require pixel-level contour annotation for each defect instance image. In industrial scenarios, defects have diverse shapes and complex backgrounds. Manual annotation of a single defect instance image is time-consuming, and annotating all defect instance images would result in an enormous amount of annotation work. Summary of the Invention
[0005] Therefore, it is necessary to provide a method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can reduce the amount of labeling required for defect sample screening, in response to the above-mentioned technical problems.
[0006] In a first aspect, this application provides a defect sample screening method, the method comprising:
[0007] Obtain an unlabeled defect sample pool, wherein the unlabeled defect sample pool includes multiple unlabeled defect samples;
[0008] For each unlabeled defect sample, calculate the model ensemble difference and prediction entropy corresponding to the unlabeled defect sample, and calculate the first uncertainty score corresponding to each unlabeled defect sample in the current round based on the model ensemble difference and the prediction entropy; wherein, the model ensemble difference indicates the degree of inconsistency between the prediction results of multiple independent deep learning models for the same input unlabeled defect sample; the prediction entropy indicates the information entropy of the average prediction probability distribution of multiple independent deep learning models for the same input unlabeled defect sample;
[0009] The first uncertainty score corresponding to each unlabeled defect sample in the current round is sorted, and the unlabeled defect samples with a value greater than the dynamic threshold are determined as the current defect samples to be labeled; wherein, the dynamic threshold is determined based on the change in the performance evaluation index of the same deep learning model on the preset verification defect samples in the current round and the previous round of the current round.
[0010] Based on the current defect sample to be labeled and the historical defect sample to be labeled, a target defect sample to be labeled is determined; wherein, the historical defect sample to be labeled is the defect sample to be labeled from all rounds prior to the current round.
[0011] In one embodiment, calculating the model ensemble difference and prediction entropy corresponding to the unlabeled defect sample, and calculating a first uncertainty score corresponding to each of the unlabeled defect samples in the current round based on the model ensemble difference and the prediction entropy, includes:
[0012] The same unlabeled defect sample is input into multiple independent deep learning models, and the defect category prediction result output by each deep learning model is obtained.
[0013] Based on the prediction results of each defect category, determine the average prediction probability distribution corresponding to each defect category;
[0014] The prediction entropy is determined based on the average prediction probability distributions described above;
[0015] The model integration differences are determined based on the prediction results of each defect category and the average prediction probability distribution corresponding to each defect category;
[0016] The model integration difference and the prediction entropy are weighted and calculated to determine the first uncertainty score corresponding to each unlabeled defect sample in the current round.
[0017] In one embodiment, the dynamic threshold is updated in the following way:
[0018] When the change exceeds the first preset threshold, the dynamic threshold is reduced by the first step.
[0019] When the change is less than the second preset threshold, the dynamic threshold is increased by a second step size; wherein the first step size is greater than the second step size; and the first preset threshold is greater than the second preset threshold.
[0020] In one embodiment, after determining the target defect sample to be labeled, the method further includes:
[0021] Obtain a pool of labeled defect samples determined based on the target defect sample to be labeled, and extract the prototype feature vector of each defect category from the pool of labeled defect samples; wherein, the prototype feature vector of each defect category corresponds to at least one labeled defect sample in the pool of labeled defect samples.
[0022] Acquire the target image to be detected, and extract the features of the target image to obtain a feature map;
[0023] Based on the structural similarity between the feature map and the prototype feature vector, an initial segmentation mask is determined;
[0024] The initial segmentation mask is updated to obtain the target segmentation mask;
[0025] The defect label category and confidence level corresponding to the target segmentation mask are determined based on the target segmentation mask.
[0026] In one embodiment, updating the initial segmentation mask to obtain the target segmentation mask includes:
[0027] Based on the initial segmentation mask, extract the query feature vector from the feature map;
[0028] Using the query feature vector as a condition, a nearest neighbor search is performed in the feature space corresponding to the labeled defect sample pool to determine multiple labeled defect samples similar to the query feature vector as target labeled defect samples; wherein, the target labeled defect sample includes the sample features, sample defect category prediction result and sample prediction mask of each labeled defect sample;
[0029] Based on the query feature vector, the features of each sample, and the prediction results of the defect categories of each sample, the retrieval consistency loss value is determined; based on the prediction mask of each sample and the actual mask of the target labeled defect sample, the segmentation quality loss value is determined.
[0030] The initial segmentation mask is iteratively updated based on the retrieval consistency loss value and the segmentation quality loss value to obtain the target segmentation mask.
[0031] In one embodiment, the step of iteratively updating the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain the target segmentation mask includes:
[0032] The initial segmentation mask is iteratively updated based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask;
[0033] Based on the new initial segmentation mask, extract a new query feature vector from the feature map;
[0034] Based on the new query feature vector, a neighbor search is re-performed in the feature space corresponding to the labeled defect sample pool to determine new target labeled defect samples;
[0035] Based on the new target-labeled defect samples, new segmentation quality loss values and new retrieval consistency loss values are obtained;
[0036] The new initial segmentation mask is iteratively updated based on the new segmentation quality loss value and the new retrieval consistency loss value until the stopping condition is met to obtain the target segmentation mask.
[0037] In one embodiment, the step of iteratively updating the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask includes:
[0038] Based on the retrieval consistency loss value and the segmentation quality loss value, determine the gradient of the predicted probability value of each pixel in the initial segmentation mask;
[0039] The update direction and update magnitude of the predicted probability values of each pixel in the initial segmentation mask are determined based on the gradient.
[0040] Based on the update direction and the update magnitude, the predicted probability values of each pixel in the initial segmentation mask are adjusted to obtain the new initial segmentation mask.
[0041] In one embodiment, the method further includes:
[0042] When a candidate new defect type is detected, a sample image containing the candidate new defect type is obtained, and the candidate new prototype feature vector corresponding to the sample image is determined.
[0043] If the difference in feature space distribution between the candidate new prototype feature vector and each prototype feature vector is greater than the new category determination threshold, the candidate new prototype feature vector shall be used as the target new prototype feature vector.
[0044] A second uncertainty score is obtained for each of the sample images, and a third uncertainty score is obtained for at least one labeled defect sample corresponding to each of the prototype feature vectors, wherein the third uncertainty score is determined based on the first uncertainty score;
[0045] Based on the second uncertainty score and the third uncertainty score, a first storage space for storing the newly added prototype feature vectors of the target and a second storage space for storing each of the prototype feature vectors are determined in the prototype memory; wherein, the uncertainty score is positively correlated with the storage space; the uncertainty score includes the second uncertainty score and the third uncertainty score, and the storage space includes the first storage space and the second storage space;
[0046] The newly added prototype feature vector of the target is stored in the first storage space, and each prototype feature vector is stored in the second storage space.
[0047] In one embodiment, the method further includes:
[0048] When the storage space of the prototype memory reaches a preset capacity threshold, the similarity between all prototype feature vectors stored in the prototype memory is calculated.
[0049] The prototype feature vectors with similarity higher than the similarity threshold are used as prototype feature vectors to be merged.
[0050] The prototype feature vectors to be merged are combined to obtain the merged prototype feature vector;
[0051] The prototype feature vectors with similarity higher than the similarity threshold are deleted from the prototype memory, and the merged prototype feature vectors are added to the prototype memory until the storage space of the prototype memory is less than or equal to the preset capacity threshold.
[0052] In one embodiment, merging the prototype feature vectors to be merged to obtain merged prototype feature vectors includes:
[0053] Based on the uncertainty scores corresponding to the prototype feature vectors to be merged, the merging weight of each prototype feature vector is determined; wherein, the merging weight is negatively correlated with the uncertainty score.
[0054] The merged prototype feature vector is obtained by weighting the prototype feature vectors to be merged according to the merging weights.
[0055] Secondly, this application also provides a defect sample screening device, comprising:
[0056] The acquisition module is used to acquire an unlabeled defect sample pool, wherein the unlabeled defect sample pool includes multiple unlabeled defect samples;
[0057] The calculation module is used to calculate the model ensemble difference and prediction entropy corresponding to each unlabeled defect sample, and to calculate the first uncertainty score corresponding to each unlabeled defect sample in the current round based on the model ensemble difference and the prediction entropy; wherein, the model ensemble difference indicates the degree of inconsistency between the prediction results of multiple independent deep learning models for the same input unlabeled defect sample; and the prediction entropy indicates the information entropy of the average prediction probability distribution of multiple independent deep learning models for the same input unlabeled defect sample.
[0058] The first determining module is used to sort the first uncertainty scores corresponding to each unlabeled defect sample in the current round, and determine the unlabeled defect samples with scores greater than a dynamic threshold as the current defect samples to be labeled; wherein, the dynamic threshold is determined based on the change in the performance evaluation index of the same deep learning model on the preset verification defect samples in the current round and the previous round of the current round.
[0059] The second determining module is used to determine the target defect sample to be labeled based on the current defect sample to be labeled and the historical defect samples to be labeled; wherein, the historical defect samples to be labeled are the defect samples to be labeled from all rounds before the current round.
[0060] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described method.
[0061] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.
[0062] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described method.
[0063] The aforementioned defect sample screening method, apparatus, computer equipment, computer-readable storage medium, and computer program product first acquire an unlabeled defect sample pool, wherein the unlabeled defect sample pool includes multiple unlabeled defect samples; secondly, for each unlabeled defect sample, the model ensemble difference and prediction entropy corresponding to the unlabeled defect sample are calculated, and a first uncertainty score corresponding to each unlabeled defect sample in the current round is calculated based on the model ensemble difference and prediction entropy; wherein, the model ensemble difference indicates the degree of inconsistency between the prediction results of multiple independent deep learning models for the same input unlabeled defect sample; and the prediction entropy indicates the information entropy of the average prediction probability distribution of multiple independent deep learning models for the same input unlabeled defect sample; through The information value of each unlabeled defect sample is quantified using a dual dimension of model ensemble discrepancy and prediction entropy. Next, the first uncertainty score corresponding to each unlabeled defect sample in the current round is ranked, and unlabeled defect samples with scores exceeding a dynamic threshold are identified as current defect samples to be labeled. The dynamic threshold is determined based on the change in performance evaluation metrics of the same deep learning model on preset verification defect samples between the current round and the previous round. Unlabeled defect samples with scores exceeding the dynamic threshold are prioritized for labeling. Finally, target defect samples to be labeled are determined based on the current and historical defect samples to be labeled. Historical defect samples to be labeled are those from all rounds prior to the current round. Quantifying the information value of each unlabeled defect sample using a dual dimension of model ensemble discrepancy and prediction entropy, unlabeled defect samples exceeding the dynamic threshold represent samples that the model finds difficult to identify; therefore, prioritizing the labeling of unlabeled defect samples with scores exceeding the dynamic threshold, and labeling both the current and historical defect samples selected from each round, reduces the number of labeled defect samples. In addition, since the dynamic threshold is determined based on the change in the performance evaluation index of the same deep learning model on the preset verification defect samples in the current round and the previous round, it takes into account both the number of labeled samples and the performance of the deep learning model. This ensures that the number of defect samples to be labeled is a reasonable number that does not affect the performance of the deep learning model, and can further reduce the number of labeled defect samples. Attached Figure Description
[0064] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0065] Figure 1 This is a flowchart illustrating a defect sample screening method in one embodiment;
[0066] Figure 2 This is a schematic diagram of the process for calculating the first uncertainty score in one embodiment;
[0067] Figure 3 This is a flowchart illustrating the online inference process in one embodiment;
[0068] Figure 4 This is a schematic diagram illustrating the process of obtaining the target segmentation mask in one embodiment;
[0069] Figure 5 This is a schematic diagram illustrating the process of obtaining a new initial segmentation mask in one embodiment;
[0070] Figure 6 This is a flowchart illustrating the process of adding a new defect type in one embodiment;
[0071] Figure 7 This is a flowchart illustrating the process of merging and deleting prototype feature vectors in one embodiment;
[0072] Figure 8 This is a structural block diagram of a defect sample screening device in one embodiment;
[0073] Figure 9 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0074] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0075] In one embodiment, such as Figure 1 As shown, a defect sample screening method is provided. This embodiment illustrates the method applied to a terminal, but it is understood that the method can also be applied to a server, and to a system including both a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps S102 to S108. Wherein:
[0076] Step S102: Obtain the unlabeled defect sample pool, wherein the unlabeled defect sample pool includes multiple unlabeled defect samples.
[0077] Optionally, the terminal acquires the original defect samples, performs median filtering for noise reduction, normalization, and contrast enhancement preprocessing on each original defect sample to obtain an unlabeled defect sample pool, which includes N unlabeled samples, where N is a positive integer.
[0078] Step S104: For each unlabeled defect sample, calculate the model ensemble difference and prediction entropy corresponding to the unlabeled defect sample, and calculate the first uncertainty score corresponding to each unlabeled defect sample in the current round based on the model ensemble difference and prediction entropy.
[0079] Model ensemble discrepancy indicates the degree of inconsistency among the predictions of multiple independent deep learning models for the same input unlabeled defect sample. Within the academic framework of active learning and uncertainty estimation, model ensemble discrepancy quantifies the epistemic uncertainty of a model's prediction, i.e., the uncertainty arising from the model's lack of sufficient knowledge. In classification tasks, for the same input unlabeled defect sample x, each of the M models in the ensemble outputs a K-dimensional class probability vector. The greater the dispersion among these predicted probability vectors, the greater the "disagreement" between the models, indicating that the unlabeled defect sample is outside the model's knowledge boundary, and the lower the reliability of the model's prediction.
[0080] Prediction entropy indicates the information entropy of the average predicted probability distribution of multiple independent deep learning models for the same input unlabeled defective sample. It is used to quantify the overall uncertainty of a model's prediction, including both cognitive uncertainty and the inherent noise of the data itself (i.e., random uncertainty). The more uniform the probability distribution (the closer the predicted probabilities of each category are), the higher the information entropy value, indicating that the model's prediction is more ambiguous; the more sharp the probability distribution (the probability of a certain category is close to 1), the lower the information entropy value, indicating that the model's prediction is more certain.
[0081] The principle behind choosing model ensemble discrepancy and prediction entropy as the two dimensions is as follows: The uncertainty of deep learning models can be decomposed into two fundamentally different sources. First, there is cognitive uncertainty, captured by model ensemble discrepancy. Cognitive uncertainty stems from the model's "ignorance" of the data, resulting from insufficient training data to cover a certain region of the input space. This uncertainty can be reduced by increasing the training data (especially samples from regions where the model is currently uncertain). Second, there is random uncertainty, partially captured by prediction entropy. Random uncertainty originates from inherent noise or ambiguity in the data itself (such as blurred images, unclear defect boundaries, or overlapping categories). This uncertainty cannot be eliminated by adding more data. Model ensemble discrepancy primarily captures cognitive uncertainty: when the predictions of the various models in the ensemble show significant divergence, it indicates that the sample is outside the model's knowledge boundary, and the model "does not know" how to correctly classify the sample. Prediction entropy captures both types of uncertainty simultaneously: it reflects both the ambiguity of the model's predictions (high entropy value if the prediction probability is uniformly distributed) and indirectly reflects the ambiguity of the data itself. Therefore, the essence of dual-dimensional design is to simultaneously capture uncertainty signals at two levels: "the model does not know" (integration difference) and "prediction is uncertain" (prediction entropy), so as to achieve a comprehensive evaluation of the value of sample information.
[0082] Optionally, the terminal calculates the model ensemble difference and prediction entropy for each unlabeled defect sample, and calculates the first uncertainty score for each unlabeled defect sample in the current round based on the two dimensions of model ensemble difference and prediction entropy. The first uncertainty score can be used to evaluate the potential contribution of unlabeled defect samples to model performance.
[0083] Step S106: Sort the first uncertainty score corresponding to each unlabeled defect sample in the current round, and determine the unlabeled defect samples with a value greater than the dynamic threshold as the current defect samples to be labeled.
[0084] The dynamic threshold is determined based on the change in performance evaluation metrics of the same deep learning model on preset verification defect samples between the current round and the previous round. The preset verification defect samples are independent of the unlabeled defect sample pool and constitute a separate verification set. Performance evaluation metrics include the average intersection-over-union (AUI), which is calculated by comparing a model's prediction mask of the preset verification defect samples with a manually labeled ground truth mask, resulting in a score between 0 and 1.
[0085] Optionally, the dynamic threshold is generated by: obtaining the average intersection-over-union (IoU) ratio of each deep learning model on preset verification defect samples in the current round, and the average IoU ratio of each deep learning model on preset verification defect samples in the previous round; selecting the deep learning model with the largest average IoU ratio that is the same in both the current and previous rounds; obtaining the performance evaluation index of the same deep learning model on preset verification defect samples in the current round and the same deep learning model on preset verification defect samples in the previous round; and calculating the change. If the change is large, it means that the deep learning model is still in the rapid learning stage and needs more unlabeled defect samples, so the dynamic threshold is lowered. If the change is small, it means that the deep learning model is close to saturation and only needs the highest quality unlabeled defect samples, so the dynamic threshold is increased. If the change is moderate, it means that the deep learning model is stable, and the dynamic threshold remains unchanged.
[0086] Furthermore, there are 5 deep learning models. In the current round, the terminal uses each deep learning model to calculate the average crossover ratio (CWR) on the preset verification defect samples, and obtains the average CWR of the 5 deep learning models. At the same time, the terminal obtains the average CWR of each deep learning model on the preset verification defect samples in the previous round, and selects the deep learning model with the largest average CWR that is the same in the current round and the previous round, such as the third deep learning model. The change in the average CWR of the third deep learning model between the two rounds is calculated, and a dynamic threshold is determined based on the change.
[0087] Optionally, the terminal sorts the first uncertainty scores corresponding to each unlabeled defect sample in the current round, for example, the fourth round, and determines the unlabeled defect samples with scores greater than the dynamic threshold as the current defect samples to be labeled in the fourth round.
[0088] Step S108: Based on the current defect samples to be labeled and the historical defect samples to be labeled, determine the target defect samples to be labeled.
[0089] Among them, the historical defect samples to be labeled are the defect samples to be labeled from all rounds before the current round.
[0090] Optionally, the terminal obtains the defect samples to be labeled from the first to the third round as historical defect samples to be labeled, and together with the current defect samples to be labeled in the third round, they are used as target defect samples to be labeled, which is the cumulative number of labeled samples as shown in Table 1.
[0091] Table 1. Adaptive sampling process guided by four-wheel uncertainty
[0092]
[0093] In another embodiment, the parameters for calculating the first uncertainty score are set to α=0.6 and β=0.4. There are 3000 images in the unlabeled sample pool, and the uncertainty score U(x) for each image is calculated. The initial sampling threshold τ_u=0.7. After calculation, 420 images have U(x)>0.7, and 200 of these are selected in descending order of score for manual annotation. After the first round of training, the model accuracy mAP@0.5 improves from 0.72 to 0.81. Based on the improvement in model performance, τ_u is dynamically adjusted to 0.65, and the second round of sampling begins. After three rounds of iterative sampling, a total of 800 samples are annotated, and the model accuracy mAP@0.5 reaches 0.91, meeting the requirements for production line inspection. Compared to the traditional random sampling strategy (which requires approximately 1600 labeled samples to achieve the same accuracy), the annotation cost is reduced by 50%.
[0094] In the aforementioned defect sample screening method, firstly, an unlabeled defect sample pool is obtained, which includes multiple unlabeled defect samples. Secondly, for each unlabeled defect sample, the model ensemble difference and prediction entropy corresponding to the unlabeled defect sample are calculated. Based on the model ensemble difference and prediction entropy, the first uncertainty score corresponding to each unlabeled defect sample in the current round is calculated. Here, the model ensemble difference indicates the degree of inconsistency between the prediction results of multiple independent deep learning models for the same input unlabeled defect sample; the prediction entropy indicates the information entropy of the average prediction probability distribution of multiple independent deep learning models for the same input unlabeled defect sample. The method utilizes the two dimensions of model ensemble difference and prediction entropy. The information value of each unlabeled defect sample is quantified using a dual-dimensional approach of model ensemble difference and prediction entropy. Unlabeled defect samples with a dynamic threshold are ranked based on their first uncertainty score, and those exceeding this threshold are identified as current unlabeled defect samples to be labeled. The dynamic threshold is determined by the change in performance evaluation metrics of the same deep learning model on preset verification defect samples between the current and previous rounds. Unlabeled defect samples with a dynamic threshold are prioritized for labeling. Finally, target unlabeled defect samples are determined based on the current and historical unlabeled defect samples. Historical unlabeled defect samples are those from all rounds prior to the current round. This method quantifies the information value of each unlabeled defect sample using both model ensemble difference and prediction entropy. Unlabeled defect samples exceeding the dynamic threshold represent samples that the model struggles to identify; therefore, they are prioritized for labeling. Labeling both current and historical unlabeled defect samples obtained from each round reduces the number of labeled defect samples. In addition, since the dynamic threshold is determined based on the change in the performance evaluation index of the same deep learning model on the preset verification defect samples in the current round and the previous round, it takes into account both the number of labeled samples and the performance of the deep learning model. This ensures that the number of defect samples to be labeled is a reasonable number that does not affect the performance of the deep learning model, and can further reduce the number of labeled defect samples.
[0095] In one exemplary embodiment, a first uncertainty score is calculated, such as Figure 2 As shown, the model ensemble difference and prediction entropy corresponding to unlabeled defect samples are calculated. Based on the model ensemble difference and prediction entropy, the first uncertainty score corresponding to each unlabeled defect sample in the current round is calculated, including the following steps S202 to S210. Wherein:
[0096] Step S202: Input the same unlabeled defect sample into multiple independent deep learning models and obtain the defect category prediction results output by each deep learning model.
[0097] An ensemble of M independently trained deep learning models (M≥3) is constructed. These deep learning models are trained using different random initializations, different subsets of training data (Bootstrap sampling), or different model architecture variants to ensure diversity among the models. This diversity is a prerequisite for ensuring that the ensemble's differences effectively reflect cognitive uncertainty.
[0098] Optionally, for the same unlabeled defect sample x, the terminal inputs x into the M models in the ensemble, and each model outputs a K-dimensional class probability vector, which is the defect class prediction result.
[0099] Step S204: Based on the prediction results of each defect category, determine the average prediction probability distribution corresponding to each defect category.
[0100] Optionally, the terminal averages the predicted probability vectors of the M deep learning models according to the defect category to obtain the average predicted probability distribution corresponding to each defect category.
[0101] Step S206: Determine the prediction entropy based on each average prediction probability distribution.
[0102] Optionally, the terminal substitutes the average predicted probability distribution corresponding to each defect category into the information entropy definition formula, as shown in formula (1), to obtain the prediction entropy.
[0103] Formula (1)
[0104] In the formula, Represents the predicted entropy. The total number of defect categories is represented by k, where k represents the k-th defect category. The probability value that belongs to the k-th class in the average probability predicted by the model ensemble for the unlabeled defect sample x; It is a very small positive number (such as 1*10). -8 This prevents zero values from occurring in logarithmic operations.
[0105] Predicting entropy The value range is [0, log K]. When When = 0, it means that the model ensemble determines that the sample belongs to a certain category with a probability of 1, and the prediction is completely certain; when When the probability of prediction is equal to log K, it means that the prediction probability of the model integration is exactly equal across all K categories (all are 1 / K), and the prediction is the most ambiguous.
[0106] Step S208: Determine the model integration differences based on the prediction results of each defect category and the average prediction probability distribution corresponding to each defect category.
[0107] Optionally, for each defect category, the terminal obtains the defect category prediction results of each deep learning model in that defect category, such as the predicted probability value and the average predicted probability value of that defect category in the average predicted probability distribution. The terminal calculates the square of the difference between the predicted probability value of each deep learning model in that category and the average predicted probability value. The terminal sums the square values of all deep learning models and divides the sum by the number of deep learning models to obtain the category variance of that defect category. The terminal sums the category variances of all defect categories and divides the sum by the total number of defect categories. The result is used as the model integration difference, as shown in formula (2).
[0108] Formula (2)
[0109] In the formula, Representative model integration differences; represents the probability that the m-th unlabeled defect sample x belongs to the k-th class; M represents the total number of deep learning models.
[0110] Step S210: Perform a weighted calculation on the model integration difference and prediction entropy to determine the first uncertainty score corresponding to each unlabeled defect sample in the current round.
[0111] Optionally, the terminal obtains the weight coefficients of the model integration difference and the weight coefficients of the prediction entropy, performs weighted calculations based on their respective weight coefficients, and determines the first uncertainty score corresponding to each unlabeled defect sample in the current round, as shown in formula (3).
[0112] Formula (3)
[0113] In the formula, Represents the first uncertainty score, The weighting coefficients representing the prediction entropy The weight coefficients representing the differences in model integration, where, .
[0114] In practical applications, using only model ensemble discrepancies makes it difficult to distinguish between "model disagreements due to lack of knowledge" (which should be sampled) and "disagreements caused by inherent ambiguity in the data" (which have lower sampling value). Some samples may lead to inconsistent predictions from different models due to poor image quality or blurred class boundaries, but even if such samples are labeled, it is unlikely to improve model performance—model ensemble discrepancies overestimate their value. Using only prediction entropy cannot distinguish between "high entropy caused by model ignorance" and "high entropy caused by inherent noise in the data." When the model gives nearly uniform prediction probabilities for all classes, the entropy value is high, but this may simply be because the sample is located on the decision boundary of all classes (high data ambiguity), rather than because the model lacks knowledge of that region. When a sample has both high model ensemble discrepancies and high prediction entropy, it indicates that the sample is both outside the model's knowledge boundary (high cognitive uncertainty) and has high prediction ambiguity—such samples have the highest potential value for model improvement and should be prioritized for labeling.
[0115] In this embodiment, the first uncertainty score corresponding to each unlabeled defect sample is determined by the dual dimensions of model integration difference and prediction entropy. This can accurately identify those samples that are both outside the model's knowledge boundary and have high learning value, thereby maximizing the improvement of model performance with minimal manual annotation cost.
[0116] In an exemplary embodiment, the dynamic threshold is updated in the following manner: when the change is greater than a first preset threshold, the dynamic threshold is decreased by a first step size; when the change is less than a second preset threshold, the dynamic threshold is increased by a second step size.
[0117] Among them, the length of the first step is greater than the length of the second step; the first preset threshold is greater than the second preset threshold.
[0118] Optionally, when the change exceeds the first preset threshold, it is determined that the current model is in the exploration stage and it is necessary to expand the sample selection range to obtain more diverse training data. In this case, the dynamic threshold is reduced by the first step length.
[0119] When the change is less than the second preset threshold, it is determined that the current model is in the utilization stage and the model is close to performance saturation. It is only necessary to select high-value samples at the decision boundary for fine labeling. At this time, the dynamic threshold is increased by the second step size.
[0120] When the change is greater than or equal to the second preset threshold and less than or equal to the first preset threshold, the current model is determined to be in a transition phase, and the dynamic threshold is kept unchanged to maintain the stability of the current sampling rhythm.
[0121] In this embodiment, by introducing a dynamic threshold adjustment strategy, the sampling strategy can adaptively transition from the exploration phase (sampling samples with high uncertainty in diversity) to the utilization phase (sampling samples with high uncertainty in the boundary region), achieving the optimal balance between annotation efficiency and model performance.
[0122] In one exemplary embodiment, the online inference process, such as Figure 3 As shown, after determining the target defect sample to be labeled, the process includes steps S302 to S310. Wherein:
[0123] Step S302: Obtain the labeled defect sample pool determined based on the target defect sample to be labeled, and extract the prototype feature vector of each defect category from the labeled defect sample pool.
[0124] In this context, the prototype feature vector of each defect category corresponds to at least one labeled defect sample in the labeled defect sample pool.
[0125] Optionally, after determining the target defect sample to be labeled, the target defect sample to be labeled is labeled manually or by other algorithms to obtain a labeled defect sample pool. The terminal obtains the labeled defect sample pool and extracts the defect region of the labeled reference image in the labeled defect sample pool. The extraction process is as shown in formula (4) to obtain the prototype feature vector of each defect category, where each defect category corresponds to at least one prototype feature vector.
[0126] Formula (4)
[0127] In the formula, The prototype feature vector representing the k-th type of defect; This represents a defect sample belonging to the k-th type of defect in the labeled defect sample pool; This represents the i-th defect sample in the labeled defect sample pool; This represents the pixel-level defect mask corresponding to the i-th defect sample; F represents element-wise multiplication; F() represents a two-branch feature extraction network.
[0128] Step S304: Obtain the target image to be detected and extract the features of the target image to obtain a feature map.
[0129] Optionally, the terminal acquires the original image of the product to be inspected captured by an industrial camera, performs denoising, normalization, and contrast enhancement preprocessing to obtain the target image to be inspected. The terminal uses a dual-branch feature extraction network to extract features from the target image to be inspected, including: extracting multi-scale depth features from the target image to be inspected through a lightweight convolutional backbone network (based on CSPNet architecture) in the first branch to obtain multi-scale depth features; extracting defect contour features from the target image to be inspected through a deformable convolutional network in the second branch to obtain contour feature maps; and adaptively fusing the outputs of the two branches to obtain a feature map of the fused features.
[0130] Furthermore, the original images of the products to be inspected are acquired using an industrial camera. These images are then preprocessed: median filtering for noise reduction (3×3 kernels, σ=0.6), Z-score normalization, and adaptive histogram equalization (clipLimit=2.5, tileGridSize=16×16). The dual-branch feature extraction network is configured as follows: Branch 1: a lightweight CSPNet backbone network, extracting multi-scale depth features (channel count progressively 256-512-1024); Branch 2: a deformable convolutional network (3 deformable convolutional layers, 3×3 kernels per layer, learnable offsets), extracting defect contour features. The outputs of the two branches are fused through an adaptive fusion layer, with the fusion weights automatically learned by the network.
[0131] Step S306: Determine the initial segmentation mask based on the structural similarity between the feature map and the prototype feature vector.
[0132] Optionally, an initial segmentation mask is generated by calculating the structural similarity between each pixel in the feature map and the prototype of each defect category using a learnable metric network. The learnable metric network employs a structure-aware attention mechanism, considering not only pixel-level feature differences but also the structural consistency of local regions when calculating similarity. This includes: for each pixel location in the feature map, obtaining the feature vector corresponding to that location; and then... Prototype feature vector of a certain defect category Concatenate the vectors to obtain the concatenated vector. ; The concatenated vector is input into the pixel-level similarity calculation function. For example, in an MLP network, pixel-level similarity is obtained. Prototype feature vectors are extracted using the local neighborhood structure extraction operator N(). and eigenvectors The two structural descriptors are input into the structural consistency evaluation function, along with their respective local neighborhood structural descriptors. The structural consistency measure is obtained. The pixel-level similarity is then added to the structural consistency measure to obtain the final structural similarity between the pixel location and the defect category. As shown in formula (5). For each pixel position (x, y) in the multi-scale depth feature map, among the k defect categories, the defect category that maximizes the structural similarity is selected as the initial predicted category of the pixel; the maximum structural similarity is used as the initial confidence score of the pixel; the initial predicted category of each pixel and its corresponding confidence score are upsampled and restored according to the spatial resolution of the original image to generate an initial segmentation mask and an initial confidence score map of the same size as the target image to be detected.
[0133] Formula (5)
[0134] In the formula, This represents the pixel position in the feature map. The vector represents the feature vector located at the pixel position, and [] represents vector concatenation operation. This represents a pixel-level similarity calculation function. Represents the structural consistency evaluation function. represent Local neighborhood structure descriptor, A structural descriptor representing a local neighborhood; Represents structural similarity.
[0135] Step S308: Update the initial segmentation mask to obtain the target segmentation mask.
[0136] Step S310: Determine the defect label category and confidence level corresponding to the target segmentation mask based on the target segmentation mask.
[0137] Optionally, the terminal updates the initial segmentation mask using a joint loss function to obtain the target segmentation mask. The joint loss function includes a retrieval consistency loss and a segmentation quality loss. The segmentation quality loss measures the pixel-level difference between the current predicted mask and the reference mask provided by the retrieved samples; the retrieval consistency loss aims to make the segmentation features of the current image converge in the feature space towards the features of similar labeled samples. The terminal performs connected component analysis on the target segmentation mask to separate defect instances and determines the category label and confidence score for each defect instance.
[0138] In this embodiment, pixel-level feature differences are considered by calculating structural similarity, and the spatial layout and texture structure consistency of local areas are captured by a structure-aware attention mechanism, which effectively suppresses false detection of isolated noise points and improves output accuracy.
[0139] In one exemplary embodiment, such as Figure 4 As shown, the initial segmentation mask is updated to obtain the target segmentation mask, including steps S402 to S408. Wherein:
[0140] Step S402: Extract the query feature vector from the feature map based on the initial segmentation mask.
[0141] Step S404: Using the query feature vector as a condition, perform a neighbor search in the feature space corresponding to the labeled defect sample pool to determine multiple labeled defect samples that are similar to the query feature vector as target labeled defect samples.
[0142] The target labeled defect samples include the sample features, sample defect category prediction results, and sample prediction mask for each labeled defect sample.
[0143] Optionally, the terminal extracts a query feature vector from the feature map based on the initial segmentation mask, and calculates the cosine similarity between the query feature vector and each labeled defect sample in the labeled defect sample pool, using the query feature vector as the retrieval condition. All labeled defect samples are then sorted in descending order of cosine similarity, and a predetermined number of the top-ranked labeled defect samples are selected as the target labeled defect samples.
[0144] Step S406: Based on the query feature vector, the features of each sample, and the prediction results of the defect category of each sample, determine the retrieval consistency loss value; based on the prediction mask of each sample and the sample true mask of the target labeled defect sample, determine the segmentation quality loss value.
[0145] Optionally, for each defect sample in the target labeled defect samples, the feature similarity between the query feature vector and the sample feature vector of that defect sample is calculated, and the feature similarity is multiplied by the logarithm of the sample defect category prediction result of that defect sample, log(p). i ) and take the negative value to obtain the retrieval contribution value of the defective sample; sum up the retrieval contribution values of all defective samples and use the summation result as the retrieval consistency loss value. The calculation process of the retrieval consistency loss value is shown in formula (6).
[0146] Formula (6)
[0147] In the formula, Represents the query feature vector. This represents the sample feature vector of the i-th retrieved defective sample. Representative feature similarity function This represents the predicted defect category of the i-th retrieved defect sample. Retrieve consistency loss function.
[0148] Optionally, for each defect sample in the target labeled defect sample, the terminal calculates the Dice loss value and Focal loss value based on the sample prediction mask and sample real mask of the unified defect sample, respectively. Based on the Dice loss value of each defect sample in the target labeled defect sample, the terminal calculates the average Dice loss value; based on the Focal loss value of each defect sample in the target labeled defect sample, the terminal calculates the average Focal loss value; and the terminal calculates the segmentation quality loss value by weighted averaging of the average Dice loss value and the average Focal loss value. The calculation process of the segmentation quality loss value is shown in formula (7).
[0149] Formula (7)
[0150] In the formula, Represents the segmentation quality loss function. and For coefficients, Representing average Loss value, This represents the average Focal loss value.
[0151] Step S408: The initial segmentation mask is iteratively updated based on the retrieval consistency loss value and the segmentation quality loss value to obtain the target segmentation mask.
[0152] Optionally, the terminal calculates the retrieval consistency loss value and the segmentation quality loss value using formula (8) to obtain the joint optimization loss value, and uses the joint optimization loss value to iteratively update the initial segmentation mask to obtain the target segmentation mask.
[0153] Formula (8)
[0154] In the formula, Represents joint optimization loss, The coefficients representing the retrieval consistency loss function are... The coefficients represent the segmentation quality loss function.
[0155] In this embodiment, a joint optimization loss is constructed by constraining the consistency of categories between query features and retrieved sample features in the feature space through retrieval consistency loss and constraining the region overlap between the predicted mask and the retrieved sample mask in the pixel space through segmentation quality loss. Under the condition that the model parameters are completely frozen, only the mask pixel values are iteratively updated, which can achieve instance-level mask refinement of a single query image while maintaining the model's generalization ability, effectively improving the segmentation accuracy of defect boundaries.
[0156] In an exemplary embodiment, the initial segmentation mask is iteratively updated based on the retrieval consistency loss value and the segmentation quality loss value to obtain the target segmentation mask. This includes: iteratively updating the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask; extracting a new query feature vector from the feature map based on the new initial segmentation mask; re-performing a nearest neighbor search in the feature space corresponding to the labeled defect sample pool based on the new query feature vector to determine new target labeled defect samples; obtaining new segmentation quality loss values and new retrieval consistency loss values based on the new target labeled defect samples; and iteratively updating the new initial segmentation mask based on the new segmentation quality loss values and the new retrieval consistency loss values until a stopping condition is met to obtain the target segmentation mask.
[0157] The stopping condition is, for example, reaching the required number of iterations.
[0158] Optionally, the terminal iteratively updates the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask; the iterative process is repeated based on the new initial segmentation mask, as shown in the previous embodiment, until the stopping condition is met to obtain the target segmentation mask.
[0159] In this embodiment, the segmentation accuracy of defects can be improved through iterative updates.
[0160] In one exemplary embodiment, such as Figure 5 As shown, the initial segmentation mask is iteratively updated based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask, including steps S502 to S506. Wherein:
[0161] Step S502: Based on the retrieval consistency loss value and the segmentation quality loss value, determine the gradient of the predicted probability value of each pixel in the initial segmentation mask.
[0162] Optionally, the terminal uses each pixel value in the probability map of the initial segmentation mask as a variable. Under the condition that all model parameters of the dual-branch feature extraction network and the learnable metric network are kept frozen, the automatic differentiation engine is invoked to perform backpropagation calculation on the joint optimization loss value. This includes: the automatic differentiation engine follows the chain rule, starting from the joint optimization loss value, and traces the gradient propagation path layer by layer forward. First, it calculates the partial derivative of the joint optimization loss value with respect to the predicted probability value of each pixel in the current segmentation mask. The calculation of the partial derivative simultaneously considers the contribution of the retrieval consistency loss component to the mask pixels and the contribution of the segmentation quality loss component to the mask pixels. The two are superimposed by a weighted summation to obtain the final gradient value.
[0163] Step S504: Determine the update direction and update magnitude of the predicted probability values of each pixel in the initial segmentation mask based on the gradient.
[0164] Optionally, for each pixel position (x, y), the terminal determines the update direction based on the basic principle of gradient descent. The update direction is always the opposite direction of the gradient. The terminal obtains the learning rate and multiplies it by the absolute value of the gradient to get the update magnitude for that pixel. It iterates through all pixel positions in the current segmentation mask, determining the update direction and magnitude for each pixel position (x, y).
[0165] Step S506: Adjust the predicted probability values of each pixel in the initial segmentation mask according to the update direction and update magnitude to obtain a new initial segmentation mask.
[0166] Optionally, for each pixel position (x, y) in the current initial segmentation mask, the terminal adjusts the current predicted probability value according to the update direction: if the gradient value is positive, the predicted probability value is subtracted from the update magnitude; if the gradient value is negative, the current predicted probability value is added to the update magnitude. After traversing all pixel positions of the current initial segmentation mask and completing the above adjustments, the updated initial segmentation mask is output.
[0167] During the inference phase, i.e., with the model parameters completely frozen, the pixel probability values of the initial segmentation mask are used as optimizable variables. Features and mask information provided by similar labeled samples retrieved from the labeled defect sample pool are used as supervision signals to construct a joint optimization loss function. The mask pixel values are then corrected through a finite number of iterations of backpropagation. Throughout the iteration process, all weight parameters of the dual-branch feature extraction network and the learnable metric network remain frozen. The gradients from backpropagation are only used to correct the predicted probability values of each pixel in the segmentation mask of the current query image, without causing any permanent changes to the model itself. This ensures that the model's generalization ability on other images remains unaffected. Using the initial segmentation mask as the query, the most similar labeled samples are retrieved from the feature space of the labeled defect sample pool. The feature vectors, class labels, and segmentation masks of these samples are used as pseudo-ground values to construct retrieval consistency loss and segmentation quality loss. This makes the calculation of the loss function feasible even in inference scenarios without ground truth labels.
[0168] In this embodiment, the gradient direction automatically guides the defect boundary to align with the high-confidence region of the retrieved sample, and the gradient magnitude is precisely controlled by the learning rate to ensure convergence stability.
[0169] In one exemplary embodiment, a new defect type is added, such as Figure 6 As shown, steps S602 to S610 are included. Wherein:
[0170] Step S602: When a candidate new defect type is detected, a sample image containing the candidate new defect type is obtained, and the feature vector of the candidate new prototype corresponding to the sample image is determined.
[0171] Among them, the prototype feature vector is a single representative vector obtained by averaging the feature vectors of all labeled samples in a specific defect category in the vector space after extracting the feature vectors of the defect regions.
[0172] Optionally, when the terminal detects a candidate new defect type, it collects multiple sample images containing the candidate new defect type, with at least three sample images. The terminal extracts the feature vectors from these sample images and calculates the corresponding candidate new prototype feature vectors.
[0173] Step S604: If the difference in feature space distribution between the candidate new prototype feature vector and each prototype feature vector is greater than the new category determination threshold, the candidate new prototype feature vector is taken as the target new prototype feature vector.
[0174] The threshold for determining the new category is denoted as: , is a preset value.
[0175] Optionally, the terminal evaluates the difference in feature space distribution between the candidate new prototype feature vector and each prototype feature vector using formula (9).
[0176] Formula (9)
[0177] In the formula, The distance between the candidate new prototype feature vector and the prototype feature vector can be either cosine distance or Euclidean distance. Representative prototype memory; Representative features show differences in spatial distribution; Represents the prototype feature vector; This represents the candidate newly added prototype feature vector.
[0178] Furthermore, the terminal uses the candidate new prototype feature vectors whose feature space distribution difference is greater than the new category determination threshold as the target new prototype feature vectors.
[0179] Step S606: Obtain the second uncertainty score for each sample image, and obtain the third uncertainty score for at least one labeled defect sample corresponding to each prototype feature vector.
[0180] The third uncertainty score is determined based on the first uncertainty score.
[0181] Optionally, the terminal calculates the second uncertainty score for each sample image using the formula (3) above. The terminal selects the uncertainty score of at least one labeled defect sample corresponding to each prototype feature vector from the first uncertainty scores of multiple labeled defect samples in the prototype memory bank, and uses it as the third uncertainty score.
[0182] Step S608: Based on the second uncertainty score and the third uncertainty score, determine the first storage space in the prototype memory bank that stores the newly added prototype feature vectors of the target and the second storage space that stores each prototype feature vector.
[0183] Step S610: Store the newly added prototype feature vector of the target in the first storage space, and store each prototype feature vector in the second storage space.
[0184] The uncertainty score includes a second uncertainty score and a third uncertainty score, while the storage space includes a first storage space and a second storage space. The uncertainty score and storage space are positively correlated; the higher the uncertainty score, the larger the storage space, and vice versa.
[0185] Optionally, the prototype memory contains three defect categories: A, B, and C, each corresponding to a storage space quota. When a new category, such as a fourth defect category D, is added, the terminal will redetermine the storage space for each category based on the second uncertainty score corresponding to category D and the third uncertainty scores corresponding to categories A, B, and C. In other words, adding a new category will compress the storage space of previously existing defect categories. The higher the uncertainty score, the larger the storage space quota. The terminal calculates the first storage space for storing the newly added prototype feature vector and the second storage space for storing each prototype feature vector in the prototype memory. The newly added prototype feature vector is stored in the first storage space, and the existing prototype feature vectors are stored in the second storage space.
[0186] In this embodiment, by adaptively allocating the storage capacity of the prototype memory bank according to the uncertainty score during the process of adding new categories, and allocating more storage resources to prototypes with high uncertainty (i.e. categories that are easily confused or forgotten), it is possible to maximize the retention of memory accuracy for difficult parts of old knowledge while continuously learning new knowledge.
[0187] In one exemplary embodiment, merging and deleting prototype feature vectors, such as Figure 7 As shown, steps S702 to S708 are included. Wherein:
[0188] Step S702: When the storage space of the prototype memory reaches a preset capacity threshold, calculate the similarity between all prototype feature vectors stored in the prototype memory.
[0189] Step S704: Use the prototype feature vectors with similarity higher than the similarity threshold as the prototype feature vectors to be merged.
[0190] Optionally, when the storage space of the prototype memory reaches a preset capacity threshold... The terminal calculates the pairwise similarity of all prototype feature vectors stored in the prototype memory. For example, if the prototype feature vectors stored in the prototype memory are of four classes (A, B, C, D), the similarity between AB, AC, AD, BC, BD, and CD is calculated. Prototype feature vector pairs with similarity higher than a similarity threshold (each pair includes two prototype feature vectors), such as AB, are selected as the prototype feature vectors to be merged. The similarity calculation may use cosine similarity, for example. There can be multiple prototype feature vector pairs.
[0191] Step S706: Merge the prototype feature vectors to be merged to obtain the merged prototype feature vector.
[0192] Step S708: Delete prototype feature vectors with similarity higher than the similarity threshold from the prototype memory, and add merged prototype feature vectors to the prototype memory until the storage space of the prototype memory is less than or equal to the preset capacity threshold.
[0193] Optionally, the terminal merges the prototype feature vectors to be merged, such as AB, to obtain a merged prototype feature vector, such as E. The terminal then deletes A and B from the prototype memory and adds E to the prototype memory. This continues until the storage space of the prototype memory is less than or equal to a preset capacity threshold.
[0194] Optionally, the terminal merges the prototype feature vectors to be merged, such as AB, to obtain a merged prototype feature vector, such as E; and merges BC to obtain a merged prototype feature vector, such as F. The terminal deletes A, B, and C from the prototype memory and adds E and F to the prototype memory. This continues until the storage space of the prototype memory is less than or equal to a preset capacity threshold.
[0195] In this embodiment, by compressing and merging the prototype feature vectors, the storage space of the prototype memory can be satisfied.
[0196] In an exemplary embodiment, merging the prototype feature vectors to be merged to obtain a merged prototype feature vector includes: determining the merging weight of each prototype feature vector in the prototype feature vectors to be merged based on the uncertainty scores corresponding to each prototype feature vector; and performing a weighted average of the prototype feature vectors to be merged based on the merging weights to obtain a merged prototype feature vector.
[0197] Among them, the merging weight is negatively correlated with the uncertainty score; the higher the uncertainty score, the smaller the merging weight, and the lower the uncertainty score, the larger the merging weight.
[0198] Optionally, the terminal determines each prototype feature vector to be merged using formula (10). and Each of their respective merge weights and .
[0199] Formula (10)
[0200] In the formula, This prevents division by zero for extremely small positive numbers. It can be compared with the aforementioned... The assigned values can be the same or different. For prototype feature vectors The corresponding category uncertainty score stored in the prototype memory. For prototype feature vectors The corresponding category uncertainty score is stored in the prototype memory.
[0201] The terminal will use the prototype feature vector Multiply by the corresponding merge weight At the same time, the prototype feature vector Multiply by the corresponding merge weight Add the two together and divide by the combined weight. and The sum is shown in formula (11).
[0202] Formula (11)
[0203] In the formula, This represents the merged prototype feature vector.
[0204] In this embodiment, during the prototype compression stage, similar prototype feature vectors are weighted and merged based on uncertainty weights, so that prototypes with high uncertainty retain more information during compression. Each round of compression sacrifices redundant information of simple classes that are stable and easy to identify, while retaining features of complex, variable, and easily forgotten difficult classes. The limited prototype storage capacity is preferentially allocated to the "most difficult to learn" defective categories, which significantly alleviates the catastrophic forgetting problem in incremental learning.
[0205] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0206] Based on the same inventive concept, this application also provides a defect sample screening device for implementing the defect sample screening method described above. The solution provided by this device is similar to the solution described in the above method; therefore, the specific limitations in one or more defect sample screening device embodiments provided below can be found in the limitations of the defect sample screening method described above, and will not be repeated here.
[0207] In one exemplary embodiment, such as Figure 8 As shown, a defect sample screening device is provided, comprising: an acquisition module 801, a calculation module 802, a first determination module 803, and a second determination module 804, wherein:
[0208] The acquisition module 801 is used to acquire an unlabeled defect sample pool, wherein the unlabeled defect sample pool includes multiple unlabeled defect samples.
[0209] The calculation module 802 is used to calculate the model ensemble difference and prediction entropy corresponding to each unlabeled defect sample, and to calculate the first uncertainty score corresponding to each unlabeled defect sample in the current round based on the model ensemble difference and the prediction entropy; wherein, the model ensemble difference indicates the degree of inconsistency between the prediction results of multiple independent deep learning models for the same input unlabeled defect sample; and the prediction entropy indicates the information entropy of the average prediction probability distribution of multiple independent deep learning models for the same input unlabeled defect sample.
[0210] The first determining module 803 is used to sort the first uncertainty score corresponding to each unlabeled defect sample in the current round, and determine the unlabeled defect samples with a dynamic threshold as the current defect samples to be labeled; wherein, the dynamic threshold is determined based on the change in the performance evaluation index of the same deep learning model on the preset verification defect samples in the current round and the previous round of the current round.
[0211] The second determining module 804 is used to determine the target defect sample to be labeled based on the current defect sample to be labeled and the historical defect samples to be labeled; wherein, the historical defect samples to be labeled are the defect samples to be labeled from all rounds before the current round.
[0212] In an exemplary embodiment, the calculation module 802 is further configured to input the same unlabeled defect sample into multiple independent deep learning models and obtain the defect category prediction result output by each deep learning model; determine the average prediction probability distribution corresponding to each defect category based on the prediction results of each defect category; determine the prediction entropy based on each average prediction probability distribution; determine the model ensemble difference based on the prediction results of each defect category and the average prediction probability distribution corresponding to each defect category; and perform a weighted calculation on the model ensemble difference and the prediction entropy to determine the first uncertainty score corresponding to each unlabeled defect sample in the current round.
[0213] In an exemplary embodiment, the defect sample screening device further includes a dynamic threshold update module, which is used to lower the dynamic threshold by a first step length when the change is greater than a first preset threshold, and to raise the dynamic threshold by a second step length when the change is less than a second preset threshold; wherein the first step length is greater than the second step length; and the first preset threshold is greater than the second preset threshold.
[0214] In an exemplary embodiment, the defect sample screening device further includes an inference module, configured to acquire a pool of labeled defect samples determined based on target defect samples to be labeled, and extract a prototype feature vector for each defect category from the pool of labeled defect samples; wherein the prototype feature vector for each defect category corresponds to at least one labeled defect sample in the pool of labeled defect samples; acquire a target image to be detected, extract features from the target image to obtain a feature map; determine an initial segmentation mask based on the structural similarity between the feature map and the prototype feature vector; update the initial segmentation mask to obtain a target segmentation mask; and determine the defect label category and confidence level corresponding to the target segmentation mask based on the target segmentation mask.
[0215] In an exemplary embodiment, the inference module is further configured to: extract a query feature vector from the feature map based on the initial segmentation mask; perform a proximity search in the feature space corresponding to the labeled defect sample pool, using the query feature vector as a condition, to determine multiple labeled defect samples similar to the query feature vector as target labeled defect samples; wherein, the target labeled defect samples include sample features, sample defect category prediction results, and sample prediction masks for each labeled defect sample; determine a retrieval consistency loss value based on the query feature vector, each sample feature, and each sample defect category prediction result; determine a segmentation quality loss value based on each sample prediction mask and the sample ground truth mask of the target labeled defect samples; and iteratively update the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain the target segmentation mask.
[0216] In an exemplary embodiment, the inference module is further configured to iteratively update the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask; extract a new query feature vector from the feature map based on the new initial segmentation mask; re-perform a nearest neighbor search in the feature space corresponding to the labeled defect sample pool based on the new query feature vector to determine a new target labeled defect sample; obtain a new segmentation quality loss value and a new retrieval consistency loss value based on the new target labeled defect sample; and iteratively update the new initial segmentation mask based on the new segmentation quality loss value and the new retrieval consistency loss value until a stopping condition is met to obtain the target segmentation mask.
[0217] In an exemplary embodiment, the inference module is further configured to determine the gradient of the predicted probability value of each pixel in the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value; determine the update direction and update magnitude of the predicted probability value of each pixel in the initial segmentation mask based on the gradient; and adjust the predicted probability value of each pixel in the initial segmentation mask based on the update direction and update magnitude to obtain a new initial segmentation mask.
[0218] In an exemplary embodiment, the defect sample screening device further includes a new addition module, configured to: acquire a sample image containing the candidate new defect type when a candidate new defect type is detected, and determine the candidate new prototype feature vector corresponding to the sample image; if the difference in feature space distribution between the candidate new prototype feature vector and each prototype feature vector is greater than a new category determination threshold, use the candidate new prototype feature vector as the target new prototype feature vector; acquire a second uncertainty score for each sample image, and acquire a third uncertainty score for at least one labeled defect sample corresponding to each prototype feature vector, wherein the third uncertainty score is determined based on the first uncertainty score; based on the second uncertainty score and the third uncertainty score, determine a first storage space in the prototype memory bank for storing the target new prototype feature vector and a second storage space for storing each prototype feature vector; wherein the uncertainty score is positively correlated with the storage space; the uncertainty score includes the second uncertainty score and the third uncertainty score, and the storage space includes the first storage space and the second storage space; store the target new prototype feature vector in the first storage space, and store each prototype feature vector in the second storage space.
[0219] In an exemplary embodiment, the defect sample screening device further includes a merging module, configured to: calculate the similarity between all prototype feature vectors stored in the prototype memory when the storage space of the prototype memory reaches a preset capacity threshold; use prototype feature vectors with similarity higher than the similarity threshold as prototype feature vectors to be merged; merge the prototype feature vectors to be merged to obtain merged prototype feature vectors; delete prototype feature vectors with similarity higher than the similarity threshold from the prototype memory; and add merged prototype feature vectors to the prototype memory until the storage space of the prototype memory is less than or equal to the preset capacity threshold.
[0220] In an exemplary embodiment, the merging module is further configured to determine the merging weight of each prototype feature vector in the prototype feature vector to be merged based on the uncertainty score corresponding to each prototype feature vector to be merged; wherein the merging weight is negatively correlated with the uncertainty score; and the prototype feature vectors to be merged are weighted and averaged according to the merging weight to obtain the merged prototype feature vector.
[0221] Each module in the aforementioned defect sample screening device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the corresponding operations of each module.
[0222] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 9As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs in the non-volatile storage media to run. The database stores unlabeled defect sample data and labeled defect sample data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a defect sample screening method.
[0223] Those skilled in the art will understand that Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0224] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0225] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0226] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0227] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0228] 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 application.
[0229] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this 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 application should be determined by the appended claims.
Claims
1. A method for screening defective samples, characterized in that, The method includes: Obtain an unlabeled defect sample pool, wherein the unlabeled defect sample pool includes multiple unlabeled defect samples; For each unlabeled defect sample, calculate the model ensemble difference and prediction entropy corresponding to the unlabeled defect sample, and calculate the first uncertainty score corresponding to each unlabeled defect sample in the current round based on the model ensemble difference and the prediction entropy; wherein, the model ensemble difference indicates the degree of inconsistency between the prediction results of multiple independent deep learning models for the same input unlabeled defect sample; the prediction entropy indicates the information entropy of the average prediction probability distribution of multiple independent deep learning models for the same input unlabeled defect sample; The first uncertainty score corresponding to each unlabeled defect sample in the current round is sorted, and the unlabeled defect samples with a value greater than the dynamic threshold are determined as the current defect samples to be labeled; wherein, the dynamic threshold is determined based on the change in the performance evaluation index of the same deep learning model on the preset verification defect samples in the current round and the previous round of the current round. Based on the current defect sample to be labeled and the historical defect sample to be labeled, a target defect sample to be labeled is determined; wherein, the historical defect sample to be labeled is the defect sample to be labeled from all rounds prior to the current round.
2. The method according to claim 1, characterized in that, The calculation of the model ensemble difference and prediction entropy corresponding to the unlabeled defect samples, and the calculation of the first uncertainty score corresponding to each unlabeled defect sample in the current round based on the model ensemble difference and prediction entropy, includes: The same unlabeled defect sample is input into multiple independent deep learning models, and the defect category prediction result output by each deep learning model is obtained. Based on the prediction results of each defect category, determine the average prediction probability distribution corresponding to each defect category; The prediction entropy is determined based on the average prediction probability distributions described above; The model integration differences are determined based on the prediction results of each defect category and the average prediction probability distribution corresponding to each defect category; The model integration difference and the prediction entropy are weighted and calculated to determine the first uncertainty score corresponding to each unlabeled defect sample in the current round.
3. The method according to claim 1, characterized in that, The dynamic threshold update method includes: When the change exceeds the first preset threshold, the dynamic threshold is reduced by the first step. When the change is less than the second preset threshold, the dynamic threshold is increased by a second step size; wherein the first step size is greater than the second step size; and the first preset threshold is greater than the second preset threshold.
4. The method according to claim 1, characterized in that, After determining the target defect sample to be labeled, the method further includes: Obtain a pool of labeled defect samples determined based on the target defect sample to be labeled, and extract the prototype feature vector of each defect category from the pool of labeled defect samples; wherein, the prototype feature vector of each defect category corresponds to at least one labeled defect sample in the pool of labeled defect samples. Acquire a target image to be detected, and extract features from the target image to obtain a feature map; Based on the structural similarity between the feature map and the prototype feature vector, an initial segmentation mask is determined; The initial segmentation mask is updated to obtain the target segmentation mask; The defect label category and confidence level corresponding to the target segmentation mask are determined based on the target segmentation mask.
5. The method according to claim 4, characterized in that, The step of updating the initial segmentation mask to obtain the target segmentation mask includes: Based on the initial segmentation mask, extract the query feature vector from the feature map; Using the query feature vector as a condition, a nearest neighbor search is performed in the feature space corresponding to the labeled defect sample pool to determine multiple labeled defect samples similar to the query feature vector as target labeled defect samples; wherein, the target labeled defect sample includes the sample features, sample defect category prediction result and sample prediction mask of each labeled defect sample; Based on the query feature vector, the features of each sample, and the prediction results of the defect categories of each sample, the retrieval consistency loss value is determined; based on the prediction mask of each sample and the actual mask of the target labeled defect sample, the segmentation quality loss value is determined. The initial segmentation mask is iteratively updated based on the retrieval consistency loss value and the segmentation quality loss value to obtain the target segmentation mask.
6. The method according to claim 5, characterized in that, The step of iteratively updating the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain the target segmentation mask includes: The initial segmentation mask is iteratively updated based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask; Based on the new initial segmentation mask, extract a new query feature vector from the feature map; Based on the new query feature vector, a neighbor search is re-performed in the feature space corresponding to the labeled defect sample pool to determine new target labeled defect samples; Based on the new target-labeled defect samples, new segmentation quality loss values and new retrieval consistency loss values are obtained; The new initial segmentation mask is iteratively updated based on the new segmentation quality loss value and the new retrieval consistency loss value until the stopping condition is met to obtain the target segmentation mask.
7. The method according to claim 6, characterized in that, The step of iteratively updating the initial segmentation mask based on the retrieval consistency loss value and the segmentation quality loss value to obtain a new initial segmentation mask includes: Based on the retrieval consistency loss value and the segmentation quality loss value, determine the gradient of the predicted probability value of each pixel in the initial segmentation mask; The update direction and update magnitude of the predicted probability values of each pixel in the initial segmentation mask are determined based on the gradient. Based on the update direction and the update magnitude, the predicted probability values of each pixel in the initial segmentation mask are adjusted to obtain the new initial segmentation mask.
8. The method according to claim 4, characterized in that, The method further includes: When a candidate new defect type is detected, a sample image containing the candidate new defect type is obtained, and the candidate new prototype feature vector corresponding to the sample image is determined. If the difference in feature space distribution between the candidate new prototype feature vector and each prototype feature vector is greater than the new category determination threshold, the candidate new prototype feature vector shall be used as the target new prototype feature vector. A second uncertainty score is obtained for each of the sample images, and a third uncertainty score is obtained for at least one labeled defect sample corresponding to each of the prototype feature vectors, wherein the third uncertainty score is determined based on the first uncertainty score; Based on the second uncertainty score and the third uncertainty score, a first storage space for storing the newly added prototype feature vectors of the target and a second storage space for storing each of the prototype feature vectors are determined in the prototype memory; wherein, the uncertainty score is positively correlated with the storage space; the uncertainty score includes the second uncertainty score and the third uncertainty score, and the storage space includes the first storage space and the second storage space; The newly added prototype feature vector of the target is stored in the first storage space, and each prototype feature vector is stored in the second storage space.
9. The method according to claim 8, characterized in that, The method further includes: When the storage space of the prototype memory reaches a preset capacity threshold, the similarity between all prototype feature vectors stored in the prototype memory is calculated. The prototype feature vectors with similarity higher than the similarity threshold are used as prototype feature vectors to be merged. The prototype feature vectors to be merged are combined to obtain the merged prototype feature vector; The prototype feature vectors with similarity higher than the similarity threshold are deleted from the prototype memory, and the merged prototype feature vectors are added to the prototype memory until the storage space of the prototype memory is less than or equal to the preset capacity threshold.
10. The method according to claim 9, characterized in that, The process of merging the prototype feature vectors to be merged to obtain the merged prototype feature vector includes: Based on the uncertainty scores corresponding to the prototype feature vectors to be merged, the merging weight of each prototype feature vector is determined; wherein, the merging weight is negatively correlated with the uncertainty score. The merged prototype feature vector is obtained by weighting the prototype feature vectors to be merged according to the merging weights.
