Appearance defect detection method based on dominant sample

By evaluating the importance of samples based on crossover and IoU in the defect detection model and adjusting the weight of the loss function, the model bias and overfitting problems caused by sample imbalance are solved, and the generalization ability and training efficiency of the model are improved.

CN119445275APending Publication Date: 2025-02-14INST OF INTELLIGENT MFG GUANGDONG ACAD OF SCI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411331916.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-23
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

When existing defect detection models deal with the problem of sample imbalance, they are prone to model bias, overfitting or insufficient generalization capabilities. Especially in the detection of appearance defects of bottled products, there are more samples in common defect categories, but more The rare defect category has fewer samples, resulting in poor performance of the model in rare defect categories.

Method used

By evaluating the importance of the sample based on the intersection between the sample and the real target, sorting the samples, and adjusting the loss function according to the importance, giving high IoU samples higher loss function weights, thus making the model more Focus on high IoU samples.

Benefits of technology

This method allows the model to learn important features more quickly and effectively, improve training efficiency, avoid overfitting the model to specific difficult samples, and maintain the generalization ability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119445275A_ABST
    Figure CN119445275A_ABST
Patent Text Reader

Abstract

The invention relates to a dominant sample-based product appearance defect detection method, which comprises the following steps of: evaluating the importance degree of a sample on the basis of the intersection-to-union ratio IoU between the sample and a real target, and sequencing the importance degree of the sample; the loss function is adjusted according to the importance degree of the samples, and a higher loss function weight is distributed to the samples with the high importance degree. A high-IoU sample is used as a dominant sample. By modifying the loss function, a dominant sample with higher intersection-to-union ratio than IoU can obtain more attention of the model. Because the high IoU sample is closer to a real target, the contained information quality is higher, the noise is less, and the features learned from the samples by the model are more reliable. Therefore, compared with the prior art, more attention is paid to'difficult samples', attention is put on the high IoU samples, so that the model can learn important features more quickly and effectively, and the training efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of defect detection, and in particular to an appearance defect detection method based on a leading sample. Background Art

[0002] In target detection, sample imbalance is a common and important problem, which refers to the significant difference in the number of samples of different categories in the training data set. In the task of detecting appearance defects of bottled drinks, the problem of sample imbalance is also very obvious. For example, in bottled products, defects in the category of "breakage" are more common, while "wrinkles" are relatively rare and only account for a small part of the defective samples. This is the imbalance of defect categories. This situation will cause the model to tend to predict categories with a larger number of samples, so that the accuracy on such samples is higher, and the performance on categories with fewer samples is poor. Therefore, the model may be biased against certain categories, causing inaccuracies or unfairness in actual detection, which in turn affects the generalization ability of the model and even causes overfitting.

[0003] In the existing defect detection solutions, the methods and defects for solving sample imbalance are as follows:

[0004] ① Process the data set by oversampling and undersampling. Oversampling is to repeatedly sample minority class samples so that their number increases to the same level as majority class samples. Undersampling, on the other hand, is to reduce the number of majority class samples. Although these two methods are simple and direct, their disadvantages are also obvious: oversampling will increase the size of the training data set, thereby increasing training time and computational costs. In addition, repeated samples may cause the model to overfit. Undersampling will lose majority class samples, resulting in insufficient model learning of the majority class, which in turn affects the overall model performance.

[0005] ② Use OHEM (Online Hard Example Mining). OHEM is a sample selection strategy that selects samples with large losses as "difficult samples". Such samples are often difficult to locate and classify, and need to be trained intensively. However, the disadvantage is that OHEM may select wrong prediction results as difficult samples for prediction, which will have a great impact on the subsequent training of the model.

[0006] ③Focal Loss, which adjusts the weight of the loss function by introducing a balance factor, so that the model pays more attention to difficult-to-classify samples during training while weakening the influence of easy-to-classify samples on the model. Its defect is similar to OHEM, that is, it pays too much attention to difficult samples. There are always abnormal samples (outliers or noise) or mispredicted samples in the training set. Although these samples are difficult to classify, they are not the objects that need to be focused on. Summary of the invention

[0007] In view of this, it is necessary to provide an appearance defect detection method based on a dominant sample to solve the above-mentioned defects of the prior art.

[0008] In order to solve the above problems, in a first aspect, an embodiment of the present invention provides an appearance defect detection method based on a dominant sample, comprising:

