A method for unbalanced abnormal image detection based on positive sample induction
By adopting the unbalanced abnormal image detection method induced by positive samples in industrial quality inspection, using positive sample classification score induced loss and feature contrast loss, combined with negative sample subset division and model integration, the problem of inconsistency between positive and negative samples in industrial quality inspection is solved. Balancing the issues of variability and abnormal region variability enables efficient abnormal image detection.
Patent Information
- Application Number
- CN202210305558.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-25
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-03-25
AI Technical Summary
In industrial quality inspection, due to the low frequency of abnormal workpieces, resulting in the problem of imbalance between positive and negative samples, it is difficult to effectively detect abnormal images with existing technology, especially the abnormal areas with variable locations, different scales, and diverse shapes, which increases the difficulty of detection. Difficulty.
An imbalanced abnormal image detection method based on positive sample induction is adopted. By introducing positive sample classification score induction loss and positive sample feature contrast loss, the deep neural network model is trained, forcing the classifier to have a margin for positive samples and focus on abnormal areas, combined with negative samples Subset division and model integration improve the effectiveness and accuracy of detection.
It effectively alleviates the imbalance problem, improves the accuracy and effectiveness of abnormal image detection, ensures the classifier's effective attention and feature expression of abnormal areas, and improves the detection performance in the case of very few positive samples.
Smart Images

