Object defect detection optimization method, device, electronic device and readable storage medium
By acquiring standard non-defect features and optimizing feature purification and classification models, the problem of high false alarm rate for metal surface defect detection is solved, and more accurate defect detection is achieved.
Patent Information
- Application Number
- CN202311645530.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-01
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2043-12-01
AI Technical Summary
Due to the influence of light on metal surfaces, the false alarm rate of defect detection is high.
By obtaining standard non-defective features, optimizing the purification model and classification model of the features to be trained, extracting training features closer to the standard features, decoupling interference features, and improving the accuracy of defective features.
The false alarm rate of metal surface defect detection is reduced, the accuracy of detection is improved, and the defect characteristics are not included in the light characteristics.
Smart Images

Figure CN117671355B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of deep learning technology and relates to an object defect detection optimization method, device, electronic device and readable storage medium. Background Art
[0002] Surface defect detection is an indispensable part of industrial automation production. Research on surface defect detection technology has great practical significance. With the development of deep learning technology, industrial defect detection technology based on deep learning has been widely used in the field of defect detection. The essence of deep learning is to learn features by building a machine learning model with multiple hidden layers and massive training data, thereby ultimately improving the accuracy and versatility of classification or prediction.
[0003] However, when using deep learning for defect detection, due to the influence of surface illumination and texture, the extraction of defect-related features may include illumination and texture features. When subsequently determining whether an object has defects, due to the interference of illumination and texture features in the defect features, even normal objects may be falsely reported as defective objects. There is more illumination on the metal surface, so when detecting defects on the metal surface, the false alarm rate of defect detection is higher.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide an object defect detection optimization method, device, electronic device and readable storage medium, aiming to solve the technical problem of high false alarm rate of metal surface defect detection caused by high light exposure on the metal surface.
[0006] To achieve the above objectives, the present application provides an object defect detection optimization method, the object defect detection optimization method comprising:
[0007] Obtaining a first training sample, a standard non-defect feature, and a first classification label of the first training sample;
[0008] Inputting the first training sample into the defect detection model to be trained, performing feature extraction on the first training sample through the feature purification model to be trained to obtain training non-defect features and training defect features, and inputting the training defect features into the classification model to be trained to obtain a first classification result;
[0009] Determine a similarity loss between the standard non-defect feature and the training non-defect feature, determine a cosine loss between the training defect feature and the training non-defect feature, and determine a classification loss based on the first classification label and the first classification result;
[0010] According to the similarity loss, the cosine loss and the classification loss, the feature purification model to be trained and the classification model to be trained are optimized to obtain a trained feature purification model and a trained classification model.
[0011] To achieve the above objectives, the present application provides an object defect detection optimization device, the object defect detection optimization device comprising:
[0012] An acquisition module, used to acquire a first training sample, a standard non-defect feature, and a first classification label of the first training sample;
[0013] an extraction and classification module, configured to input the first training sample into the defect detection model to be trained, extract features of the first training sample through the feature purification model to be trained, obtain training non-defect features and training defect features, input the training defect features into the classification model to be trained, and obtain a first classification result;
[0014] a loss determination module, configured to determine a similarity loss between the standard non-defect feature and the training non-defect feature, determine a cosine loss between the training defect feature and the training non-defect feature, and determine a classification loss based on the first classification label and the first classification result;
[0015] An optimization module is used to optimize the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss, so as to obtain a trained feature purification model and a trained classification model.
[0016] The present application also provides an electronic device, comprising: a memory, a processor, and a program of the object defect detection optimization method stored in the memory and executable on the processor. When the program of the object defect detection optimization method is executed by the processor, the steps of the object defect detection optimization method as described above can be implemented.
[0017] The present application also provides a readable storage medium, on which is stored a program for implementing the object defect detection optimization method. When the program of the object defect detection optimization method is executed by a processor, the steps of the object defect detection optimization method as described above are implemented.
[0018] The present application also provides a computer program product, including a computer program, which implements the steps of the object defect detection optimization method as described above when executed by a processor.
[0019] The present application provides an object defect detection optimization method, device, electronic device and readable storage medium. The embodiments of the present application obtain standard non-defect features, so that when training a feature purification model to be trained to extract training non-defect features, the similarity loss between the standard non-defect features and the training non-defect features can be determined, so that the feature purification model to be trained can extract training non-defect features that are closer to the standard non-defect features, so that the features that interfere with defect detection are decoupled from the training non-defect features, and it can also avoid that the training non-defect features extracted by the feature purification model to be trained contain defect features, thereby improving the accuracy of extracting training defect features.
[0020] In addition, when training the to-be-trained purification model, the cosine loss between the training defect features and the training non-defect features will also be calculated, so that the training defect features obtained by decoupling the to-be-trained feature purification model are independent of the training non-defect features. Since the to-be-trained feature purification model can be trained to decouple and obtain more standard training non-defect features, when calculating the cosine loss, the accuracy of the cosine loss can also be improved, thereby improving the accuracy of the to-be-trained feature purification model in extracting the training defect features and reducing the influence of interference features on the training defect features. Since the classification loss of the classification model to be trained can also reflect the accuracy of the feature purification model in extracting training defect features, the feature purification model to be trained and the classification model to be trained are optimized together through similarity loss, cosine loss and classification loss, which can improve the accuracy of the feature purification model to be trained in extracting clean training defect features. After iterative optimization of the feature purification model to be trained and the classification model to be trained, a trained feature purification model and a trained classification model are obtained, so that the defect features extracted by the feature purification model do not contain interference features, and thus the defect features do not contain illumination features. When the classification model performs defect detection on the surface of a metal object based on the defect features, the accuracy of metal surface defect detection can be improved, thereby reducing the false alarm rate and solving the technical problem of high false alarm rate of metal surface defect detection caused by more light on the metal surface. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings herein are incorporated in and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the description, are used to explain the principles of the present application.
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1A schematic diagram of the process of training and extracting standard object features and standard illumination features in the object defect detection optimization method of this application;
[0024] Figure 2 A schematic diagram of a process for extracting non-interference defect features in the object defect detection optimization method of the present application;
[0025] Figure 3 This is a flow chart of the first embodiment of the object defect detection optimization method of the present application;
[0026] Figure 4 This is a flow chart of the second embodiment of the object defect detection optimization method of the present application;
[0027] Figure 5 This is a flow chart of object defect detection using a feature purification model and a classification model in the object defect detection optimization method of this application;
[0028] Figure 6 A schematic diagram of an apparatus according to an embodiment of the object defect detection optimization method of the present application;
[0029] Figure 7 Schematic diagram of the device structure of the hardware operating environment involved in the object defect detection optimization method in the embodiment of the present application.
[0030] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0031] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work belong to the scope of protection of this application.
[0032] For a better understanding of the embodiments of the present application, refer to Figure 1 and Figure 2 , the technical solution of the embodiment of the present application is described, Figure 1 Schematic diagram of the process of extracting standard object features and standard lighting features for training. Figure 2 Schematic diagram of the process for extracting non-interference defect features.
[0033] Figure 1In the process, the normal object features and normal illumination features in the second training sample are extracted through the sub-encoding model to be trained in the self-encoding model to be trained. The cosine similarity between the normal object features and the normal illumination features is calculated to obtain the normal feature-independent loss. The normal object features are then added to the normal illumination features and input into the decoding model to be trained to obtain the restored sample. Then, the mean square error between the restored sample and the second training sample is calculated to obtain the restored loss. In addition, the normal object features are input into the discriminant model to be trained. The discriminant model to be trained will classify the sample sources of the normal object features by labels to obtain the second classification result, and then calculate the second training loss based on the properties of the GAN (Generative Adversarial Network) network. The standard extraction model to be trained can be considered to be determined based on the GAN network. The standard extraction model to be trained includes the self-encoding model to be trained and the discriminant model to be trained. The self-encoding model to be trained includes the sub-encoding model to be trained and the decoding model to be trained. This makes it possible to extract non-interference standard illumination features and non-interference standard object features, so that when training the feature purification model to be trained, the training illumination features and training object features that are decoupled from the feature purification model to be trained can be constrained based on the standard illumination features and standard object features, so that the training illumination features and training object features are closer to the standard illumination features and standard object features, thereby improving the accuracy of extracting training defect features and reducing the interference of other features on the training defect features.
[0034] Figure 2 In the method, the first training sample is input into the feature purification model to be trained. The first training sample includes normal samples and defective samples. The feature purification model to be trained will decode the first training sample into training object features, training defect features and training illumination features. Further, the cosine similarity between the training object features and the training defect features is calculated to obtain the cosine object loss, and the cosine similarity between the training defect features and the training illumination features is calculated to obtain the cosine illumination loss. The KL divergence (Kullback-Leibler divergence) is calculated between the training object features and the standard object features to obtain the object similarity loss, and the KL divergence is calculated between the training illumination features and the illumination similarity loss to obtain the illumination similarity loss. The training defect features are input into the classification model to be trained to obtain the first classification result of the training defect features, and then the classification loss of the model to be classified is calculated. As a result, the trained feature purification model can extract non-interference defect features and provide the missing features to the trained classification model for defect detection, thereby improving the accuracy of defect detection and reducing the false alarm rate.
[0035] Embodiment 1
[0036] Reference Figure 3The embodiment of the present application provides an object defect detection optimization method. In the first embodiment of the object defect detection optimization method of the present application, the object defect detection optimization method is applied to a first device, and a defect detection model to be trained is deployed on the first device. The defect detection model to be trained includes a feature purification model to be trained and a classification model to be trained. The object defect detection optimization method includes:
[0037] The object defect detection optimization method comprises:
[0038] Step S10, obtaining a first training sample, a standard non-defect feature, and a first classification label of the first training sample;
[0039] It should be noted that the first device may be a terminal. The defect detection model to be trained is an untrained neural network model, and the defect detection model to be trained is used to determine whether an object has defects. The feature purification model to be trained is an untrained neural network model, and the feature purification model to be trained is used to extract features from the input data, and the feature purification model to be trained may be a CNN (Convolutional Neural Network). The classification model to be trained is an untrained neural network model, and the classification model to be trained is used to determine the probability of defects on the surface of an object. The first training sample includes abnormal samples and normal samples. The abnormal samples and normal samples are simultaneously input into the defect detection model to be trained, so that the classification model to be trained can well distinguish between normal samples and abnormal samples. The first training sample may be a normal image sample of a metal object and an abnormal image sample with defects. The standard non-defect features include standard object features and standard illumination features. The standard object features are characterized as attribute features of the surface of an object, and the standard illumination features are illumination features of the surface of an object other than the standard object features in the preset normal sample. The first classification label is used to label the first training sample. The first classification label includes a defect label and a normal label. When the sample is a normal sample, its label is a normal label. When the sample is an abnormal label, its label is an abnormal label.
[0040] Exemplarily, the first training sample may be preset, and the standard non-defect features may also be preset in advance to ensure that the standard non-defect features do not include defect features.
[0041] In a feasible embodiment, step S10 includes:
[0042] Step S11, obtaining a second training sample, a second classification label of the second training sample, and determining a standard extraction model to be trained based on a preset game strategy;
[0043] It should be noted that the second training sample is a normal sample pre-set for training the standard extraction model to be trained, and the second training sample does not include defective samples. The standard extraction model to be trained can be GAN, which is a generative model that learns by means of mutual game between two neural networks. The two neural networks are called generator and discriminator, respectively. The training purpose of the generator is to make the discriminator unable to distinguish whether the data is generated by the generator, and the training purpose of the discriminator is to be able to judge whether the data is generated by the generator. The indicator of good training is that the generator successfully makes the discriminator invalid. The preset game strategy refers to replacing the generator in GAN with the self-standard extraction model to be trained. In an embodiment of the present application, the generator in GAN is the self-encoding model to be trained, and the discriminator is the discriminative model to be trained. The second classification label includes a first sample and a second sample, and the first sample and the second sample are both normal samples.
[0044] Step S12, inputting the second training sample into the standard extraction model to be trained, performing feature extraction on the second training sample through the autoencoder model to be trained of the standard extraction model to be trained, obtaining normal object features and normal illumination features, and determining restored samples of the normal object features and the normal illumination features, and determining a first training loss according to the normal object features, the normal illumination features, the restored samples, and the second training samples;
[0045] It should be noted that the autoencoder model to be trained is used to compress and encode the input data and then restore the code to the input data. The autoencoder model to be trained is an untrained neural network model. The normal object feature is the attribute feature of the metal surface extracted from the second training sample, and the normal lighting feature is the lighting feature of the metal surface extracted from the second training sample. Since the second training sample does not include defective samples. Therefore, the features in the second training sample except the normal object feature can be considered to be normal lighting features. The restored sample is a sample obtained by jointly restoring the normal object feature and the normal lighting feature by the autoencoder model to be trained. The first training loss includes the normal feature-irrelevant loss and the restoration loss. The first training loss is used to describe the training status of the autoencoder model to be trained. In a feasible embodiment, step S12 also includes:
[0046] Step S121, extracting features of the second training sample using the to-be-trained sub-encoding model of the to-be-trained auto-encoding model to obtain the normal object features and the normal illumination features;
[0047] Step S122, calculating the cosine similarity between the normal object feature and the normal illumination feature to obtain the normal feature irrelevant loss;
[0048] It should be noted that the sub-coding model to be trained is an untrained neural network, and the sub-coding model to be trained can be a CNN. The sub-coding model to be trained is used to perform latent coding on the second training sample, and decompose the latent coding into normal object features and normal illumination features. The cosine similarity can be expressed as a cosine value, and the normal feature irrelevant loss can be used to describe the similarity between the normal object features and the normal illumination features. The smaller the normal feature irrelevant loss, the more irrelevant the normal object features are to the normal illumination features.
[0049] Exemplarily, the formula for encoding the second training sample to obtain the normal object feature and the normal illumination feature is:
[0050] fobj=W1*X+b1
[0051] fenU=W2*X+b2
[0052] fobj=BN(fobj)
[0053] f env =BN(f env )
[0054] f obj =σ(f obj )
[0055] f env =σ(f env )
[0056] Among them, f obj is the normal object feature, f env is a normal illumination feature, X is a second training sample input to the standard extraction model to be trained, W1 and b1 are both normal object training learning parameters of the normal object feature, W2 and b2 are normal illumination training learning parameters of the normal illumination feature, * is a convolution operation, BN is a batch normalization function that maintains data distribution and avoids overfitting; σ activation function, the ReLU activation function is used in the embodiment of the present application. Among them, the normal object training learning parameters and the normal illumination training learning parameters can be updated and iterated at any time.
[0057] Step S123, based on the to-be-trained decoding model of the to-be-trained autoencoder model, decoding and restoring the normal object features and the normal illumination features to obtain restored samples;
[0058] Step S124, calculating the mean square error between the restored sample and the second training sample to obtain the restoration loss.
[0059] It should be noted that the decoding model to be trained is an untrained neural network, and the decoding model to be trained can be a Transposed CNN (Transposed Convolution, deconvolution), and the decoding model to be trained is used to restore the normal object features and normal training features encoded by the sub-encoding model to be trained. The restoration loss is the mean square error between the restored sample and the second training sample.
[0060] Exemplarily, steps S121 to S124 include: based on the sub-coding model to be trained, encoding the second training sample to obtain the normal object feature and the normal lighting feature; calculating the cosine similarity between the normal object feature and the normal lighting feature to obtain the normal feature irrelevant loss; inputting the sum of the normal object feature and the normal lighting feature into the self-encoding model to be trained to restore the normal object feature and the normal lighting feature to obtain a restored sample; calculating the mean square error between the restored sample and the second training sample to obtain the restoration loss.
[0061] Exemplarily, the formula for inputting the sum of the normal object feature and the normal illumination feature into the autoencoder model to be trained to restore the normal object feature and the normal illumination feature to obtain a restored sample may be:
[0062] Z=f obj +f env
[0063] f Z =DeConv(Z;θ1)
[0064] fz=BN(fz)
[0065] X=σ(fz)
[0066] Wherein, Z is the sum of the normal object feature and the normal illumination feature, fz is the feature of Z, DeConv is Transposed CNN, θ1 is the learnable parameter of Transposed CNN, To restore the sample.
[0067] Exemplarily, the formula for calculating the mean square error between the restored sample and the second training sample to obtain the restoration loss, and calculating the cosine similarity between the normal object feature and the normal illumination feature to obtain the normal feature-independent loss is:
[0068]
[0069]
[0070] Wherein, L1 is the restoration loss, L2 is the normal feature-independent loss, n is the number of input data, in this embodiment, the input data may be the number of second training samples, i represents the i-th input data, and · is the dot product.
[0071] The embodiment of the present application calculates the mean square error between the restored sample and the second training sample to obtain the restoration loss, thereby improving the accuracy of the encoding restoration of the model to be self-encoded when training the model to be self-encoded, and also calculates the cosine similarity between the normal object feature and the normal illumination feature to obtain the normal feature-irrelevant loss. Since the normal feature-irrelevant loss can be characterized as the correlation between the normal object feature and the normal illumination feature, the accuracy of the encoding decomposition of the second training sample by the model to be self-encoded can be improved when iteratively training the model to be self-encoded, so that the normal object feature and the normal illumination feature obtained by the encoding decomposition of the model to be self-encoded are irrelevant, ensuring that the normal illumination feature is not included in the normal object feature, and ensuring that the normal illumination feature is not included in the normal object feature. This facilitates improving the accuracy of extracting standard object features and normal object features.
[0072] Step S13, classifying the sample sources of the normal object features by using the to-be-trained discriminant model of the to-be-trained standard extraction model to obtain a second classification result, and determining a second training loss based on the second classification result and the second classification label;
[0073] It should be noted that the discriminant model to be trained is an untrained neural network, and the sample source classification refers to the source of samples for judging the characteristics of normal objects. The sample source labels in the embodiment of the present application can be divided into two categories, including a first sample and a second sample. Exemplarily, in the discriminant model to be trained, the first sample can be labeled 0, and the second sample can be labeled 1. The second training loss includes a generator loss and a discriminator loss. The discriminant loss refers to the loss corresponding to the discriminant model to be trained, and the generation loss refers to the loss of the generator replaced by the autoencoder model to be trained within the preset game strategy. The generation loss does not affect the first training loss of the autoencoder model to be trained. In a feasible embodiment, step S13 also includes:
[0074] Step S131, classifying the sample sources of the normal object features by using the discriminant model to be trained, obtaining the probability that the sample sources of the normal object features are the first sample and the second sample respectively, and obtaining a second classification result;
[0075] Step S132: Calculate a second training loss of the standard extraction model to be trained according to the second classification result and the second classification label.
[0076] It should be noted that the second classification label includes the first sample and the second sample, and the sample source classification refers to the probability of predicting the source of the sample of the normal object feature as the first sample, and the probability of predicting the source of the sample of the normal object feature as the second sample. The second classification result includes the probability that the normal object feature is the first sample and the probability that the normal object feature is the second sample. The second training loss includes generation loss and discrimination loss. Exemplarily, the second training loss of the standard extraction model to be trained can be calculated according to the second classification result and the second classification label by preset game loss information. The preset game loss information refers to the loss function for calculating the second training loss of the standard extraction model to be trained, and the preset game loss information includes a generator loss function and a discriminator loss function.
[0077] Exemplarily, steps S131 to S132 include: classifying the sample sources of the normal object features according to the discriminant model to be trained and the second classification label, predicting the probability that the sample source of the normal object features is the first sample, and predicting the probability that the sample source of the normal object is the second sample; calculating the second training loss of the standard extraction model to be trained according to the preset game loss information and the second classification result.
[0078] Exemplarily, the calculation method of determining the second classification result in step S131 is:
[0079]
[0080]
[0081]
[0082] in, is the second classification result, W3 and b3 are the discriminant learning parameters of the discriminant model to be trained, the discriminant learning parameters can be updated iteratively, and Softmax is a function used to calculate probability.
[0083] Exemplarily, the function for calculating the generation loss is:
[0084]
[0085] The function for calculating the discriminative loss is:
[0086]
[0087] Among them, L G To generate the loss, L D is the discrimination loss. obj ~P1(f obj ) represents the source of the second training sample of the input normal object feature as the sample of the second sample, fobj ~P0(f obj ) is the source of the second training sample for inputting normal object features, which is the sample of the first sample, and E refers to the expectation.
[0088] The embodiment of the present application determines the standard extraction model to be trained by presetting the game strategy, and replaces the generator in the standard extraction model to be trained with the self-encoding model to be trained, so that the normal object features of the self-standard extraction model to be trained can be detected by the discriminant model to be trained to ensure that the normal object features extracted by the self-standard extraction model to be trained do not contain other interference features. Since the samples input into the self-standard extraction model to be trained are all second training samples, and each second training sample is an object of the same type and its inherent properties are similar, the normal object features decomposed by the self-encoding model to be trained should be similar.
[0089] Since the training purpose of the generator in the standard extraction model to be trained is to make the discriminator unable to distinguish whether the data is generated by the generator, and the training purpose of the discriminator is to be able to judge whether the data is generated by the generator. The indicator of good training is that the generator successfully makes the discriminator invalid; therefore, the generator and discriminator in the standard extraction model to be trained can be used to detect whether the normal object features decomposed by the autoencoder model to be trained are consistent. When the standard extraction model to be trained cannot distinguish which sample the normal object features belong to, it means that the normal object training features extracted by the autoencoder model to be trained are standard and interference-free.
[0090] Step S14, aggregating the first training loss and the second training loss to obtain a total loss for standard extraction, iteratively optimizing the standard extraction model to be trained according to the total loss for standard extraction, and obtaining a trained standard extraction model;
[0091] Step S15: extracting the standard object features and the standard illumination features from the preset normal samples based on the standard extraction model.
[0092] It should be noted that the total loss of standard extraction is the sum of the first training loss and the second training loss. Since the autoencoder model to be trained replaces the generator in the standard extraction model to be trained, the autoencoder model to be trained and the discriminant model to be trained are optimized based on the total loss of standard extraction, thereby improving the training speed of the standard extraction model to be trained and improving the accuracy of the standard extraction model in extracting standard object features and standard illumination features from preset normal samples.
[0093] Exemplarily, step S14 to step S15 include: calculating the sum of the first training loss and the second training loss to obtain a standard extraction total loss, iteratively optimizing the standard extraction model to be trained according to the standard extraction total loss, until the standard extraction total loss converges to a preset convergence threshold to obtain a standard extraction model. Based on the standard extraction model, extract the standard object feature and the standard illumination feature from the preset normal sample.
[0094] Exemplarily, the calculation method for iteratively optimizing the standard extraction model to be trained according to the total loss of standard extraction can be:
[0095] L auto =L1+L2+L G +L D
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103] Among them, L auto is the standard extraction total loss, L1 is the restoration loss, L2 is the normal feature-independent loss, and L G To generate the loss, L D is the discriminant loss, θ1 is the learnable parameter of Transposed CNN, W1 and b1 are both normal object training learning parameters of the normal object feature, W2 and b2 are normal illumination training learning parameters of the normal illumination feature, W3 and b3 are the discriminant learning parameters of the discriminant model to be trained, W′1 and b′1 are the updated normal object training learning parameters, W′2 and b′2 are the updated normal illumination training learning parameters, θ′1 is the updated learnable parameter of Transposed CNN, W′3 and b′3 are the updated discriminant learning parameters. α is the learning rate, which can be set to 0.002 in the embodiment of the present application.
[0104] The embodiment of the present application obtains a standard extraction model by training the standard extraction model to be trained, thereby improving the accuracy of extracting standard object features and standard lighting features from preset normal samples.
[0105] Step S20, inputting the first training sample into the defect detection model to be trained, extracting features of the first training sample through the feature purification model to be trained to obtain training non-defect features and training defect features, and inputting the training defect features into the classification model to be trained to obtain a first classification result;
[0106] It should be noted that the first training sample is a normal metal image sample and / or a metal image sample with defects, the training non-defect features are the properties, illumination and other features of the surface of the object without defects in the first training sample, and the training defect features are the defect features of the surface of the object with defects in the first training sample. The training non-defect features include training illumination features and training object features.
[0107] Exemplarily, based on the feature purification model to be trained, the common samples are subjected to feature extraction through preset purification learning parameters to obtain training object features, training illumination features and training defect features. The purification learning parameters include object purification learning parameters for training object features, illumination purification learning parameters for training illumination features and defect purification learning parameters for training defect features.
[0108] Exemplarily, based on the object purification learning parameters, the illumination purification learning parameters and the defect purification learning parameters, the formula for decoupling the first training sample to obtain the training object feature, the training illumination feature and the training defect feature is:
[0109]
[0110]
[0111] f a =W6*X+b6
[0112] in, is the training object feature, f a To train defect features, To train illumination features, W4 and b4 are object purification learning parameters for extracting training object features, W5 and b5 are object purification learning parameters for extracting training illumination features, and W6 and b6 are object purification learning parameters for extracting training defect features.
[0113] Step S30, determining a similarity loss between the standard non-defect feature and the training non-defect feature, determining a cosine loss between the training defect feature and the training non-defect feature, and determining a classification loss based on the first classification label and the first classification result;
[0114] It should be noted that the similarity loss can be used to describe the similarity between the training non-defect features and the standard non-defect features. The more the similarity loss converges to the preset similarity value, the more similar the training non-defect features are to the standard non-defect features, which means that the training non-defect features obtained by decoupling the feature purification model to be trained are more accurate. The preset similarity value can be determined based on the actual situation. The cosine loss is used to describe the degree of difference between the training defect features and the training non-defect features. The more the cosine loss converges, the greater the difference between the training defect features and the training non-defect features, which means that the training defect features are less related to the training non-defect features. The classification loss is used to describe the accuracy of the classification model to be trained in predicting whether the first training sample has defects based on the training defect features. The more the classification loss converges, the higher the accuracy of the classification model to be trained in predicting whether the first training sample has defects. In a feasible embodiment, the step of determining the similarity loss between the standard non-defect features and the training non-defect features in step S30 includes:
[0115] Step A10, calculating the divergence loss between the standard object feature and the training object feature to obtain the object similarity loss;
[0116] Step A10, calculating the divergence loss between the standard illumination feature and the training object feature to obtain the illumination similarity loss.
[0117] It should be noted that the object similarity loss can be obtained by calculating the KL divergence loss between the standard object feature and the training object feature, or by calculating the JS divergence. By calculating the object similarity loss, the degree of correlation between the standard object feature and the training object feature can be determined, and by calculating the illumination similarity loss, the degree of correlation between the standard illumination feature and the training object feature can be determined. This makes it easier to ensure that the training object features extracted by the feature purification model to be trained do indeed only contain object features, and that the illumination features extracted by the feature purification model to be trained do indeed only contain illumination features.
[0118] Exemplarily, the formula for calculating object similarity loss is:
[0119]
[0120] Among them, KL obj is the object similarity loss, is the training object feature, f obj is a normal object feature. n is the number of input data, and in this embodiment, the number of input data may be the number of first training samples.
[0121] Exemplarily, the formula for calculating object similarity loss is:
[0122]
[0123] Among them, KL env is the illumination similarity loss, f env For normal lighting characteristics, To train the lighting features.
[0124] The embodiment of the present application calculates the object similarity loss and the illumination similarity loss, thereby facilitating the training of the training object features and the training illumination features extracted by the training purification model to be trained with higher accuracy, which are closer to the standard object features and the standard illumination features.
[0125] In one feasible embodiment, the step of determining the cosine loss between the training defect feature and the training non-defect feature in step S30 includes:
[0126] Step B10, calculating the cosine similarity between the training defect feature and the training object feature to obtain the cosine object loss;
[0127] Step B20, calculating the cosine similarity between the training defect feature and the training illumination feature to obtain the cosine illumination loss.
[0128] It should be noted that the cosine object loss can be used to describe the correlation between the training defect feature and the training object feature, and the cosine illumination loss can be used to describe the correlation between the training defect feature and the training illumination feature.
[0129] Exemplarily, the formula for calculating the cosine object loss and the formula for calculating the cosine illumination loss are:
[0130]
[0131]
[0132] Among them, L3 is the cosine object loss, L4 is the cosine illumination loss, To train the illumination features, is the training object feature, f a It is the training defect feature.
[0133] The embodiment of the present application calculates the cosine object loss and the cosine illumination loss, thereby facilitating the training defect features extracted by the training purification model to be trained to be cleaner, so that the training defect features do not include the training illumination features and the training object features, thereby improving the accuracy of extracting the training defect features.
[0134] In a feasible embodiment, the step of determining the classification loss based on the first classification label and the first classification result in step S30 includes:
[0135] Step C10, determining the classification probability corresponding to the first classification label from the first classification result;
[0136] Step C20, calculating the cross entropy loss based on the classification probability.
[0137] It should be noted that the classification loss includes cross entropy loss, the classification model to be trained is a neural network model that has not been trained, and the classification model to be trained is used to detect the probability of defects in an object. The first classification label includes normal samples and abnormal samples, and the first classification result is the sum of the probability that the input data is a normal sample and the probability of an abnormal sample. It can be considered as the probability that the classification model to be trained outputs a normal sample when a normal sample is input, and the sum of the probability that the classification model to be trained outputs an abnormal sample when an abnormal sample is input. Classification loss can be used to describe the degree of training of the classification model to be trained. When the normal sample in the first training sample is input into the feature purification model to be trained, the training non-defect feature will be output, so that the non-defect feature is input into the classification model to be trained, and the classification model to be trained performs label classification on the training non-defect feature to obtain the first classification result. When the abnormal sample in the first training sample is input into the feature purification model to be trained, the extracted training defect feature will be input into the classification model to be trained, so that the classification model to be trained can perform label classification on the sample corresponding to the training defect feature. Thus, the first classification result is obtained.
[0138] Exemplarily, the formula for calculating the first classification result is:
[0139]
[0140]
[0141]
[0142] in, is the first classification result, W7 and b7 are the classification learning parameters of the classification model to be trained, and f a It is the training defect feature.
[0143] Exemplarily, the formula for calculating classification loss is:
[0144]
[0145] Among them, L5 is the classification loss, y2 is the defect label or normal label, is the first classification result. n is the number of input data. In this embodiment, the number of input data may be the number of training defect features.
[0146] The embodiment of the present application calculates the classification loss, thereby training the classification model to be trained, thereby improving the accuracy of the classification model to be trained in detecting defects in objects.
[0147] Step S40, optimizing the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss, to obtain a trained feature purification model and a trained classification model.
[0148] It should be noted that the feature purification model is used for non-interference defect features, and the classification model is used to perform defect detection based on the defect features extracted by the feature purification model to obtain the probability of defects on the metal surface. The feature purification model to be trained and the classification model to be trained are iteratively optimized. When the sum of the similarity loss, the cosine loss and the classification loss converges to a preset training threshold, it means that the training of the purification model to be trained and the classification model to be trained are successful, thereby obtaining a feature purification model and a classification model. The preset training threshold can be set based on actual conditions.
[0149] In a feasible embodiment, step S40 further includes:
[0150] Step S41, calculating the sum of the similarity loss, the cosine loss and the classification loss to obtain the total model loss;
[0151] Step S42, based on the total loss of the model, respectively update the purification learning parameters corresponding to the feature purification model to be trained and the classification learning parameters corresponding to the classification model to be trained, so as to iteratively optimize the feature purification model to be trained and the classification model to be trained to obtain the trained feature purification model and the trained classification model.
[0152] It should be noted that the total model loss is the total loss of the feature purification model to be trained and the classification model to be trained. The purification learning parameters include the object purification learning parameters of the training object features, the illumination purification learning parameters of the training illumination features, and the defect purification learning parameters of the training defect features. The purification learning parameters are used to iteratively optimize the feature purification model to be trained, so that the feature purification model to be trained can improve the accuracy of extracting training object features, training illumination features, and training defect features, so that the feature purification model to be trained can extract non-interference training defect features. The classification learning parameters are used to iteratively optimize the classification model to be trained, so that the classification model to be trained can improve the accuracy of predicting whether an object has defects.
[0153] Exemplarily, steps S41 to S42 include: calculating the sum of the similarity loss, the cosine loss and the classification loss to obtain the total model loss; based on the total model loss, updating the object purification learning parameters, illumination purification learning parameters, defect purification learning parameters corresponding to the feature purification model to be trained, and the classification learning parameters corresponding to the classification model to be trained, respectively, so as to iteratively optimize the feature purification model to be trained and the classification model to be trained until the total model loss converges to a preset convergence threshold, and the preset convergence threshold can be set based on actual conditions, so as to obtain a feature purification model and a classification model.
[0154] Exemplarily, based on the total model loss, the formulas for updating the object purification learning parameters, illumination purification learning parameters, defect purification learning parameters corresponding to the feature purification model to be trained, and the classification learning parameters corresponding to the classification model to be trained include:
[0155] L total =L3+L4+L5+KL obj +KL env
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164] Among them, L total is the total loss of the model, KL obj KL is the object similarity loss envis the illumination similarity loss, L3 is the cosine object loss, L4 is the cosine illumination loss, L5 is the classification loss, and β is the learning rate, which can be set to 0.0001 in the embodiment of the present application. W4 and b4 are object purification learning parameters for extracting training object features, W5 and b5 are illumination purification learning parameters for extracting training illumination features, and W6 and b6 are defect purification learning parameters for extracting training defect features. W7 and b7 are classification learning parameters of the classification model to be trained. W′4 and b′4 are updated object purification learning parameters for extracting training object features, W′5 and b′5 are updated illumination purification learning parameters for extracting training illumination features, W′6 and b′6 are updated defect purification learning parameters, and W′7 and b′7 are updated classification learning parameters.
[0165] The embodiment of the present application obtains standard non-defect features, so that when training the feature purification model to be trained to extract training non-defect features, the similarity loss between the standard non-defect features and the training non-defect features can be determined, so that the feature purification model to be trained can extract training non-defect features that are closer to the standard non-defect features, so that the features that interfere with defect detection are decoupled from the training non-defect features, and it can also avoid that the training non-defect features extracted by the feature purification model to be trained include defect features, thereby improving the accuracy of extracting training defect features.
[0166] In addition, when training the to-be-trained purification model, the cosine loss between the training defect features and the training non-defect features will also be calculated, so that the training defect features obtained by decoupling the to-be-trained feature purification model are independent of the training non-defect features. Since the to-be-trained feature purification model can be trained to decouple and obtain more standard training non-defect features, when calculating the cosine loss, the accuracy of the cosine loss can also be improved, thereby improving the accuracy of the to-be-trained feature purification model in extracting the training defect features and reducing the influence of interference features on the training defect features. Since the classification loss of the classification model to be trained can also reflect the accuracy of the feature purification model in extracting training defect features, the feature purification model to be trained and the classification model to be trained are optimized together through similarity loss, cosine loss and classification loss, which can improve the accuracy of the feature purification model to be trained in extracting clean training defect features. After iterative optimization of the feature purification model to be trained and the classification model to be trained, a trained feature purification model and a trained classification model are obtained, so that the defect features extracted by the feature purification model do not contain interference features, and thus the defect features do not contain illumination features. When the classification model performs defect detection on the surface of a metal object based on the defect features, the accuracy of metal surface defect detection can be improved, thereby reducing the false alarm rate and solving the technical problem of high false alarm rate of metal surface defect detection caused by more light on the metal surface.
[0167] Embodiment 2
[0168] Further, refer to Figure 4 Based on the above embodiment of the present application, in another embodiment of the present application, the same or similar contents as the above embodiment can be referred to the above introduction, and will not be repeated later. On this basis, after the step of optimizing the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss to obtain the feature purification model and the classification model, it also includes:
[0169] Step X10, obtaining a sample to be detected, and extracting the features of the defects to be detected in the sample to be detected by using the feature purification model;
[0170] Step X20, using the classification model, classify the labels of the defect features to be detected to obtain the probability that the defect features to be detected are defect labels.
[0171] It should be noted that the sample to be detected is a sample that needs to be tested on the surface of a metal object, and the defect feature to be detected is the defect feature extracted from the sample to be detected by the feature purification model. The feature purification model is a trained feature purification model to be trained. The feature purification model does not need to be constrained by standard non-defect features, nor does it need to calculate the cosine similarity between the defect feature to be detected and other features in the sample to be detected. After the sample to be detected is input into the feature purification model, the feature purification model can directly extract the defect feature to be detected from the sample to be detected. Therefore, by detecting defects on the surface of metal objects through the feature purification model and the classification model, the efficiency and accuracy of detecting defects on the surface of metal objects can be improved.
[0172] Exemplarily, step X10 to step X20 include: obtaining a sample to be detected, and extracting the defect features to be detected from the sample to be detected through the feature purification model; labeling the defect features to be detected through the classification model to obtain the probability that the defect features to be detected are defect labels, and the probability can be output for inspection personnel to view.
[0173] For a better understanding of the embodiments of the present application, refer to Figure 5 , Figure 5 The flow chart of object defect detection for feature extraction model and classification model. Input data to the feature extraction model, the input data can be the sample to be detected, the feature extractor extracts defect features from the input data, the defect features can be the defect features to be detected corresponding to the sample to be detected, the classification model obtains the defect features and outputs the results, the output results are the probability of the input sample to be detected having defects.
[0174] Embodiment 3
[0175] Reference Figure 6The embodiment of the present application further provides an object defect detection optimization device, the object defect detection optimization device comprising:
[0176] An acquisition module 10 is used to acquire a first training sample, a standard non-defect feature, and a first classification label of the first training sample;
[0177] An extraction and classification module 20 is used to input the first training sample into the defect detection model to be trained, extract features of the first training sample through the feature purification model to be trained to obtain training non-defect features and training defect features, and input the training defect features into the classification model to be trained to obtain a first classification result;
[0178] a loss determination module 30, configured to determine a similarity loss between the standard non-defect feature and the training non-defect feature, determine a cosine loss between the training defect feature and the training non-defect feature, and determine a classification loss based on the first classification label and the first classification result;
[0179] The optimization module 40 is used to optimize the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss, so as to obtain a trained feature purification model and a trained classification model.
[0180] Optionally, the acquisition module 10 is further used for:
[0181] Obtaining a second training sample, a second classification label of the second training sample, and determining a standard extraction model to be trained based on a preset game strategy;
[0182] Inputting the second training sample into the standard extraction model to be trained, performing feature extraction on the second training sample through the autoencoder model to be trained of the standard extraction model to be trained, obtaining normal object features and normal illumination features, determining restored samples of the normal object features and the normal illumination features, and determining a first training loss according to the normal object features, the normal illumination features, the restored samples, and the second training samples;
[0183] Using the to-be-trained discriminant model of the to-be-trained standard extraction model, classifying the sample source of the normal object features to obtain a second classification result, and determining a second training loss based on the second classification result and the second classification label;
[0184] Aggregating the first training loss and the second training loss to obtain a total loss for standard extraction, iteratively optimizing the standard extraction model to be trained according to the total loss for standard extraction, and obtaining a trained standard extraction model;
[0185] The standard extraction model is used to extract features from normal samples to obtain the standard object features and the standard illumination features.
[0186] Optionally, the acquisition module 10 is further used for:
[0187] By using the to-be-trained sub-encoding model of the to-be-trained auto-encoding model, extracting features from the second training sample to obtain the normal object features and the normal illumination features;
[0188] Calculating the cosine similarity between the normal object feature and the normal illumination feature to obtain the normal feature irrelevant loss;
[0189] Based on the to-be-trained decoding model of the to-be-trained autoencoder model, performing feature restoration on the normal object features and the normal illumination features to obtain restored samples;
[0190] The mean square error between the restored sample and the second training sample is calculated to obtain the restoration loss.
[0191] Optionally, the acquisition module 10 is further used for:
[0192] Using the discriminant model to be trained, classifying the sample sources of the normal object features, obtaining the probability that the sample sources of the normal object features are the first sample and the second sample, and obtaining a second classification result;
[0193] A second training loss of the standard extraction model to be trained is calculated according to the second classification result and the second classification label.
[0194] Optionally, the loss determination module 30 is further used to:
[0195] Calculating the divergence loss between the standard object features and the training object features to obtain the object similarity loss;
[0196] The divergence loss between the standard illumination feature and the training object feature is calculated to obtain the illumination similarity loss.
[0197] Optionally, the loss determination module 30 is further used to:
[0198] Calculating the cosine similarity between the training defect feature and the training object feature to obtain the cosine object loss;
[0199] The cosine similarity between the training defect feature and the training illumination feature is calculated to obtain the cosine illumination loss.
[0200] Optionally, the loss determination module 30 is further used to:
[0201] Determine a classification probability corresponding to the first classification label from the first classification result;
[0202] A cross entropy loss is calculated based on the classification probabilities.
[0203] Optionally, the optimization module 40 is further used for:
[0204] Calculate the sum of the similarity loss, the cosine loss and the classification loss to obtain the total model loss;
[0205] Based on the total loss of the model, the purification learning parameters corresponding to the feature purification model to be trained and the classification learning parameters corresponding to the classification model to be trained are updated respectively, so as to iteratively optimize the feature purification model to be trained and the classification model to be trained to obtain the trained feature purification model and the trained classification model.
[0206] Optionally, the optimization module 40 is further used for:
[0207] Acquire a sample to be detected, and extract the features of the defects to be detected in the sample to be detected by using the feature purification model;
[0208] The classification model is used to classify the defect features to be detected into labels, and the probability that the defect features to be detected are defect labels is obtained.
[0209] The object defect detection optimization device provided by the present application adopts the object defect detection optimization method in the above-mentioned embodiment, aiming to solve the technical problem of high false alarm rate of metal surface defect detection caused by more light on the metal surface. Compared with the prior art, the beneficial effects of the object defect detection optimization method provided by the embodiment of the present application are the same as the beneficial effects of the object defect detection optimization method provided by the above-mentioned embodiment, and the other technical features in the object defect detection optimization device are the same as the features disclosed in the above-mentioned embodiment method, which will not be repeated here.
[0210] Embodiment 4
[0211] An embodiment of the present application provides an electronic device, which may be a playback device, and the electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the object defect detection optimization method in the above-mentioned embodiment.
[0212] Reference below Figure 7, which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (portable Android devices), PMPs (portable media players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0213] like Figure 7 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a ROM (Read-Only Memory) or a program loaded from a storage device into a RAM (Random Access Memory). In the RAM, various programs and data required for the operation of the electronic device are also stored. The processing device, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0214] Typically, the following systems can be connected to the I / O interface: input devices such as touch screens, touch pads, keyboards, mice, image sensors, microphones, tachometers, gyroscopes, etc.; output devices such as LCDs (Liquid Crystal Displays), speakers, vibrators, etc.; storage devices such as magnetic tapes, hard disks, etc.; and communication devices. The communication device can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.
[0215] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication system, or installed from a storage system, or installed from a ROM. When the computer program is executed by a processing system, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0216] The electronic device provided by the present application adopts the object defect detection optimization method in the above-mentioned embodiment 1 to solve the technical problem of high false alarm rate of metal surface defect detection caused by more light on the metal surface. Compared with the prior art, the beneficial effect of product flow data allocation provided by the embodiment of the present application is the same as the beneficial effect of the object defect detection optimization method provided by the above-mentioned embodiment, and the other technical features in the object defect detection optimization device are the same as the features disclosed in the above-mentioned embodiment method, which will not be repeated here.
[0217] It should be understood that the various parts of the present disclosure can be implemented with hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0218] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0219] Embodiment 5
[0220] This embodiment provides a readable storage medium having computer-readable program instructions stored thereon, and the computer-readable program instructions are used to execute the object defect detection optimization method in the above-mentioned embodiment 1.
[0221] The readable storage medium provided in the embodiment of the present application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor devices, equipment or devices, or any combination of the above. More specific examples of readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable EPROM (Electrical Programmable Read Only Memory, read-only memory) or flash memory, an optical fiber, a portable compact disk CD-ROM (compact disc read-only memory, read-only memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution device, device or device or used in combination with it. The program code contained on the readable storage medium can be transmitted with any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency, radio frequency), etc., or any suitable combination of the above.
[0222] The above-mentioned readable storage medium may be included in the electronic device; or may exist independently without being assembled into the electronic device.
[0223] The above-mentioned readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by an electronic device, the electronic device: obtains a feature purification model to be trained and a classification model to be trained, and obtains a standard non-defect feature of a preset normal sample; based on the feature purification model to be trained, decouples the first training sample into a training non-defect feature and a training defect feature; determines the similarity loss between the standard non-defect feature and the training non-defect feature, determines the cosine loss between the training defect feature and the training non-defect feature, and determines the classification loss based on the first classification label and the first classification result; optimizes the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss to obtain a feature purification model and a classification model.
[0224] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a LAN (local area network) or WAN (Wide Area Network), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0225] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the equipment, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based device that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0226] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of the module does not limit the unit itself in some cases.
[0227] The readable storage medium provided by the present application stores computer-readable program instructions for executing the above-mentioned object defect detection optimization method, aiming to solve the technical problem of high false alarm rate of metal surface defect detection caused by more light on the metal surface. Compared with the prior art, the beneficial effects of the readable storage medium provided by the embodiment of the present application are the same as the beneficial effects of the object defect detection optimization method provided by the above-mentioned embodiment, and will not be repeated here.
[0228] Embodiment 6
[0229] The present application also provides a computer program product, including a computer program, which implements the steps of the object defect detection optimization method as described above when executed by a processor.
[0230] The computer program product provided in this application is intended to solve the technical problem of high false alarm rate of metal surface defect detection caused by high light exposure on the metal surface. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiment of this application are the same as the beneficial effects of the object defect detection optimization method provided in the above embodiment, which will not be repeated here.
[0231] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent processing scope of the present application.
Claims
1. An object defect detection optimization method, characterized in that: The object defect detection optimization method is applied to a first device, a defect detection model to be trained is deployed on the first device, the defect detection model to be trained includes a feature purification model to be trained and a classification model to be trained, and the object defect detection optimization method includes: Obtaining a first training sample, a standard non-defect feature, and a first classification label of the first training sample; Inputting the first training sample into the defect detection model to be trained, performing feature extraction on the first training sample through the feature purification model to be trained to obtain training non-defect features and training defect features, and inputting the training defect features into the classification model to be trained to obtain a first classification result; Determine a similarity loss between the standard non-defect feature and the training non-defect feature, determine a cosine loss between the training defect feature and the training non-defect feature, and determine a classification loss based on the first classification label and the first classification result; According to the similarity loss, the cosine loss and the classification loss, the feature purification model to be trained and the classification model to be trained are optimized to obtain a trained feature purification model and a trained classification model.
2. The object defect detection optimization method according to claim 1, characterized in that: The standard non-defect features include standard object features and standard illumination features; The steps to obtain standard non-defect features include: Obtaining a second training sample, a second classification label of the second training sample, and determining a standard extraction model to be trained based on a preset game strategy; Inputting the second training sample into the standard extraction model to be trained, performing feature extraction on the second training sample through the autoencoder model to be trained of the standard extraction model to be trained, obtaining normal object features and normal illumination features, determining restored samples of the normal object features and the normal illumination features, and determining a first training loss according to the normal object features, the normal illumination features, the restored samples, and the second training samples; Using the to-be-trained discriminant model of the to-be-trained standard extraction model, classifying the sample source of the normal object features to obtain a second classification result, and determining a second training loss based on the second classification result and the second classification label; Aggregating the first training loss and the second training loss to obtain a total loss for standard extraction, iteratively optimizing the standard extraction model to be trained according to the total loss for standard extraction, and obtaining a trained standard extraction model; The standard extraction model is used to extract features from normal samples to obtain the standard object features and the standard illumination features.
3. The object defect detection optimization method according to claim 2, characterized in that: The first training loss includes normal feature-independent loss and restoration loss; The step of inputting the second training sample into the standard extraction model to be trained, extracting features of the second training sample through the autoencoder model to be trained of the standard extraction model to be trained, obtaining normal object features and normal illumination features, and determining restored samples of the normal object features and the normal illumination features, and determining the first training loss according to the normal object features, the normal illumination features, the restored samples and the second training samples comprises: By using the to-be-trained sub-encoding model of the to-be-trained auto-encoding model, extracting features from the second training sample to obtain the normal object features and the normal illumination features; Calculating the cosine similarity between the normal object feature and the normal illumination feature to obtain the normal feature irrelevant loss; Based on the to-be-trained decoding model of the to-be-trained autoencoder model, performing feature restoration on the normal object features and the normal illumination features to obtain restored samples; The mean square error between the restored sample and the second training sample is calculated to obtain the restoration loss.
4. The object defect detection optimization method according to claim 2, characterized in that: The second training loss includes a generation loss and a discrimination loss; the second classification result includes a first sample probability and a second sample probability; The step of performing sample source classification on the normal object features by using the to-be-trained discriminant model of the to-be-trained standard extraction model to obtain a second classification result, and determining a second training loss based on the second classification result and the second classification label comprises: Using the discriminant model to be trained, classifying the sample sources of the normal object features, obtaining the probability that the sample sources of the normal object features are the first sample and the second sample, and obtaining a second classification result; A second training loss of the standard extraction model to be trained is calculated according to the second classification result and the second classification label.
5. The object defect detection optimization method according to claim 1, characterized in that: The standard non-defect features include standard object features and standard illumination features; The training non-defect features include training illumination features and training object features; the similarity loss includes object similarity loss and illumination similarity loss; The step of determining the similarity loss between the standard non-defect feature and the training non-defect feature comprises: Calculating the divergence loss between the standard object features and the training object features to obtain the object similarity loss; The divergence loss between the standard illumination feature and the training object feature is calculated to obtain the illumination similarity loss.
6. The object defect detection optimization method according to claim 1, characterized in that: The training non-defect features include training object features and training illumination features; the cosine loss includes cosine object loss and cosine illumination loss; The step of determining the cosine loss between the training defect feature and the training non-defect feature comprises: Calculating the cosine similarity between the training defect feature and the training object feature to obtain the cosine object loss; The cosine similarity between the training defect feature and the training illumination feature is calculated to obtain the cosine illumination loss.
7. The object defect detection optimization method according to claim 1, characterized in that: The classification loss includes a cross entropy loss, and the step of determining the classification loss based on the first classification label and the first classification result includes: Determine a classification probability corresponding to the first classification label from the first classification result; A cross entropy loss is calculated based on the classification probabilities.
8. The object defect detection optimization method according to claim 1, characterized in that: The step of optimizing the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss to obtain the trained feature purification model and the trained classification model comprises: Calculate the sum of the similarity loss, the cosine loss and the classification loss to obtain the total model loss; Based on the total loss of the model, the purification learning parameters corresponding to the feature purification model to be trained and the classification learning parameters corresponding to the classification model to be trained are updated respectively, so as to iteratively optimize the feature purification model to be trained and the classification model to be trained to obtain the trained feature purification model and the trained classification model.
9. The object defect detection optimization method according to claim 1, characterized in that: After the step of optimizing the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss to obtain the trained feature purification model and the trained classification model, the method further includes: Acquire a sample to be detected, and extract the features of the defects to be detected in the sample to be detected by using the feature purification model; The classification model is used to classify the defect features to be detected into labels, and the probability that the defect features to be detected are defect labels is obtained.
10. An object defect detection optimization device, characterized in that: The object defect detection optimization device is applied to a first device, a defect detection model to be trained is deployed on the first device, and the defect detection model to be trained includes a feature purification model to be trained and a classification model to be trained; The object defect detection optimization device comprises: An acquisition module, used to acquire a first training sample, a standard non-defect feature, and a first classification label of the first training sample; an extraction and classification module, configured to input the first training sample into the defect detection model to be trained, extract features of the first training sample through the feature purification model to be trained, obtain training non-defect features and training defect features, input the training defect features into the classification model to be trained, and obtain a first classification result; a loss determination module, configured to determine a similarity loss between the standard non-defect feature and the training non-defect feature, determine a cosine loss between the training defect feature and the training non-defect feature, and determine a classification loss based on the first classification label and the first classification result; An optimization module is used to optimize the feature purification model to be trained and the classification model to be trained according to the similarity loss, the cosine loss and the classification loss, so as to obtain a trained feature purification model and a trained classification model.
11. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; Wherein, the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the steps of the object defect detection optimization method described in any one of claims 1 to 9.
12. A readable storage medium, characterized in that: The readable storage medium is a computer-readable storage medium, on which is stored a program for implementing the object defect detection optimization method. The program for implementing the object defect detection optimization method is executed by a processor to implement the steps of the object defect detection optimization method as described in any one of claims 1 to 9.
Citation Information
Patent Citations
Steel rail surface defect detection method and device based on few-sample learning
CN112330591A
Training method of object defect detection model and object defect detection method and device
CN112348787A