[0009] Step S1, evaluating the importance of samples based on the intersection over union (IoU) ratio between samples and true targets, and ranking the importance of samples;

[0010] Step S2, adjust the loss function according to the importance of the samples, and assign a higher loss function weight to samples with high importance.

[0011] Preferably, in step S1, evaluating the importance of samples based on the intersection over union (IoU) ratio between samples and true targets and ranking the importance of samples include:

[0012] Determine the mAP performance indicator for target detection, and analyze the impact of different types of samples on the mAP performance indicator; the sample types include: True Positive: actual positive samples that the model correctly predicts as positive samples; True Negative: actual negative samples that the model correctly predicts as negative samples; False Positive: actual negative samples that the model incorrectly predicts as positive samples; False Negative: actual positive samples that the model incorrectly predicts as negative samples;

[0013] For the True Positive samples and False Positive samples that affect the performance index mAP, the intersection over union (IoU) between the samples and the true targets is obtained, and the importance of the samples is ranked according to the size of the intersection over union (IoU).

[0014] Preferably, the analysis of the impact of different types of samples on the performance indicator mAP includes:

[0015] The mean average precision mAP is related to the precision rate Precision and the recall rate Recall, where the expressions of precision rate and recall rate are:

[0016]

[0017] In the formula, TP is True Positive, FP is False Positive, and FN is False Negative;

[0018] From the expressions of precision and recall, we can see that True Positive samples have an impact on precision and recall, False Positive samples have an impact on precision, and False Negative has an impact on recall.

[0019] Preferably, the importance ranking process of the True Positive samples includes:

[0020] Get True Positive samples and divide them into several groups according to the distance between the predicted box and the true target box;

[0021] In the group, the importance of True Positive samples is sorted from high to low according to the intersection over union (IoU) ratio from large to small;

[0022] A pairwise comparison of the intersection over union (IoU) is performed between each group to obtain the final True Positive sample importance ranking.

[0023] Preferably, in step S1, evaluating the importance of samples based on the intersection-over-union ratio (IoU) between the samples and the true targets and ranking the importance of the samples further comprises:

[0024] Sort the importance of the specified number of samples with the highest intersection over union (IoU), and randomly sort the importance of the remaining samples.

[0025] Preferably, in step S2, adjusting the loss function according to the importance of the samples includes:

[0026] S21, converting the importance ranking of samples into importance values ​​through linear transformation;

[0027]

[0028] In the formula, u i Represents the importance of the i-th sample in the j-th defect category; r i Indicates the ranking of the i-th sample, n max represents the number of samples that generate the most prediction samples among all defect categories;

[0029] S22, converting the importance value into a loss function weight, and assigning a higher loss function weight to samples with higher importance;

[0030] S23, normalize the loss function weights to ensure the numerical stability of the loss function.

[0031] S24, combines the number of positive and negative samples, model predictions and true labels to form the final loss function.

[0032] Preferably, in step S22, converting the importance value into a loss function weight includes:

[0033] The loss function weight w is obtained by the importance value i The expression is:

[0034] w i =((1-β)u i +β) γ

[0035] In the formula, w i is the loss function weight of sample i, β and γ are hyperparameters, β represents the bias, and γ represents the degree of attention paid by the loss function to important samples.

[0036] In step S24, the final loss function is:

[0037]

[0038] In the formula, Loss is the loss function, n and m represent the number of positive and negative samples respectively, and s i and Represent the model prediction and true label of positive sample i, s j and Respectively represent the model prediction and true label of negative sample j; w' i represents the loss function weight of sample i after normalization, w' j represents the loss function weight of sample i after normalization, and CE (CrossEntropy) represents the cross entropy loss.

[0039] In a second aspect, an embodiment of the present invention provides an appearance defect detection system based on a dominant sample, comprising:

[0040] The importance ranking module is used to evaluate the importance of samples based on the intersection over union (IoU) ratio between samples and true targets, and to rank the importance of samples;

[0041] The loss function adjustment module is used to adjust the loss function according to the importance of the samples and assign higher loss function weights to samples with high importance.

[0042] In a third aspect, the present invention further provides an electronic device, including a memory and a processor, wherein:

[0043] The memory is used to store programs;

[0044] The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the appearance defect detection method based on the dominant sample as described in the embodiment of the first aspect of the present invention.

