Industrial product defect detection method based on distillation contrast learning

Through the method based on distillation comparison learning, an industrial product defect detection model is constructed, which solves the problems of insufficient data set coverage and low detection accuracy in the existing technology, and realizes efficient and accurate defect detection and long-term data processing.

CN119540223AActive Publication Date: 2025-02-28HENAN UNIV OF SCI & TECH
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411940124.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-02-28
Estimated Expiration
2044-12-26

AI Technical Summary

Technical Problem

The prior art is difficult to collect comprehensive labeled data sets covering all possible defect forms, cannot accurately detect abnormal data, and has problems with forgetting and drifting of long-term unupdated data.

Method used

Using industrial product defect detection method based on distillation comparison learning, product images are collected for preprocessing, normal images and pseudo-abnormal images are obtained, and knowledge distillation and data enhancement are used to construct product defect detection models.

Benefits of technology

It has achieved the ability to cover a wide range of defect forms, high detection accuracy, and effective processing of data not updated for a long time, improving the efficiency and accuracy of product defect detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119540223A_ABST
    Figure CN119540223A_ABST
Patent Text Reader

Abstract

The invention provides an industrial product defect detection method based on distillation contrast learning, and belongs to the field of product defect detection.The method comprises the steps that a product image is collected and preprocessed, and a normal image and a pseudo abnormal image are obtained; acquiring a real label of the related image, training a teacher network, and respectively obtaining normal teacher output features and abnormal teacher output features; defining a soft target and a hard target, and optimizing the hard target and the soft target by using the student network according to distillation comparative learning to obtain an optimal student network; constructing a product defect detection model, inputting an image of a to-be-detected product into the product defect detection model to obtain embedded features, calculating cosine similarity, comparing the cosine similarity to obtain a predicted value, and analyzing the predicted value and a real label; the problems that in the prior art, a comprehensive mark data set covering all possible defect forms is difficult to collect, abnormal data cannot be accurately detected, and the data are forgotten and drifted are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of product defect detection, and in particular relates to an industrial product defect detection method based on distillation contrast learning. Background Art

[0002] Detecting surface defects of industrial products is an important area of ​​industrial intelligent development. It mainly detects surface defects of products, including scratches, breakages and color contamination, during industrial production and quality control processes to ensure product quality and production safety.

[0003] The probability of producing abnormal products is low and the types of abnormalities are diverse. In traditional manual inspection, the accuracy and efficiency of inspection cannot be guaranteed due to the subjectivity and fatigue of manual inspection. The use of defect detection models can effectively solve these problems, improve the accuracy and efficiency of defect detection, and reduce costs and labor burden. Therefore, defect detection of industrial products is very important in digital manufacturing.

[0004] There are currently two methods for defect detection. The first is a supervised method, which uses defect images with labels (including categories, rectangular boxes, or pixel by pixel, etc.) to input into the network for training; the second is an unsupervised method, which is to learn normal defect-free samples, learn the characteristics of normal areas, and the network detects abnormal areas. However, since defects in industrial manufacturing are caused by uncontrolled factors in the production process, the defects come in various forms. Therefore, it is difficult to collect a comprehensive labeled dataset that covers all possible defect forms.

[0005] The existing technologies usually use unsupervised methods in defect detection, including reconstruction-based methods and feature embedding similarity-based methods. For reconstruction-based methods, only normal images are used to train the neural network for image reconstruction. Abnormal images are detected as defective images because they cannot be reconstructed well, and the abnormal scores are represented by reconstruction errors. The most common reconstruction-based methods are autoencoders and generative adversarial networks. However, this method requires a large amount of normal data as training samples. If the distribution of abnormal data is similar to that of normal data, the model may not be able to accurately detect anomalies. Although reconstruction-based methods are very intuitive and explainable, they can sometimes produce good reconstruction results for abnormal images.