Figure CN114742773B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing, and more specifically, relates to an unbalanced abnormal image detection method based on positive sample induction. Background Art
[0002] Industrial quality inspection is an important step for products to leave the factory or for workpieces to enter the next production cycle. It is necessary to detect abnormal products that are different from normal products (or workpieces), which are often damaged by defects such as surface damage during the production process. Image processing technology is often used in industrial quality inspection. The industrial cameras are arranged to collect images of the parts to be inspected, and the collected images are processed and analyzed to determine whether they are abnormal parts, to assist manual quality inspection and thus improve production efficiency.
[0003] In the actual production process, due to the low frequency of abnormal workpieces, the number of images collected of abnormal workpieces is far less than the number of images of normal workpieces. Therefore, in the actual quality inspection scenario, the problem of imbalance between positive and negative samples arises, and general classification methods or unsupervised abnormal image detection methods often find it difficult to solve such problems. At the same time, due to the low controllability and high complexity of the production process, the problems that cause product or workpiece abnormalities are often different, resulting in the abnormal areas in the collected abnormal images being variable in position, scale, shape, etc., which further increases the difficulty of abnormal image detection. Summary of the invention
[0004] In view of the defects and improvement needs of the prior art, the present invention provides an unbalanced abnormal image detection method based on positive sample induction, which aims to solve the problem of imbalance between positive and negative samples in actual scenarios.
[0005] To achieve the above objectives, in a first aspect, the present invention provides a training method for an unbalanced abnormal image detection model based on positive sample induction, comprising:
[0006] Determine a training sample set, where samples in the training sample set are labeled training images; wherein a label of 0 represents a negative sample, and a label of 1 represents a positive sample;
[0007] According to the training sample set, the initial neural network is trained by a loss function to obtain an abnormal image detection model;
[0008] Among them, the loss function l PLI It is expressed as:
[0009]
[0010] Where N b represents the total number of training samples in a batch, x i and iRespectively represent the i-th training image and the corresponding label in the batch of training samples, y i is 0 or 1, p0 and p1 represent the frequencies of negative and positive samples in the batch of training samples, respectively, and f θ (x i )[0] and f θ (x i )[1] represent the classification scores of predicting the i-th training image as a negative sample and a positive sample, respectively.
[0011] In a second aspect, the present invention provides a training method for an unbalanced abnormal image detection model based on positive sample induction, comprising:
[0012] Determine a training sample set, where samples in the training sample set are labeled training images; wherein a label of 0 represents a negative sample, and a label of 1 represents a positive sample;
[0013] According to the training sample set, the initial neural network is trained by a loss function to obtain an abnormal image detection model;
[0014] Among them, the loss function l PSI It is expressed as:
[0015] l PSI = l PLI +λ·l PFC
[0016]
[0017]
[0018]
[0019] In the formula, l PLI represents the positive sample classification score induced loss, N b represents the total number of training samples in a batch, x i and i Respectively represent the i-th training image and the corresponding label in the batch of training samples, y i is 0 or 1, p0 and p1 represent the frequencies of negative and positive samples in the batch of training samples, respectively, and f θ (x i )[0] and f θ (x i )[1] represent the classification scores of predicting the i-th training image as a negative sample and a positive sample respectively; l PFC represents the positive sample feature contrast loss, N b0 Indicates the number of negative samples in the batch of training samples, F θ Represents the neural network f θThe extracted features; λ represents the loss adjustment weight.
[0020] In a third aspect, the present invention provides an unbalanced abnormal image detection method based on positive sample induction, comprising:
[0021] Acquire the image to be detected;
[0022] Predicting the abnormality score of the image to be detected by using the abnormal image detection model trained by the training method of the unbalanced abnormal image detection model based on positive sample induction as described in the first aspect or the second aspect;
[0023] The image to be detected whose abnormality score is greater than the score threshold is identified as an abnormal image.
[0024] Further, the negative samples in the training sample set are equally divided into K parts to obtain K negative sample subsets, and the positive samples in the training sample set are added to each of the negative sample subsets to form K new training sample sets;
[0025] According to each of the new training sample sets, a corresponding abnormal image detection model is trained;
[0026] The abnormality score of the image to be detected is predicted according to the K trained abnormal image detection models.
[0027] Furthermore, the average of the anomaly scores predicted by the K trained anomaly image detection models is used as the anomaly score of the image to be detected.
[0028] In a fourth aspect, the present invention provides a training system for an unbalanced abnormal image detection model induced by positive samples, comprising: a computer-readable storage medium and a processor;
[0029] The computer-readable storage medium is used to store executable instructions;
[0030] The processor is used to read the executable instructions stored in the computer-readable storage medium and execute the method as described in the first aspect or the second aspect.
[0031] In a fifth aspect, the present invention provides an unbalanced abnormal image detection system based on positive sample induction, comprising: a computer-readable storage medium and a processor;
[0032] The computer-readable storage medium is used to store executable instructions;
[0033] The processor is used to read the executable instructions stored in the computer-readable storage medium and execute the method as described in the third aspect.
[0034] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:
[0035] (1) The positive sample classification score induced loss function proposed in this invention introduces the sample label frequency to force the classifier to have at least The margin of is tested, so the imbalance problem can be effectively alleviated; at the same time, the positive samples are continuously optimized by introducing label information. In this way, the back propagation loss of the sample is constrained in terms of label frequency and positive samples continuously encouraging parameter optimization, and the deep neural network f is adjusted. θ The parameter θ is used to effectively express features and expand the classification margin.
[0036] (2) Based on the positive sample classification score induced loss, the present invention takes into account the problems of variable positions, different scales, and diverse shapes of abnormal regions in the image, and proposes a positive sample feature contrast loss, so that during the training process, the distance relationship between positive and negative samples in the feature space is constrained, forcing positive samples to be far away from negative samples in the feature space. In this way, the effectiveness of the classifier is guaranteed and the deep neural network is guided to pay more attention to the abnormal region itself, further improving the effectiveness of unbalanced abnormal image detection.
[0037] (3) The present invention divides the negative samples in the training sample set into K equal parts to obtain K negative sample subsets, and then adds all the positive samples in the training sample set to each negative sample subset to form K new training sample sets; according to each new training sample set, the corresponding abnormal image detection model is trained; finally, in the inference stage, the models trained by all new training sample sets are integrated for detection. Through the integrated approach, the effectiveness and accuracy of abnormal image detection are further improved when there are very few positive samples. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 One of the flow charts of the training method of the unbalanced abnormal image detection model based on positive sample induction provided in an embodiment of the present invention;
[0039] Figure 2 A second flow chart of a training method for an unbalanced abnormal image detection model induced by positive samples provided in an embodiment of the present invention;
[0040] Figure 3 The attention map of printed circuit board defect anomalies provided by the embodiment of the present invention, wherein the first and third rows are printed circuit board defect anomaly images, the black box is the abnormal area, and the second and fourth rows are abnormal attention maps that the model pays attention to;
[0041] Figure 4An attention map of abnormal fundus lesions provided in an embodiment of the present invention, wherein the first and third rows are images of abnormal fundus lesions, the black boxes are abnormal areas, and the second and fourth rows are abnormal attention maps that the model pays attention to. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0043] In the present invention, abnormal samples are defined as positive samples, and normal samples are defined as negative samples.
[0044] See also Figure 1 , combined with Figure 2 The present invention provides a training method for an unbalanced abnormal image detection model based on positive sample induction, including operation S1 and operation S2.
[0045] Operation S1 : determining a training sample set, where samples in the training sample set are labeled training images; wherein a label of 0 represents a negative sample, and a label of 1 represents a positive sample.
[0046] In this embodiment, given a training set of labeled image samples y i Represents image x i The label, y i =0 indicates negative sample (normal sample), y i =1 indicates a positive sample (abnormal sample), where the frequency p0 of negative samples is much greater than the frequency p1 of positive samples. In actual scenarios, p1:p0≤0.5%:1.
[0047] Operation S2: training the initial neural network through a loss function according to the training sample set to obtain an abnormal image detection model.
[0048] In this embodiment, the training sample set To conduct a deep neural network model f θ Learning to determine whether the sample to be tested is abnormal.
[0049] Since there are far fewer positive samples than negative samples in the training sample set, the model trained by deep neural network using general cross entropy loss tends to classify negative samples and cannot learn effective sample feature expressions and classifiers. To solve this problem, the present invention proposes a positive sample classification score induced loss to optimize and adjust the weights of deep neural network by introducing the frequency of sample labels and continuous optimization of positive samples to deal with the problem of unbalanced abnormal image detection, which is expressed as follows:
[0050]
[0051] Where N b represents the total number of training samples in a batch, x i and i Respectively represent the i-th training image and the corresponding label in the batch of training samples, y i is 0 or 1, p0 and p1 represent the frequencies of negative and positive samples in the batch of training samples, respectively, and f θ (x i )[0] and f θ (x i )[1] represent the classification scores of predicting the i-th training image as a negative sample and a positive sample, respectively.
[0052] As can be seen from the above formula, compared with the ordinary cross entropy loss log(1+exp(f θ (x i )[1-y i ]-f θ (x i )[y i ])), the positive sample classification score induced loss proposed by the present invention introduces sample label information and the frequency of sample labels. Specifically:
[0053] 1) The frequency of sample labels is introduced. During the training process, since p1<<p0, The value is very large, and it is necessary to minimize the To minimize, we must make the positive sample To be established, it is necessary to force the classifier to have at least The margin can be detected, so the imbalance problem can be effectively alleviated.
[0054] 2) Introduce sample label information. Since there are very few positive samples, they are easily well classified by the neural network during the training process, thus losing the effectiveness of neural network parameter optimization and the discriminative expression of its features. To this end, label information is introduced to continuously optimize the neural network parameters using positive samples. The back propagation formula of the induced loss of the positive sample classification score is as follows:
[0055]
[0056]
[0057] Although when a small number of positive samples are well classified by the classifier, its back propagation gradient Still large. For the cross entropy loss that only introduces the frequency of sample labels For , its gradient back propagation is Therefore, when the positive sample is optimized, the gradients generated by introducing both the sample label information and the loss of the sample label frequency and the loss of only the sample label frequency are Even if Δ0 approaches 0, the gradient ratio generated by positive samples is as high as Then the positive samples can still guide the network parameters to be continuously optimized. This paper proposes a positive sample classification score induced loss that constrains the back propagation loss of the sample in terms of label frequency and positive samples to continuously encourage parameter optimization, and adjusts the deep neural network f θ The parameter θ is used to effectively express features and expand the classification margin.
[0058] In addition, the above-mentioned positive sample classification score induced loss can effectively deal with the unbalanced classification problem with very few positive samples, but it ignores the problem of anomaly detection and does not consider the problem that the abnormal area in the image has variable positions, different scales, and various shapes. The model trained by the positive sample classification score induced loss needs to be improved in terms of its attention to abnormal areas. Therefore, the present invention further deals with this problem by proposing a positive sample feature contrast loss, further improving the feature discriminability of abnormal samples, and guiding the deep neural network model to pay more attention to abnormal areas in the image.
[0059] Based on this, the present invention also provides another training method for an unbalanced abnormal image detection model based on positive sample induction, comprising:
[0060] Determine a training sample set, where samples in the training sample set are labeled training images; wherein a label of 0 represents a negative sample, and a label of 1 represents a positive sample;
[0061] According to the training sample set, the initial neural network is trained by a loss function to obtain an abnormal image detection model;
[0062] Among them, the loss function l PSI It is expressed as:
[0063] l PSI = l PLI +λ·l PFC
[0064]
[0065]
[0066]
[0067] In the formula, l PLI represents the positive sample classification score induced loss, N b represents the total number of training samples in a batch, x i and i Respectively represent the i-th training image and the corresponding label in the batch of training samples, y i is 0 or 1, p0 and p1 represent the frequencies of negative and positive samples in the batch of training samples, respectively, and f θ (x i )[0] and f θ (x i )[1] represent the classification scores of predicting the i-th training image as a negative sample and a positive sample respectively; l PFC represents the positive sample feature contrast loss, N b0 Indicates the number of negative samples in the batch of training samples, F θ Represents the neural network f θ The extracted features; λ represents the loss adjustment weight.
[0068] A positive sample induced loss ensures the effectiveness of the classifier by constraining the classifier and features at the same time during the training phase, while guiding the deep neural network model to pay more attention to the abnormal area itself, further improving the effectiveness of unbalanced abnormal image detection. Finally, the neural network model f θ The updates are as follows:
[0069]
[0070] Among them, η, t represent the learning rate and update time respectively.
[0071] In the inference stage, the present invention uses a proposed positive sample induced loss to train the deep neural network model f θ Treat the test sample Perform abnormal identification as follows:
[0072]
[0073] in Indicates the sample to be tested If the abnormal score is greater than the set threshold, it is judged as an abnormal image, otherwise it is judged as a normal image. At the same time, the present invention uses the gradient back propagation technology CAM to obtain the deep neural network model f θ Attention map of abnormal areas as follows:
[0074]
[0075] Therefore, the abnormal area attention map obtained further It can help the analysis model to determine whether the abnormal area has been paid attention to and characterized, and at the same time, it can assist workers to further distinguish whether it is an abnormal area. Figure 3 and Figure 4 As shown in Figure 2, the attention maps for printed circuit board defect anomaly detection and fundus lesion anomaly detection are displayed, which demonstrates the effectiveness of the method proposed in this paper.
[0076] In order to further improve the effectiveness and accuracy of unbalanced abnormal image detection, the present invention proposes to divide the negative samples in the training sample set equally into K parts to each subset, but all positive samples are divided into each subset, and a proposed positive sample induced loss is used to train a model for each subset. like Figure 2 Finally, in the inference phase, the trained models of all subsets are integrated for detection, as follows:
[0077]
[0078] This method further improves the effectiveness and accuracy of abnormal image detection in cases with very few positive samples through integration.
[0079] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A training method for an unbalanced abnormal image detection model based on positive sample induction, characterized in that: include: Determine a training sample set, where samples in the training sample set are labeled training images; wherein a label of 0 represents a negative sample, and a label of 1 represents a positive sample; According to the training sample set, the initial neural network is trained by a loss function to obtain an abnormal image detection model; Among them, the loss function l PLI It is expressed as: Where N b represents the total number of training samples in a batch, x i and i Respectively represent the i-th training image and the corresponding label in the batch of training samples, y i is 0 or 1, p0 and p1 represent the frequencies of negative and positive samples in the batch of training samples, respectively, and f θ (x i )[0] and f θ (x i )[1] represent the classification scores of predicting the i-th training image as a negative sample and a positive sample, respectively.
2. A training method for an unbalanced abnormal image detection model based on positive sample induction, characterized in that: include: Determine a training sample set, where samples in the training sample set are labeled training images; wherein a label of 0 represents a negative sample, and a label of 1 represents a positive sample; According to the training sample set, the initial neural network is trained by a loss function to obtain an abnormal image detection model; Among them, the loss function l PSI It is expressed as: L PSI l PLI +λ·l PFC In the formula, l PLI represents the positive sample classification score induced loss, N b represents the total number of training samples in a batch, x i and i Respectively represent the i-th training image and the corresponding label in the batch of training samples, y i is 0 or 1, p0 and p1 represent the frequencies of negative and positive samples in the batch of training samples, respectively, and f θ (x i )[0] and f θ (x i )[1] represent the classification scores of predicting the i-th training image as a negative sample and a positive sample respectively; l PFC represents the positive sample feature contrast loss, N b0 Indicates the number of negative samples in the batch of training samples, F θ Represents the neural network f θ The extracted features; λ represents the loss adjustment weight.
3. A method for detecting unbalanced abnormal images based on positive sample induction, characterized in that: include: Acquire the image to be detected; Predicting the abnormality score of the image to be detected by using the abnormal image detection model trained by the training method of the unbalanced abnormal image detection model based on positive sample induction as claimed in claim 1 or 2; The image to be detected whose abnormality score is greater than the score threshold is identified as an abnormal image.
4. The unbalanced abnormal image detection method based on positive sample induction according to claim 3 is characterized in that: The negative samples in the training sample set are equally divided into K parts to obtain K negative sample subsets, and the positive samples in the training sample set are added to each of the negative sample subsets to form K new training sample sets; According to each of the new training sample sets, a corresponding abnormal image detection model is trained; The abnormality score of the image to be detected is predicted according to the K trained abnormal image detection models.
5. The unbalanced abnormal image detection method based on positive sample induction according to claim 4 is characterized in that: The average of the anomaly scores predicted by the K trained anomaly image detection models is used as the anomaly score of the image to be detected.
6. A training system for an unbalanced abnormal image detection model based on positive sample induction, characterized in that: include: A computer readable storage medium and a processor; The computer-readable storage medium is used to store executable instructions; The processor is used to read the executable instructions stored in the computer-readable storage medium and execute the method according to claim 1 or 2.
7. A positive sample-induced unbalanced abnormal image detection system, characterized in that: include: A computer readable storage medium and a processor; The computer-readable storage medium is used to store executable instructions; The processor is used to read the executable instructions stored in the computer-readable storage medium and execute the method according to any one of claims 3 to 5.