[0045] In a fourth aspect, the present invention further provides a computer-readable storage medium for storing computer-readable programs or instructions, which, when executed by a processor, can implement the steps in the appearance defect detection method based on a dominant sample as described in the embodiment of the first aspect of the present invention.

[0046] The appearance defect detection method based on dominant samples provided by the present invention evaluates the importance of samples based on the intersection-over-union (IoU) ratio between samples and true targets, sorts the importance of samples, and uses high IoU samples as dominant samples. By modifying the loss function, dominant samples with higher intersection-over-union (IoU) ratios can obtain more attention from the model. Since high IoU samples are closer to the true targets, the information they contain is of higher quality and has less noise, the features learned by the model from these samples are more reliable. Therefore, compared to the prior art that pays more attention to "difficult samples", the present invention focuses on high IoU samples, which allows the model to learn important features more quickly and effectively, thereby improving training efficiency. At the same time, it can avoid overfitting the model to specific difficult samples and maintain the generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A flow chart of the appearance defect detection method based on the leading sample provided by the present invention;

[0048] Figure 2 The Precision-Recall curve provided by the present invention;

[0049] Figure 3 A schematic diagram of the importance ranking of True Positive samples in the bottled product defect detection provided by the present invention;

[0050] Figure 4 A schematic diagram of the importance ranking of False Positive samples in the bottled product defect detection provided by the present invention;

[0051] Figure 5 A structural block diagram of the appearance defect detection system based on the leading sample provided by the present invention;

[0052] Figure 6 This is a structural block diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0053] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings, wherein the accompanying drawings constitute a part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not used to limit the scope of the present invention.

[0054] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0055] At present, existing defect detection models usually assume that all samples contribute independently and equally to the overall performance, with the goal of maximizing the average performance. But in fact, not all samples contribute equally to the final mAP, and some samples may be more important to improving model performance. The proposers of Focal Loss and OHEM obviously noticed this, and adjusted the loss function and sample selection strategy respectively to make the model pay more attention to specific samples. But both Focal Loss and OHEM have a misunderstanding, that is, they directly believe that "difficult samples" with large loss, difficult to classify and locate are those that play a dominant role in training. It is true that paying more attention to difficult samples can alleviate the problem of sample imbalance. However, difficult samples include outliers and noise. Paying too much attention to such samples will cause the model to learn wrong features and affect the overall performance. Secondly, difficult samples often require more computing resources to process, because the features of difficult samples are generally complex and changeable, and more iterations are required to correctly classify them during the training process, which will extend the entire training cycle and increase the training cost. Moreover, complex features may cause large fluctuations in loss during training, unstable model parameter updates, and increase uncertainty in the training process. The easy-to-classify samples that are finally fixed are easy to process, but they play an important role in helping the model learn the overall distribution and basic characteristics of the data. Completely ignoring these samples may cause the model to have insufficient understanding of the overall distribution of the data.

[0056] Different from undersampling or oversampling, which directly adjusts the data set, the detection method based on sample sorting proposed in this patent belongs to a sample selection strategy. The present invention does not take the training premise that all samples contribute equally to the model performance, but believes that some samples play a leading role in the results of model training during the training process, and pays more attention to these leading samples. The method focusing on the leading samples can make more efficient use of training data and improve the efficiency of model training.

[0057] The present invention considers that samples with high IoU (Intersection over Union) with the ground truth, i.e., samples with a high degree of overlap with the ground truth, are the dominant samples of the model. The dominant samples have a significant impact on the effect of model training, and paying more attention to these samples is conducive to improving the performance of the model. Finding these dominant samples by the sample sorting method can make more efficient use of training data, while avoiding overfitting or information loss caused by oversampling and undersampling.

[0058] In view of this, the present invention provides an appearance defect detection method based on dominant samples, and the predicted samples near the real target are arranged according to the intersection-over-union ratio (IoU), and the sample with the largest IoU with the real target is ranked first, the second is the second highest, and so on. At the same time, the samples in some positions are randomly sorted so that the model obtains more diverse features. The higher the ranking of the samples in the sequence, the higher the attention they receive. This patent considers these top-ranked samples to be dominant samples. High IoU samples are closer to the real target, contain higher quality information, and have less noise, so the features learned by the model from these samples are more reliable. This allows the model to learn important features more quickly and effectively, thereby improving training efficiency. Paying attention to high IoU samples can avoid overfitting the model to specific difficult samples and maintain the generalization ability of the model. The following will be explained and introduced through multiple embodiments.