[0006] For feature embedding similarity, the deep neural network extracts and learns the meaningful vector of the entire image, and the anomaly score is represented by the distance between the embedding vector of the test image and the reference vector representing normality in the training data set. Methods based on feature embedding similarity include memory bank, knowledge distillation, etc. Memory bank is a method that has been used more frequently in recent years. It adopts the idea of ​​establishing a feature bank, extracts all normal image features and stores them in the bank, and compares the distance between the features of the test sample and the features of the feature bank to perform anomaly detection. However, the anomaly detection method based on the memory bank needs to continuously update the normal data features in the memory bank, which may cause the model to forget and drift for data that has not been updated for a long time. At the same time, the size of the memory bank has a decisive influence on the detection ability of the model; knowledge distillation uses the output results of the teacher network and the student network on the data set to be as consistent as possible to train the comparison model. Since the model has been trained consistently on normal images, when the test sample is abnormal data, the output of the student model and the teacher model will be very different in theory, thereby judging that the data is abnormal data. Summary of the invention

[0007] In view of the above-mentioned deficiencies in the prior art, the present invention provides an industrial product defect detection method based on distillation contrastive learning, which solves the problems that the prior art is difficult to collect a comprehensive labeled data set covering all possible defect forms, cannot accurately detect abnormal data, and has forgetting and drift for data that has not been updated for a long time.

[0008] In order to achieve the above objectives, the technical solution adopted by the present invention is: an industrial product defect detection method based on distillation contrast learning, comprising the following steps:

[0009] S1, collecting product images, preprocessing the product images, and obtaining normal images and pseudo-abnormal images;

[0010] S2. Obtain the true labels of normal images and pseudo-abnormal images, use the normal images and pseudo-abnormal images to train the teacher network, and obtain the output features of the normal teacher and the output features of the abnormal teacher respectively;

[0011] S3, taking the output features of the normal teacher and the output features of the abnormal teacher as soft targets, taking the true labels as hard targets, and optimizing the hard targets and soft targets using the student network according to distillation contrastive learning, obtaining the total distillation loss, and obtaining the optimal student network;

[0012] S4. Combining the normal teacher network, the abnormal teacher network and the optimal student network, a product defect detection model is constructed;

[0013] S5. Input the image of the product to be tested into the product defect detection model to obtain embedded features, use the embedded features to calculate the cosine similarity, and compare the cosine similarities to obtain the predicted value, analyze the predicted value and the true label, and complete the industrial product defect detection.

[0014] The beneficial effects of the present invention are as follows: the present invention constructs a product defect detection model by using a knowledge distillation structure and a data enhancement structure based on contrastive learning, thereby achieving the ability to cover a wide range of defect forms, high detection accuracy, and effectively process data that has not been updated for a long time; the present invention establishes an end-to-end product defect detection model and completes product defect detection using only one model, thereby improving the efficiency of product defect detection; and uses the area under the receiver operating characteristic curve to analyze the predicted value, thereby improving the accuracy of product defect detection.

[0015] Furthermore, the S1 comprises the following steps:

[0016] S101, collecting product images, and randomly adjusting the brightness, contrast, saturation, and hue of the product images to obtain normal images;

[0017] S102, randomly selecting a matrix area as a patch according to the normal image, and performing a transformation operation on the patch to obtain a transformed patch;

[0018] S103 , embedding the transformed patch into a random position of the normal image to obtain a pseudo abnormal image.

[0019] The beneficial effects of the above further scheme are as follows: the present invention increases the diversity of image data by randomly adjusting the basic attributes of product images; and obtains pseudo-abnormal samples through random selection and transformation operations, thereby increasing the diversity of pseudo-abnormal samples and making the pseudo-abnormal samples closer to the characteristics of real abnormal samples; and provides effective abnormal samples for subsequent abnormality detection.

[0020] Furthermore, the S2 comprises the following steps:

[0021] S201, obtaining the true labels of normal images and pseudo-abnormal images, initializing the normal teacher network and the abnormal teacher network, training the normal teacher network using normal images, and optimizing the parameters of the normal teacher network according to the training results;

[0022] S202, training the abnormal teacher network using pseudo abnormal images, and optimizing the parameters of the abnormal teacher network according to the training results;