[0059] Figure 1 This is a flow chart of the appearance defect detection method based on the leading sample provided by the present invention. Figure 1 As shown, the appearance defect detection method based on the leading sample at least includes steps S1 to S2, wherein:

[0060] Step S1, evaluate the importance of samples based on the intersection over union (IoU) between samples and true targets, and rank the importance of samples.

[0061] This embodiment takes bottled products as the research object, and solves the problem of sample imbalance in the bottled product appearance defect data set by sorting the samples.

[0062] Step S1 may specifically include the following steps S11 to S12;

[0063] S11, determine the performance indicator mAP of target detection, and analyze the impact of different types of samples on the performance indicator mAP.

[0064] Among them, mAP (meanAverage Precision) is an important indicator for measuring the performance of the target detection model. It comprehensively considers the precision and recall of the model, and can more comprehensively reflect the average detection performance of the model in different categories. In this embodiment, mAP is used as the performance indicator of target detection.

[0065] Generally, the samples predicted by the target detection model are divided into the following four categories: True Positive: actual positive samples that the model correctly predicts as positive samples; True Negative: actual negative samples that the model correctly predicts as negative samples; False Positive: actual negative samples that the model incorrectly predicts as positive samples; False Negative: actual positive samples that the model incorrectly predicts as negative samples.

[0066] The expressions of precision and recall are:

[0067]

[0068] In the formula, TP is True Positive, FP is False Positive, and FN is False Negative;

[0069] From formula (1), we can see that precision represents the proportion of all instances predicted by the model as positive samples that are actually positive samples, while recall represents the proportion of all instances that are actually positive samples that are correctly predicted by the model as positive samples. Figure 2 The Precision-Recall curve provided by the present invention is as follows: Figure 2 As shown in the figure, the relationship curves are drawn at different confidence thresholds with precision and recall as the horizontal and vertical coordinates (only samples exceeding the confidence threshold are considered positive samples). Each point in the Precision-Recall curve corresponds to a specific confidence threshold. The area enclosed by the curve and the coordinate axis is the AP (Average Precision) of this category. The average precision of all categories is mAP.

[0070] According to the expressions of precision and recall, we analyze the impact of different types of samples on the performance indicator mAP. We can know that True Positive samples have an impact on precision and recall, False Positive samples have an impact on precision, and False Negative has an impact on recall.

[0071] S12, for the True Positive samples and False Positive samples that affect the performance index mAP, obtain the intersection over union (IoU) between the samples and the true targets, and sort the importance of the samples according to the size of the intersection over union (IoU).

[0072] Specifically, according to formulas (1) and (2), True Positive appears in the numerator of the calculation formula of precision and recall, so the change in the number of True Positive has a direct impact on both precision and recall. Therefore, if you want to improve mAP, you need to pay more attention to True Positive.

[0073] Figure 3 This is a schematic diagram of the importance ranking of True Positive samples in the bottled product defect detection provided by the present invention. Figure 3 , the importance ranking process of True Positive samples includes:

[0074] First, get the True Positive samples and divide them into several groups according to the distance between the predicted box and the true target box. Figure 3 As shown in the figure, there are two damaged parts in the bottled product. The location marked by the red dotted box is the damaged part, or the location of the ground truth. The object detection model also generates corresponding predictions around the ground truth. Figure 3 The confidence and IoU of the prediction boxes A to E exceed the threshold (threshold = 0.5), which means that these six prediction boxes are all True Positive. In this embodiment, the six prediction boxes are divided into two groups according to the distance between the prediction box and the true target box, namely Figure 3 Group 1 and Group 2 in .

[0075] Then, within the group, the importance of the True Positive samples is sorted from high to low according to the intersection over union (IoU) ratio. Among them, IoU (Intersection over Union) represents the degree of overlap between the predicted box and the ground truth. The higher the IoU value, the larger the overlap area between the predicted box and the ground truth, and the more accurate the prediction.

[0076] Furthermore, the groups are compared by the intersection over union (IoU) ratio. In this embodiment, the ratio of the highest IoU to the highest, the second highest IoU to the second highest, and so on is compared. After the comparison is completed, the importance ranking of the True Positive samples is obtained.