[0023] S203. In response to the training being completed, parameters of the normal teacher network and the abnormal teacher network are frozen, and output features of the normal teacher and output features of the abnormal teacher are obtained.

[0024] The beneficial effect of the above further scheme is: in the training process of the product defect detection model, the present invention uses two encoders with the same network structure and the same initial parameters as teacher networks, one for normal image training and the other for pseudo-abnormal image training, to obtain a teacher network for normal image distribution and a teacher network for pseudo-abnormal image classification, respectively. Since the corresponding network has not learned the remaining distribution features, the significance of the output features is enhanced, and the accuracy and efficiency of anomaly detection are improved.

[0025] Furthermore, the S3 comprises the following steps:

[0026] S301, taking the output features of the normal teacher and the output features of the abnormal teacher as soft targets, and taking the true label as hard target;

[0027] S302, initialize the student network, optimize the hard targets and soft targets using the student model according to distillation contrast learning, and minimize the distillation loss function;

[0028] S303, distilling the student network model using feature graphs of different network layers of the normal teacher network and the abnormal teacher network, and obtaining the total distillation loss according to the minimized distillation loss function;

[0029] S304. Use the optimizer to back-propagate and optimize the total distillation loss, adjust the student network parameters, and obtain the optimal student network.

[0030] Furthermore, the expression for minimizing the distillation loss function is as follows:

[0031]

[0032] Among them, L KD represents the distillation loss, α1 and α2 represent the normalized weights, α1+α2∈{0,1}, N represents the total number of samples, j and k represent the sample numbers, T represents the temperature, represents the prediction result of the normal teacher based on sample j at temperature T, represents the prediction result of the abnormal teacher based on sample j at temperature T, represents the prediction result of the student network based on sample j at temperature T, v j represents the output feature obtained by the corresponding teacher network based on sample j, v k represents the output feature obtained by the corresponding teacher network based on sample k, z j represents the output features obtained by the student network based on sample j, z k represents the output features obtained by the student network based on sample k, c j Represents the true label value.

[0033] The beneficial effects of the above further scheme are: the present invention improves the ability of the student network to learn and understand data distribution by transmitting feature information from the teacher network to the student network, and at the same time combines contrastive learning and distillation learning to enable the student network to learn richer and more meaningful feature representations; compared with the traditional knowledge distillation-based method, the present invention improves the effectiveness and discrimination ability of defect detection; the present invention uses an optimizer to backpropagate and optimize the total distillation loss, effectively adjusts the parameters of the student network, enables the student network to better fit the knowledge of the teacher network, and improves the abnormal discrimination ability of the student network.

[0034] Further, the S5 comprises the following steps:

[0035] S501, input the image of the product to be tested into the product defect detection model, use the normal teacher network, the abnormal teacher network and the optimal student network to process the image of the product to be tested, and obtain normal embedding features, abnormal embedding features and student embedding features respectively;

[0036] S502, according to the normal embedding features, the abnormal embedding features and the student embedding features, through the last layer network of the product defect detection model, obtain the output features of the normal teacher network, the output features of the abnormal teacher network and the output features of the student network;

[0037] S503, calculating the cosine similarity according to the output features of the normal teacher network and the output features of the student network to obtain a first cosine similarity, and calculating the cosine similarity according to the output features of the abnormal teacher network and the output features of the student network to obtain a second cosine similarity;

[0038] S504, comparing the first cosine similarity and the second cosine similarity to obtain a predicted value;

[0039] S505. According to the predicted value and the true label, the area under the receiver operating characteristic curve is calculated for analysis to complete the industrial product defect detection.