[0077] From the influence of different types of samples on the performance index mAP obtained by analyzing step S11, it can be seen that in addition to TruePositive samples, FalsePositive samples and FalseNegative samples will also affect the precision and recall rate respectively. FalsePositive is a positive sample that is incorrectly identified, which is a false alarm. FalseNegative is a negative sample that is incorrectly identified, which is a missed alarm. Generally speaking, false alarms are more harmful to the model than missed alarms, so the embodiments of the present invention pay more attention to FalsePositive.

[0078] Although the confidence of False Positive exceeds the threshold, the overlap with the real target is low and contains more background areas, which is not conducive to model detection and reduces Precision. On the other hand, False Positive can also help the model better distinguish between foreground and background. Paying more attention to False Positive with relatively high IoU is conducive to the model to reduce false positives, learn more general features, and improve the generalization ability of the model in different scenarios. Therefore, this embodiment sorts False Positive.

[0079] Figure 4 This is a schematic diagram of the importance ranking of False Positive samples in the bottled product defect detection provided by the present invention, referring to Figure 4 , the importance ranking principle of False Positive samples is Figure 3 The principle of sorting True Positive samples is the same as that of the previous one, which is also based on the IoU size. It should be noted that False Positive samples with lower IoU will be processed by NMS (Non-Maximum Suppression) in the post-processing stage. Therefore, there is no need to pay too much attention to False Positive samples with lower IoU.

[0080] Step S2, adjust the loss function according to the importance of the samples, and assign a higher loss function weight to samples with high importance.

[0081] Step S2 may specifically include the following steps S21 to S24;

[0082] S21, converting the importance ranking of samples into importance values ​​through linear transformation;

[0083]

[0084] In the formula, u i represents the importance of the i-th sample in the j-th defect category; ri Indicates the ranking of the i-th sample, n max This represents the importance of the i-th sample in the "broken" category.

[0085] In this embodiment, u i Indicates the importance of the i-th sample in the defect category of "broken". If the number of prediction samples generated by the "broken" category is 30, and it generates the most prediction samples among all categories, then n max =30.

[0086] S22, converts the importance value into a loss function weight, and assigns a higher loss function weight to samples with higher importance.

[0087] Specifically, the loss function weight w is obtained by the importance value i The expression is:

[0088] w i =((1-β)u i +β) γ (4)

[0089] In the formula, w i is the loss function weight of sample i, β and γ are hyperparameters, β represents the bias, and γ represents the degree of attention paid by the loss function to important samples.

[0090] In this embodiment, the loss function of the target detection model for bottled product defects is improved according to the order of sample importance, and a higher weight is assigned to the dominant samples, so that the model can pay more attention to these samples during the training process. And through this improved loss function design, the performance of the model in bottled product defect detection is enhanced in the case of unbalanced samples.

[0091] S23, normalize the loss function weights to ensure the numerical stability of the loss function.

[0092]

[0093] In the formula, s i and Represent the model prediction and true label of positive sample i, s j and Respectively represent the model prediction and true label of negative sample j; w' i represents the loss function weight of sample i after normalization, w' j represents the loss function weight of sample i after normalization, and CE (Cross Entropy) represents the cross entropy loss.

[0094] In this embodiment, considering that directly adding weights will change the ratio between the positive and negative sample losses, it is necessary to normalize the weights of the loss function. Specifically, in order to ensure the numerical stability of the loss function, after summing the weighted losses of all samples, the weight of the i / jth sample is divided by the sum of all weights. This normalization process ensures that the output of the loss function does not appear too large or too small due to the introduction of weights, while maintaining the relative contribution of different samples to the total loss.

[0095] S24, combines the number of positive and negative samples, model predictions and true labels to form the final loss function.

[0096] In step S24, the final loss function is:

[0097]

[0098] In the formula, Loss is the loss function, n and m represent the number of positive and negative samples respectively. They represent the model's prediction and true label respectively, and the cross entropy is used to measure the difference between them.

[0099] The appearance defect detection method based on dominant samples provided by the present invention evaluates the importance of samples based on the intersection-over-union (IoU) ratio between samples and true targets, sorts the importance of samples, and uses high IoU samples as dominant samples. By modifying the loss function, dominant samples with higher intersection-over-union (IoU) ratios can obtain more attention from the model. Since high IoU samples are closer to the true targets, the information they contain is of higher quality and has less noise, the features learned by the model from these samples are more reliable. Therefore, compared to the prior art that pays more attention to "difficult samples", the present invention focuses on high IoU samples, which allows the model to learn important features more quickly and effectively, thereby improving training efficiency. At the same time, it can avoid overfitting the model to specific difficult samples and maintain the generalization ability of the model.