[0040] The beneficial effects of the above further scheme are as follows: the present invention predicts the image of the product to be tested by constructing a product defect model, calculates the output distance between the student model and the teacher model using the features of different network layers, obtains the cosine similarity, and uses the deep network layer to effectively suppress the noise and interference of the image; and by performing anomaly detection in the semantic feature space, the significance and discriminability of the defect analysis results are improved, which is not only the pixel-level difference, but also achieves independence from the pixel-level distance error; the present invention analyzes by calculating the area under the receiver operating characteristic curve, provides an overall performance evaluation of the product defect model under all possible thresholds, comprehensively reflects the effect of the classifier, makes the predicted value more consistent with the real label, and realizes rapid and accurate detection of industrial product defects. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 The present invention is a flow chart of the method.

[0042] Figure 2 This is a schematic diagram of generating a pseudo abnormal image according to this embodiment.

[0043] Figure 3 This is a diagram of the testing process of the distillation contrast learning and product defect detection model used in this embodiment. DETAILED DESCRIPTION

[0044] The specific implementation modes of the present invention are described below so that those skilled in the art can understand the present invention. However, it should be clear that the present invention is not limited to the scope of the specific implementation modes. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations utilizing the concept of the present invention are protected.

[0045] Before describing this embodiment, the following terms are explained:

[0046] AUROC: area under the receiver operating characteristic curve;

[0047] ROC: receiver operating characteristic;

[0048] AUC: area under the curve;

[0049] Accuracy: accuracy;

[0050] Precision: accuracy;

[0051] Recall: recall rate;

[0052] F1-Score: Harmonic mean.

[0053] Example

[0054] like Figure 1 As shown, the present invention provides an industrial product defect detection method based on distillation contrast learning, and its implementation method is as follows:

[0055] S1. Collect product images and preprocess them to obtain normal images and pseudo-abnormal images. The specific steps are as follows:

[0056] S101, collecting product images, and randomly adjusting the brightness, contrast, saturation, and hue of the product images to obtain normal images;

[0057] S102, randomly selecting a matrix area as a patch according to the normal image, and performing a transformation operation on the patch to obtain a transformed patch;

[0058] S103 , embedding the transformed patch into a random position of the normal image to obtain a pseudo abnormal image.

[0059] In this embodiment, the present invention provides a new detection model; the knowledge distillation structure and data enhancement structure used by the product defect detection model are based on the idea of ​​contrastive learning, which is different from the traditional knowledge distillation model. First, this model uses the features of normal images and pseudo-defect images, corresponding to two different teacher models in knowledge distillation, so that it can distill the student model at the same time. When detecting the test image, the idea of ​​contrastive learning is used to compare the distance between the output features of the student model and the two teacher models to judge whether the test image is normal or abnormal. Secondly, the present invention does not rely on pixel-level distance errors, but performs anomaly detection in the semantic feature space. By operating on higher-level representations, defects can be analyzed more meaningfully and discriminatively, rather than just pixel-level differences. Compared with traditional knowledge distillation-based methods, these improvements improve the effectiveness and discriminative ability of defect detection.

[0060] In this embodiment, the present invention is divided into two parts, the construction and training of the product defect detection model, and the testing and defect detection of the defect detection model; the construction and training of the product defect detection model include the acquisition of product images and preprocessing, the training of the teacher model and the training of the student model; the testing and defect detection of the defect detection model include the product defect detection model testing the image of the product to be tested, and calculating the cosine similarity, and calculating the cosine similarity to obtain the predicted value, analyzing the predicted value, and completing the industrial product defect detection;

[0061] Collect product images, randomly adjust the brightness, contrast, saturation and hue of the product images to obtain normal images; then randomly select a small matrix area from the normal image as a patch, the size and aspect ratio of the patch can be adjusted as needed to adapt to different abnormal sample shapes and sizes; the randomly selected patch area can simulate the abnormal situation of different parts in the real world; and transform the patch, the transformation operation can be: rotate or modify the pixel value; the rotation operation can make the patch have different angles when pasted back to the original image, increasing the diversity of the sample; modifying the pixel value can change the appearance of the patch to make it closer to the characteristics of the real abnormal sample; such as Figure 2 As shown, the transformed patch is pasted back to a random position of the normal image to generate a pseudo-anomalous sample.

[0062] S2. Get the real labels of normal images and pseudo-abnormal images, use normal images and pseudo-abnormal images to train the teacher network, and obtain the output features of normal teachers and the output features of abnormal teachers respectively. The specific steps are as follows:

[0063] S201, obtaining the true labels of normal images and pseudo-abnormal images, initializing the normal teacher network and the abnormal teacher network, training the normal teacher network using normal images, and optimizing the parameters of the normal teacher network according to the training results;

[0064] S202, training the abnormal teacher network using pseudo abnormal images, and optimizing the parameters of the abnormal teacher network according to the training results;

[0065] S203. In response to the training being completed, parameters of the normal teacher network and the abnormal teacher network are frozen, and output features of the normal teacher and output features of the abnormal teacher are obtained.

[0066] In this embodiment, two encoders with the same network structure and the same initial parameters are used as teacher networks, one teacher network is trained with normal images and is a normal teacher network, and the other teacher network is trained with pseudo-abnormal images and is an abnormal teacher network; according to the obtained normal image and pseudo-abnormal image, the normal image and the pseudo-abnormal image are converted into tensors and normalized to obtain the true labels of the normal image and the pseudo-abnormal image. Since the normal image and the pseudo-abnormal image are known, the true label of the normal image is 0, and the true label of the pseudo-abnormal image is 1;

[0067] Initialize the normal teacher network and the abnormal teacher network, use binary cross entropy as the loss function for supervised training, use normal images to train the normal teacher network, and optimize the parameters of the normal teacher network based on the training results, use pseudo-abnormal images to train the abnormal teacher network, and optimize the parameters of the abnormal teacher network based on the training results;

[0068] The normal teacher loss function formula is:

[0069]

[0070] Among them, L NT represents normal teacher loss, N represents the total number of samples, i represents the sample number, p i Indicates the probability that sample i is predicted to be a positive class;

[0071] The abnormal teacher loss function formula is:

[0072]

[0073] Among them, L AT represents the abnormal teacher loss, N represents the total number of samples, i represents the sample number, pi Represents the probability that sample i is predicted to be a positive class; in response to the completion of training, the parameters of the normal teacher network and the abnormal teacher network are frozen to obtain the trained normal teacher network and the abnormal teacher network; and the trained normal teacher network and the abnormal teacher network are used to process normal images and pseudo-abnormal images to obtain normal teacher output features and abnormal teacher output features.

[0074] S3. Take the output features of the normal teacher and the output features of the abnormal teacher as soft targets, and the true labels as hard targets. According to the distillation contrast learning, the student network is used to optimize the hard targets and soft targets, and the total distillation loss is obtained to obtain the optimal student network. The specific steps are as follows:

[0075] S301, taking the output features of the normal teacher and the output features of the abnormal teacher as soft targets, and taking the true label as hard target;

[0076] S302, initialize the student network, optimize the hard targets and soft targets using the student model according to distillation contrast learning, and minimize the distillation loss function;

[0077] S303, distilling the student network model using feature graphs of different network layers of the normal teacher network and the abnormal teacher network, and obtaining the total distillation loss according to the minimized distillation loss function;

[0078] S304. Use the optimizer to back-propagate and optimize the total distillation loss, adjust the student network parameters, and obtain the optimal student network.

[0079] In this embodiment, the student network uses the same initial parameters and network structure as the teacher network, takes the output features of the normal teacher and the output features of the abnormal teacher as soft targets, and takes the true label as the hard target; initializes the student network, and uses the student network to simultaneously optimize the hard target and the soft target according to distillation contrast learning, and minimizes the distillation loss function; the expression for minimizing the distillation loss function is as follows:

[0080]