[0100] In actual operation, if all samples are sorted by importance according to IoU, it will lead to the defect of a single sorting index. To address this problem. In a preferred embodiment of the present invention, in step S1, the importance of samples is evaluated based on the intersection-over-union ratio (IoU) between the samples and the real targets, and the importance of samples is sorted, and the following steps are also included:

[0101] Sort the importance of the specified number of samples with the highest intersection over union (IoU), and randomly sort the importance of the remaining samples.

[0102] It is understandable that if the importance ranking of samples is determined only by the level of IoU, and the ranking itself is related to the weight of the loss function. This will cause the model to only pay attention to samples ranked by IoU in each round of training. Although paying attention to these samples can effectively improve the mAP of the model, this single ranking method may cause the model to ignore the diversity of samples. For example, although the IoU of some samples is relatively low, it contains rich features, and these samples are also worthy of our attention. For example Figure 3 Sample D in Group 2 has an IoU of only 0.33, but this sample is at the edge of the target and contains transition features between the target and the background. Such features can help the model distinguish boundaries, so this patent decides to optimize the sorting rules. Figure 4 As shown in the figure, except for the samples E, D, and C with the highest relative IoU in the two groups, the samples in the remaining positions are randomly sorted. This helps the model learn more diverse features while retaining the focus on high IoU samples.

[0103] Figure 5 The structural block diagram of the appearance defect detection system based on the leading sample provided by the present invention is shown in FIG. Figure 5 , the appearance defect detection system 500 based on the dominant sample includes:

[0104] An importance ranking module 501 is used to evaluate the importance of samples based on the intersection-over-union ratio (IoU) between the samples and the true targets, and to rank the importance of the samples;

[0105] The loss function adjustment module 502 is used to adjust the loss function according to the importance of the samples and assign a higher loss function weight to samples with higher importance.

[0106] The appearance defect detection system based on dominant samples provided by the present invention executes the appearance defect detection method based on dominant samples provided by the above-mentioned embodiments through the above-mentioned modules. The appearance defect detection method based on dominant samples has been described in detail in the above-mentioned embodiments, and will not be repeated in this embodiment.

[0107] Figure 6 The structural block diagram of the electronic device provided by the present invention is as follows: Figure 6 As shown, the present invention also provides an electronic device, and the electronic device 600 can be a computing device such as a mobile terminal, a desktop computer, a notebook, a PDA, and a server. The electronic device 600 includes a processor 601 and a memory 602, wherein the memory 602 stores an appearance defect detection program 603 based on a dominant sample.

[0108] In some embodiments, the memory 602 may be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the memory 602 may also be an external storage device of the computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. Further, the memory 602 may also include both an internal storage unit of the computer device and an external storage device. The memory 602 is used to store application software and various types of data installed on the computer device, such as program codes for installing the computer device. The memory 602 can also be used to temporarily store data that has been output or is to be output. In one embodiment, when the appearance defect detection program 603 based on the dominant sample is executed by the processor 601, the following steps are implemented:

[0109] Step S1, evaluating the importance of samples based on the intersection over union (IoU) ratio between samples and true targets, and ranking the importance of samples;

[0110] Step S2, adjust the loss function according to the importance of the samples, and assign a higher loss function weight to samples with high importance.

[0111] In some embodiments, the processor 601 may be a central processing unit (CPU), a microprocessor or other data processing chip, used to run program codes or process data stored in the memory 602, such as executing an appearance defect detection program based on a dominant sample.

[0112] This embodiment further provides a computer-readable storage medium, on which a dominant sample-based appearance defect detection program is stored. When the dominant sample-based appearance defect detection program is executed by a processor, the following steps are implemented:

[0113] Step S1, evaluating the importance of samples based on the intersection over union (IoU) ratio between samples and true targets, and ranking the importance of samples;

[0114] Step S2, adjust the loss function according to the importance of the samples, and assign a higher loss function weight to samples with high importance.

[0115] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