[0081] Among them, L KD represents the distillation loss, α1 and α2 both represent normalized weights, α1+α2∈{0,1}, L NT-soft represents the normal teacher loss in the soft target, L AT-soft represents the abnormal teacher loss in the soft target, L hard represents the hard target loss, N represents the total number of samples, j and k both represent the sample numbers, represents the prediction result of the normal teacher based on sample j at temperature T, represents the prediction result of the abnormal teacher based on sample j at temperature T, vj represents the output feature obtained by the corresponding teacher network based on sample j, v k represents the output feature obtained by the corresponding teacher network based on sample k, z j represents the output features obtained by the student network based on sample j, z k represents the output features obtained by the student network based on sample k, represents the prediction result of the student network at temperature T, T∈(0,∞). When T>1, the difference between the prediction values ​​of the target class and the non-target class decreases. On the contrary, when T<1, the difference between the prediction values ​​of the target class and the non-target class will be further widened. c j represents the true label value, c j ∈{0,1};

[0082] The student network model is distilled using feature maps from different layers of the two teacher networks. The outputs of different layers can capture features at different levels of abstraction. Shallower layers may focus more on low-level features such as edges and textures, while deeper layers may focus more on high-level semantic features such as object shape and structure. By utilizing the outputs of multiple different layers, richer and more diverse feature representations can be obtained, which helps improve the performance of the student model. Using the outputs of multiple different layers for distillation can enhance the robustness of the model. Features at different levels may have different sensitivities to different types of anomalies. By taking features from multiple levels into consideration, the student model can learn the representation of abnormal features more comprehensively, thereby improving the ability to detect various anomalies. In real-world scenarios, images may be affected by noise and interference. Shallower layers may be more sensitive to these noise and interference, while deeper layers may have stronger suppression capabilities. By utilizing the outputs of multiple different layers, noise and interference can be effectively suppressed, improving the robustness and accuracy of the model.

[0083] like Figure 3 As shown in (a), during the distillation process, the normal image is input into the student network for forward propagation to obtain the embedding features and prediction results of the normal distilled student network at the last four levels. Similarly, the same normal image is input into the normal teacher network for forward propagation to obtain the corresponding normal distilled teacher network output. The embedding features of the student network for the abnormal image at the last four levels are used as the output of the abnormal distilled student network, and the output and embedding features of the abnormal teacher network at the same level are used as the output of the abnormal distilled teacher network. The distillation loss function is used to calculate the losses of normal distillation and abnormal distillation respectively. The abnormal distillation loss and the normal distillation loss are added to obtain the total distillation loss; and the optimizer is used to backpropagate and optimize the total distillation loss to adjust the student network parameters.

[0084] S4. Combine the normal teacher network, abnormal teacher network and optimal student network to build a product defect detection model.

[0085] In this embodiment, a normal teacher network, an abnormal teacher network and an optimal student network are combined to construct an industrial product defect detection model based on distillation contrastive learning. The model is constructed by the network obtained by distillation contrastive learning, so the loss function of the product defect detection model is also the same distillation loss function.

[0086] S5. Input the image of the product to be tested into the product defect detection model to obtain embedded features, calculate the cosine similarity using the embedded features, and compare the cosine similarity to obtain the predicted value. Analyze the predicted value and the true label to complete the industrial product defect detection. The specific steps are as follows:

[0087] S501, input the image of the product to be tested into the product defect detection model, use the normal teacher network, the abnormal teacher network and the optimal student network to process the image of the product to be tested, and obtain normal embedding features, abnormal embedding features and student embedding features respectively;

[0088] S502, according to the normal embedding features, the abnormal embedding features and the student embedding features, through the last layer network of the product defect detection model, obtain the output features of the normal teacher network, the output features of the abnormal teacher network and the output features of the student network;

[0089] S503, calculating the cosine similarity according to the output features of the normal teacher network and the output features of the student network to obtain a first cosine similarity, and calculating the cosine similarity according to the output features of the abnormal teacher network and the output features of the student network to obtain a second cosine similarity;

[0090] S504, comparing the first cosine similarity and the second cosine similarity to obtain a predicted value;

[0091] S505. According to the predicted value and the true label, the area under the receiver operating characteristic curve is calculated for analysis to complete the industrial product defect detection.

[0092] In this embodiment, Figure 3As shown in (b), the current test product image is input into the product defect detection model, and the normal teacher network, abnormal teacher network and optimal student network are used to process the product image to be tested, respectively, and the normal embedding features, abnormal embedding features and student embedding features are obtained respectively. The output features of different network layers are used to calculate the output distance between the student model and the teacher model, that is, the output features of the normal teacher network, the output features of the abnormal teacher network and the output features of the student network are obtained through the features output by the last layer of the network. These output features are all contained in the semantic feature space and are high-dimensional deep features. The cosine similarity between the student model and the output of different teacher models is calculated to obtain the normal cosine similarity and the abnormal cosine similarity, which is independent of the pixel-level distance error. The expression for calculating the cosine similarity is as follows:

[0093]

[0094] Among them, cos(q,k) represents the cosine similarity between the student network and the teacher network, q represents the output feature of the teacher network, k represents the output feature of the student network, n represents the total number of product images currently tested, and q i represents the i-th output feature of the corresponding teacher network, k i Represents the i-th output feature of the student network. When the output feature of the corresponding teacher network is more similar to the output feature of the student network, the cosine similarity value is closer to 1, otherwise it is closer to -1;

[0095] According to the calculated normal cosine similarity and abnormal cosine similarity, when the normal cosine similarity is greater than the abnormal cosine similarity, a prediction value is obtained, and it can be known that the product image currently being tested is a normal image; when the abnormal cosine similarity is greater than the normal cosine similarity, a prediction value is obtained, and it can be known that the product image currently being tested is an abnormal image;

[0096] Combined with the true label, the predicted value is directly used to calculate AUROC. It is necessary to calculate the accuracy, precision, recall and harmonic mean. The calculation expression is as follows:

[0097]

[0098] Among them, TP represents the number of positive classes predicted as positive classes, TN represents the number of negative classes predicted as negative classes, FP represents the number of negative classes predicted as positive classes, FN represents the number of positive classes predicted as negative classes, Accuracy represents accuracy, Precision represents precision, Recall represents recall, and F1-Score represents the harmonic mean; ROC receiver operating characteristic; the horizontal axis of ROC is the false positive rate (also called false positive rate, False Positive Rate), and the vertical axis is the true positive rate (true positive rate, True Positive Rate); Among them, TPR represents the ratio of samples that are correctly judged as positive among all samples that are actually positive, and the calculation formula is the same as the recall formula; FPR represents the ratio of samples that are incorrectly judged as positive among all samples that are actually negative, and the calculation formula is Given a binary classification model and its threshold, a coordinate point (X=FPR, Y=TPR) can be calculated from the true value and predicted value of all samples; the AUROC curve is formed by plotting the relationship between the true positive rate (TPR) and the false positive rate (FPR). The closer the AUROC curve is to the upper left corner, the better the prediction performance of the present invention. When AUROC is used for classification tasks, the area under the ROC curve and the coordinate axis is between 0.1 and 1. AUC as a numerical value can intuitively evaluate the quality of the classifier, and the larger the value, the better. After the overall performance evaluation of the present invention under all possible thresholds, industrial product defect detection is completed.

Claims

1. A method for industrial product defect detection based on distillation contrastive learning, characterized in that: The following steps are involved: S1, collecting product images, preprocessing the product images, and obtaining normal images and pseudo-abnormal images; S2. Obtain the true labels of normal images and pseudo-abnormal images, use the normal images and pseudo-abnormal images to train the teacher network, and obtain the output features of the normal teacher and the output features of the abnormal teacher respectively; S3, taking the output features of the normal teacher and the output features of the abnormal teacher as soft targets, taking the true labels as hard targets, and optimizing the hard targets and soft targets using the student network according to distillation contrastive learning, obtaining the total distillation loss, and obtaining the optimal student network; S4. Combining the normal teacher network, the abnormal teacher network and the optimal student network, a product defect detection model is constructed; S5. Input the image of the product to be tested into the product defect detection model to obtain embedded features, use the embedded features to calculate the cosine similarity, and compare the cosine similarities to obtain the predicted value, analyze the predicted value and the true label, and complete the industrial product defect detection.