[0116] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for detecting appearance defects based on a dominant sample, characterized in that: include: Step S1, evaluating the importance of samples based on the intersection over union (IoU) ratio between samples and true targets, and ranking the importance of samples; Step S2, adjust the loss function according to the importance of the samples, and assign a higher loss function weight to samples with high importance.

2. The appearance defect detection method based on the dominant sample according to claim 1 is characterized in that: In step S1, the importance of the samples is evaluated based on the intersection over union (IoU) ratio between the samples and the true targets, and the importance of the samples is ranked, including: Determine the mAP performance indicator for target detection, and analyze the impact of different types of samples on the mAP performance indicator; the sample types include: True Positive: actual positive samples that the model correctly predicts as positive samples; True Negative: actual negative samples that the model correctly predicts as negative samples; False Positive: actual negative samples that the model incorrectly predicts as positive samples; False Negative: actual positive samples that the model incorrectly predicts as negative samples; For the True Positive samples and False Positive samples that affect the performance index mAP, the intersection over union (IoU) between the samples and the true targets is obtained, and the importance of the samples is ranked according to the size of the intersection over union (IoU).

3. The appearance defect detection method based on the dominant sample according to claim 2 is characterized in that: The analysis of the impact of different types of samples on the performance indicator mAP includes: The mean average precision mAP is related to the precision rate Precision and the recall rate Recall, where the expressions of precision rate and recall rate are: In the formula, TP is True Positive, FP is False Positive, and FN is False Negative; From the expressions of precision and recall, we can see that True Positive samples have an impact on precision and recall, False Positive samples have an impact on precision, and False Negative has an impact on recall.

4. The appearance defect detection method based on the dominant sample according to claim 2 is characterized in that: The importance ranking process of the TruePositive samples includes: Get True Positive samples and divide them into several groups according to the distance between the predicted box and the true target box; In the group, the importance of True Positive samples is sorted from high to low according to the intersection over union (IoU) ratio from large to small; A pairwise comparison of the intersection over union (IoU) is performed between each group to obtain the final True Positive sample importance ranking.

5. The appearance defect detection method based on the dominant sample according to claim 2 is characterized in that: In step S1, the importance of the samples is evaluated based on the intersection over union (IoU) ratio between the samples and the true targets, and the importance of the samples is ranked, which also includes: Sort the importance of the specified number of samples with the highest intersection over union (IoU), and randomly sort the importance of the remaining samples.

6. The method for detecting appearance defects based on a dominant sample according to claim 1, characterized in that: In step S2, the loss function is adjusted according to the importance of the samples, including: S21, converting the importance ranking of samples into importance values ​​through linear transformation; In the formula, u i represents the importance of the i-th sample in the j-th defect category; t i Indicates the ranking of the i-th sample, n amx represents the number of samples that generate the most prediction samples among all defect categories; S22, converting the importance value into a loss function weight, and assigning a higher loss function weight to samples with higher importance; S23, normalize the loss function weights to ensure the numerical stability of the loss function. S24, combines the number of positive and negative samples, model predictions and true labels to form the final loss function.

7. The method for detecting appearance defects based on a dominant sample according to claim 6, characterized in that: In step S22, converting the importance value into a loss function weight includes: The loss function weight w is obtained by the importance value i The expression is: w i =((1-β)u i +b) γ In the formula, w i is the loss function weight of sample i, β and γ are hyperparameters, β represents the bias, and γ represents the degree of attention paid by the loss function to important samples. In step S24, the final loss function is: In the formula, Loss is the loss function, n and m represent the number of positive and negative samples respectively, and s i and Represent the model prediction and true label of positive sample i, s j and Respectively represent the model prediction and true label of negative sample j; w' i represents the loss function weight of sample i after normalization, w' j represents the loss function weight of sample i after normalization, and CE represents the cross entropy loss.

8. An appearance defect detection system based on a dominant sample, characterized in that: include: The importance ranking module is used to evaluate the importance of samples based on the intersection over union (IoU) ratio between samples and true targets, and to rank the importance of samples; The loss function adjustment module is used to adjust the loss function according to the importance of the samples and assign higher loss function weights to samples with high importance.

9. An electronic device, It is characterized in that comprising a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps of the appearance defect detection method based on the dominant sample as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store computer-readable programs or instructions, which, when executed by a processor, can implement the steps of the appearance defect detection method based on a dominant sample as described in any one of claims 1 to 7.