2. The industrial product defect detection method based on distillation contrast learning according to claim 1, characterized in that: The S1 comprises the following steps: S101, collecting product images, and randomly adjusting the brightness, contrast, saturation, and hue of the product images to obtain normal images; S102, randomly selecting a matrix area as a patch according to the normal image, and performing a transformation operation on the patch to obtain a transformed patch; S103 , embedding the transformed patch into a random position of the normal image to obtain a pseudo abnormal image.

3. The industrial product defect detection method based on distillation contrast learning according to claim 1, characterized in that: The S2 comprises the following steps: S201, obtaining the true labels of normal images and pseudo-abnormal images, initializing the normal teacher network and the abnormal teacher network, training the normal teacher network using normal images, and optimizing the parameters of the normal teacher network according to the training results; S202, training the abnormal teacher network using pseudo abnormal images, and optimizing the parameters of the abnormal teacher network according to the training results; S203. In response to the training being completed, parameters of the normal teacher network and the abnormal teacher network are frozen, and output features of the normal teacher and output features of the abnormal teacher are obtained.

4. The industrial product defect detection method based on distillation contrast learning according to claim 1, characterized in that: The S3 comprises the following steps: S301, taking the output features of the normal teacher and the output features of the abnormal teacher as soft targets, and taking the true label as hard target; S302, initialize the student network, optimize the hard targets and soft targets using the student model according to distillation contrast learning, and minimize the distillation loss function; S303, distilling the student network model using feature graphs of different network layers of the normal teacher network and the abnormal teacher network, and obtaining the total distillation loss according to the minimized distillation loss function; S304. Use the optimizer to back-propagate and optimize the total distillation loss, adjust the student network parameters, and obtain the optimal student network.

5. The industrial product defect detection method based on distillation contrast learning according to claim 3, characterized in that: The expression for minimizing the distillation loss function is as follows: Among them, L KD represents the distillation loss, α1 and α2 represent the normalized weights, α1+α2∈{0,1}, N represents the total number of samples, j and k represent the sample numbers, T represents the temperature, represents the prediction result of the normal teacher based on sample j at temperature T, represents the prediction result of the abnormal teacher based on sample j at temperature T, represents the prediction result of the student network based on sample j at temperature T, v j represents the output feature obtained by the corresponding teacher network based on sample j, v k represents the output feature obtained by the corresponding teacher network based on sample k, z j represents the output features obtained by the student network based on sample j, z k represents the output features obtained by the student network based on sample k, c j represents the true label value, c j ∈{0,1}.

6. The industrial product defect detection method based on distillation contrast learning according to claim 1, characterized in that: The S5 comprises the following steps: S501, input the image of the product to be tested into the product defect detection model, use the normal teacher network, the abnormal teacher network and the optimal student network to process the image of the product to be tested, and obtain normal embedding features, abnormal embedding features and student embedding features respectively; S502, according to the normal embedding features, the abnormal embedding features and the student embedding features, through the last layer network of the product defect detection model, obtain the output features of the normal teacher network, the output features of the abnormal teacher network and the output features of the student network; S503, calculating the cosine similarity according to the output features of the normal teacher network and the output features of the student network to obtain a first cosine similarity, and calculating the cosine similarity according to the output features of the abnormal teacher network and the output features of the student network to obtain a second cosine similarity; S504, comparing the first cosine similarity and the second cosine similarity to obtain a predicted value; S505. According to the predicted value and the true label, the area under the receiver operating characteristic curve is calculated for analysis to complete the industrial product defect detection.

Citation Information

Patent Citations

  • Steel plate surface defect detection method and system based on semi-supervised learning

    CN116863274A

  • Glass defect detection algorithm based on multi-mode teacher and student framework

    CN118468230A

  • Image defect detection method based on double-branch inverse distillation and multi-input image

    CN118521570A

  • Workpiece defect detection method based on reverse distillation and auxiliary segmentation

    CN118762030A

  • System and method for defect detection

    US20230259760A1