A defect detection method based on variational autoencoder

Through the combination of variational autoencoder network and decoder network, the Wasserstein distance and sliced ​​Wasserstein distance measurement methods are used to solve the problems of dimensionality disaster and insufficient detection accuracy in industrial defect detection, and achieve high-resolution images Reconstruction and accurate defect detection improve detection accuracy and network stability.

CN114862811BActive Publication Date: 2024-09-03HUNAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210544694.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-19
Publication Date
2024-09-03
Estimated Expiration
2042-05-19

AI Technical Summary

Technical Problem

Existing technologies have limitations in dimensionality disaster, feature extraction and learning normal data distribution in industrial defect detection, resulting in insufficient detection accuracy and stability, especially in high-dimensional complex data environments.

Method used

A defect detection method based on variational autoencoders is used to extract latent features and puzzle reconstruction of the image through variational autoencoders and decoders. The Wasserstein distance is used to fit the prior and posterior distributions, combined with slicing. Wasserstein distance measurement method improves the generalization ability and detection accuracy of the network.

Benefits of technology

It achieves high-resolution image reconstruction and accurate defect detection, improves detection accuracy, reduces computational costs, and improves the stability and generalization capabilities of the network.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114862811B
    Figure CN114862811B
Patent Text Reader

Abstract

The present invention discloses a defect detection method based on a variational autoencoder, which collects a product data set, divides the data set into a training set and a test set, and generates a defect detection method based on a variational autoencoder. i The image blocks are shuffled; a variational autoencoder network is constructed, and the shuffled image blocks are fed into the encoder network to obtain potential features; a decoder network is constructed, and the potential features output by the encoder are fed into the decoder to assist in solving the puzzle, capture global and local information, and thus reconstruct a high-resolution image. The network parameters are updated by back-propagating the model in combination with the preset loss function to obtain a trained model; the model is tested on the test set to complete defect detection. The experimental results show the excellent generalization ability and defect detection ability of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of defect detection, and in particular relates to an industrial defect detection method based on a variational autoencoder. Background Art

[0002] Defect detection is a very important part of manufacturing. It can monitor product quality, enable workers to find problems in time, and thus screen out unqualified products and improve technology. Industrial defect detection that penetrates into each production step plays a vital role in reducing production costs, improving production efficiency, and increasing product quality pass rate. However, traditional manual visual inspection has various limitations and cannot meet the needs of high-speed and accurate inspection.

[0003] Deep learning algorithms are widely used in industrial defect detection, however, some traditional methods, such as One-class SVM and SVDD, rely on manually labeled datasets and suffer from dimensionality curse when directly applied to high-dimensional complex data. Existing methods follow the way of feature extraction and learning normal data distribution. For example, Deep SVDD fits the neural network output to the minimum set. In addition, anomaly detection based on generative adversarial network (GAN) can learn to fit the normal data distribution. This method usually produces visually clearer image data, but they are limited by the lack of operational latent space and unstable training.

[0004] Generative models in the context of variational Bayesian techniques have shown great potential in modeling complex distributions. Variational autoencoders (VAEs) are theoretically good and easy to train. However, observing VAE-based anomaly detection methods, the reconstruction results are often only vaguely similar to the input and are only based on semantics rather than pixel values. For these over-smoothed reconstructed images, it is difficult to set thresholds to classify outliers and normal values.

[0005] Wasserstein distance is used in WAE and SWAE to replace the traditional divergence metric. The network generates high-resolution images while retaining the true posterior. However, the approximate posterior distribution is often too simple and different from the true posterior distribution.

[0006] In view of the above problems, a model and method that can accurately detect defects is urgently needed. Summary of the invention

[0007] In view of the above technical problems, the present invention provides a defect detection method based on variational autoencoder.

[0008] The technical solution adopted by the present invention to solve the technical problem is:

[0009] A defect detection method based on variational autoencoder, the method comprising the following steps:

[0010] Step S100: Collect a data set and divide it into a training set and a test set according to a preset ratio, wherein the training set is a normal sample and the test set includes a normal sample and an abnormal sample;

[0011] Step S200: constructing a defect detection network model, the defect detection network model including a variational autoencoder network and a decoder network;

[0012] Step S300: After initializing the parameters of the variational autoencoder network and the decoder network, the images in the training set are split and shuffled according to the preset rules and then input into the variational autoencoder network to obtain the potential features corresponding to each image block, and the potential features corresponding to each image block are input into the decoder network for jigsaw reconstruction to obtain the reconstructed training image, and the model is back-propagated according to the reconstructed training image, the image in the training set and the preset loss function to update the network parameters, so as to obtain the trained defect detection network model;

[0013] Step S400: Input the pictures in the test set into the trained defect detection network model to obtain a reconstructed test image, obtain the reconstruction test error of the entire picture and the reconstruction test error of each patch picture based on the reconstructed test image and the pictures in the test set, and obtain the defect detection result based on the reconstruction test error of the entire picture, the reconstruction test error of each patch picture and the preset corresponding error threshold.

[0014] Preferably, in step S300, the images in the training set are input into the variational autoencoder network to obtain the potential features corresponding to each block, including:

[0015] Step S310: generating image blocks shuffled according to pseudo labels from the images in the training set, and sending the shuffled image blocks to the variational autoencoder network in parallel;

[0016] Step S320: The variational autoencoder network performs feature extraction and inference on the received shuffled image blocks to obtain potential features corresponding to each image block; wherein the variational autoencoder network uses a standard pre-trained ResNet-50 network on ImageNet, removes the last fully connected layer of the standard pre-trained ResNet-50 network, and uses the second to last layer as a potential feature mapping layer.

[0017] Preferably, step S310 includes:

[0018] Step S311: Use a regular n×n grid to separate the training image to obtain a training patch image

[0019] Step S312: According to S i The patches are shuffled with the pseudo labels to obtain shuffled image blocks, and the shuffled image blocks are sent to the variational autoencoder network.

[0020] Preferably, the potential feature corresponding to each image block in step S320 obeys the posterior distribution, and the prior distribution is introduced. The posterior distribution of the potential feature corresponding to each image block is obtained according to the encoder inference, and the prior distribution and the posterior distribution are fitted by the Wasserstein distance, specifically:

[0021] Introducing t distribution As each grid patch x k The prior distribution of the latent features p(z k ):

[0022]

[0023] Where ν represents the number of degrees of freedom, Γ is the gamma function;

[0024] The variational autoencoder network infers the received shuffled image blocks to obtain the posterior distribution q(z) of the potential features corresponding to each image block k |x k );

[0025] According to the Wasserstein distance, the prior distribution p(z k ) and the posterior distribution q(z k |x k ) distribution differences between them.

[0026] Preferably, the prior distribution p(z k ) and the posterior distribution q(z k |x k The specific distribution differences between them are:

[0027]

[0028] in, represents the d-dimensional unit sphere, for a fixed value Indicates p (x) The marginal distribution of W p is the p-wasserstein distance.

[0029] Preferably, in step S300, the potential features corresponding to each block are input into the decoder network for jigsaw reconstruction to obtain a reconstructed training image, including:

[0030] The decoder network reorders the latent features corresponding to each received block, where the decoder network is built as multiple blocks consisting of Upsample-Conv-BN-ReLU layers.

[0031] Preferably, the preset loss function is specifically:

[0032]

[0033] in

[0034]

[0035]

[0036] Among them, λ1 and λ2 are hyperparameters, is the mean square error between the input data and the reconstructed data, x i is the i-th input image, is the reconstructed image corresponding to the i-th input image, is the inference distribution loss, represents the permutation classification error, S i is the label, z k is the potential feature of the kth image patch, Represents the solution z k The corresponding labels are probability.

[0037] Preferably, in step S400, the defect detection result is obtained according to the reconstruction test error of the entire image, the reconstruction test error of each patch image and a preset corresponding error threshold, including:

[0038] Preferably, when the reconstruction test error of the entire image is less than or equal to a preset first threshold ∈ 0 and the reconstruction test error of each patch image is less than or equal to a preset second threshold ∈ k When , the defect detection result is that the input is normal input, specifically:

[0039]

[0040] in, is the kth image patch of the ith input image, is the reconstructed image corresponding to the kth image block of the ith input image, ∈0, ∈ k They are respectively a preset first threshold and a preset second threshold.

[0041] The above-mentioned defect detection method based on variational autoencoder can infer the distribution of normal data through the encoder network, and solve the puzzle through the decoder network as an aid. The network can capture global and local information, thereby supporting the network to reconstruct high-resolution images, and back-propagate the model to update the network parameters according to the reconstructed training images, the images in the training set and the preset loss function to obtain a trained defect detection network model; the pictures in the test set are input into the trained defect detection network model to obtain a reconstructed test image, and the reconstruction test error of the entire picture and the reconstruction test error of each patch picture are obtained according to the reconstructed test image and the pictures in the test set, and the defect detection result is obtained according to the reconstruction test error of the entire picture, the reconstruction test error of each patch picture and the preset corresponding error threshold, and the defect detection accuracy is high. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A flow chart of a defect detection method based on a variational autoencoder of the present invention;

[0043] Figure 2 A structural diagram of the defect detection network model designed for the present invention;

[0044] Figure 3 This is a visualization diagram of the test results of the method of the present invention on the MVTec-AD dataset. DETAILED DESCRIPTION

[0045] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings.

[0046] In one embodiment, Figure 1 As shown, a defect detection method based on variational autoencoder comprises the following steps:

[0047] Step S100: Collect a data set and divide it into a training set and a test set according to a preset ratio, wherein the training set is a normal sample and the test set includes normal samples and abnormal samples.

[0048] Specifically, the core idea of ​​the anomaly detection network model constructed by the present invention is to model the normal data distribution, and the situations outside the normal distribution can be detected as anomalies. Therefore, the collected original data set needs to be split (that is, the training set only contains normal data, and the test set contains normal and abnormal data). Thereby, an unsupervised anomaly detection scenario is configured, and only normal samples are used during training. The experiments of the present invention are carried out on the MVTec-AD data set. The network is trained and tested using the three categories of bottles, tablets, and capsules in the data set.

[0049] For example, when training and testing the bottle data set, the N samples contained in it are represented as D X (D X ={x1,x2,…,x N}),in is a defect-free manifold from Euclidean space The core goal of anomaly detection is to detect a single input data point sampled from D X Model and learn its manifold make To represent space, Represents x i potential characteristics.

[0050] Step S200: construct a defect detection network model, which includes a variational autoencoder network and a decoder network.

[0051] Step S300: After initializing the parameters of the variational autoencoder network and the decoder network, the images in the training set are split and shuffled according to the preset rules and then input into the variational autoencoder network to obtain the potential features corresponding to each image block, and the potential features corresponding to each image block are input into the decoder network for jigsaw reconstruction to obtain the reconstructed training image, and the model is back-propagated according to the reconstructed training image, the image in the training set and the preset loss function to update the network parameters, so as to obtain the trained defect detection network model;

[0052] In one embodiment, Figure 2 As shown, in step S300, the images in the training set are input into the variational autoencoder network to obtain the potential features corresponding to each block, including:

[0053] Step S310: Generate image blocks that are shuffled according to pseudo labels from the images in the training set, and send the shuffled image blocks to the variational autoencoder network in parallel.

[0054] Further, step S310 includes:

[0055] Step S311: Use a regular n×n grid to separate the training image to obtain a training patch image

[0056] Step S312: According to S i The patches are shuffled with the pseudo labels to obtain shuffled image blocks, and the shuffled image blocks are sent to the variational autoencoder network.

[0057] Specifically, given a normal sample during training, we first separate the training patch images using a regular n×n grid Then according to S iThe patches are shuffled according to the pseudo labels of n. For example, keep n = 3, and S contains 1000 randomly permuted arrays. That is, the image is divided into 9 patches, and for each training iteration, according to S i The patches are shuffled with pseudo labels and sent to the variational autoencoder network in parallel.

[0058] Step S320: The variational autoencoder network performs feature extraction and inference on the received shuffled image blocks to obtain potential features corresponding to each image block; wherein the variational autoencoder network uses a standard pre-trained ResNet-50 network on ImageNet, removes the last fully connected layer of the standard pre-trained ResNet-50 network, and uses the second to last layer as a potential feature mapping layer.

[0059] Specifically, we use a standard pre-trained ResNet-50 network on ImageNet for inference, removing the last fully connected layer and using the penultimate layer as a latent feature mapper.

[0060] In one embodiment, the potential feature corresponding to each image block in step S320 obeys the posterior distribution, and the prior distribution is introduced. The posterior distribution of the potential feature corresponding to each image block is obtained according to the encoder inference, and the prior distribution and the posterior distribution are fitted by the Wasserstein distance, specifically:

[0061] Introducing t distribution As each grid patch x k The prior distribution of the latent features p(z k ):

[0062]

[0063] Where v represents the number of degrees of freedom, Γ is the gamma function;

[0064] The variational autoencoder network infers the received shuffled image blocks to obtain the posterior distribution q(z) of the potential features corresponding to each image block k |x k );

[0065] According to the Wasserstein distance, the prior distribution p(z k ) and the posterior distribution q(z k |x k ) distribution differences between them.

[0066] Specifically, for each patch latent feature The t distribution Assign it as a prior distribution, where 5 is the degree of freedom. The reason for using 5 degrees of freedom is that the results are more robust and convergent. The posterior distribution q(z) of the potential features corresponding to each image block is obtained in the variational autoencoder network. k |x k ), for the latent feature z i Approximate. Following the variational inference principle, the goal is to minimize q(z k |x k ) and the prior p(z k ), the Wasserstein distance is introduced here to measure the divergence.

[0067] In one embodiment, the prior distribution p(z k ) and the posterior distribution q(z k |x k The specific distribution differences between them are:

[0068]

[0069] in, represents the d-dimensional unit sphere, for a fixed value Indicates p (x) The marginal distribution of W p is the p-wasserstein distance.

[0070] Specifically, Sliced-Wasserstein distance (SWD) can alleviate its high computational cost by linearly slicing (Radon transform) the probability distribution:

[0071]

[0072] in represents the d-dimensional unit sphere, δ(·) represents the one-dimensional Dirac function, and for a fixed Yes X The marginal distribution of .

[0073] On this basis, for the prior distribution p(z k ) and the inference posterior p(z k |x k ) can be defined as:

[0074]

[0075] The cumulative inference loss function is the sum of the sliced-Wasserstein distances for each patch:

[0076]

[0077] where n 2 is the number of patches.

[0078] Finally, the accumulated patch inference distribution ∑q(z k |x k ) can be respectively based on the Student t distribution prior Approximately a mixture of .

[0079] In one embodiment, Figure 2 As shown, in step S300, the potential features corresponding to each block are input into the decoder network for jigsaw reconstruction to obtain a reconstructed training image, including:

[0080] The decoder network reorders the latent features corresponding to each received block, where the decoder network is built as multiple blocks consisting of Upsample-Conv-BN-ReLU layers.

[0081] Specifically, the encoder outputs the latent feature z i Input decoder f θ (·), assists in solving the puzzle, capturing global and local information, and thus reconstructing a high-resolution image.

[0082] In one embodiment, the preset loss function is specifically:

[0083]

[0084] in

[0085]

[0086]

[0087] Among them, λ1 and λ2 are hyperparameters, is the mean square error between the input data and the reconstructed data, x i is the i-th input image, is the reconstructed image corresponding to the i-th input image, is the inference distribution loss, represents the permutation classification error, S i is the label, z k is the potential feature of the kth image patch, Represents the solution z k The corresponding labels are probability.

[0088] Specifically, in the training phase, given a defect-free instance, the objective function consists of three parts:

[0089]

[0090] Through the above objective function, the network can easily simulate the true normal data distribution.

[0091] Step S400: Input the pictures in the test set into the trained defect detection network model to obtain a reconstructed test image, obtain the reconstruction test error of the entire picture and the reconstruction test error of each patch picture based on the reconstructed test image and the pictures in the test set, and obtain the defect detection result based on the reconstruction test error of the entire picture, the reconstruction test error of each patch picture and the preset corresponding error threshold.

[0092] Furthermore, in step S400, the defect detection result is obtained according to the reconstruction test error of the entire image, the reconstruction test error of each patch image and the preset corresponding error threshold, including:

[0093] In one embodiment, when the reconstruction test error of the entire image is less than or equal to a preset first threshold ∈ 0 and the reconstruction test error of each patch image is less than or equal to a preset second threshold ∈ k When , the defect detection result is that the input is normal input, specifically:

[0094]

[0095] in, is the kth image patch of the ith input image, is the reconstructed image corresponding to the kth image block of the i-th input image. ∈0, ∈ k They are respectively a preset first threshold and a preset second threshold.

[0096] Specifically, the criterion for a defect-free instance is that the reconstruction error of the entire image and each patch should be below a threshold.

[0097] The above defect detection method based on variational autoencoder proposes a model structure for anomaly detection, which is a simple and effective method to infer the distribution of normal data. By solving the puzzle as an auxiliary task, the network can capture global and local information, which encourages the network to generate high-resolution images. A slice Wasserstein measure is introduced to address the problem of feature collapse, thereby improving the generalization ability of the network, and their computational cost is lower than that of ordinary divergence. This method shows superior performance in anomaly detection, including but not limited to industrial defect detection.

[0098] The above is a detailed introduction to a defect detection method based on a variational autoencoder provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the core idea of ​​the present invention. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.

Claims

1. A defect detection method based on variational autoencoder, characterized in that: The method comprises the following steps: Step S100: Collecting a data set and dividing it into a training set and a test set according to a preset ratio, wherein the training set is a normal sample, and the test set includes normal samples and abnormal samples; Step S200: constructing a defect detection network model, wherein the defect detection network model includes a variational autoencoder network and a decoder network; Step S300: After initializing the parameters of the variational autoencoder network and the decoder network, the images in the training set are split and shuffled according to preset rules and then input into the variational autoencoder network to obtain the potential features corresponding to each image block, and the potential features corresponding to each image block are input into the decoder network for jigsaw reconstruction to obtain a reconstructed training image, and the model is back-propagated according to the reconstructed training image, the image in the training set and the preset loss function to update the network parameters, so as to obtain a trained defect detection network model; Step S400: input the pictures in the test set into the trained defect detection network model to obtain a reconstructed test image, obtain a reconstruction test error of the entire picture and a reconstruction test error of each patch picture according to the reconstructed test image and the pictures in the test set, and obtain a defect detection result according to the reconstruction test error of the entire picture, the reconstruction test error of each patch picture and a preset corresponding error threshold; In step S300, the image in the training set is input into the variational autoencoder network to obtain the potential features corresponding to each block, including: Step S310: generating image blocks that are shuffled according to pseudo labels from the images in the training set, and sending the shuffled image blocks in parallel to the variational autoencoder network; Step S320: the variational autoencoder network performs feature extraction and inference on the received shuffled image blocks to obtain potential features corresponding to each image block; wherein the variational autoencoder network uses a standard pre-trained ResNet-50 network on ImageNet, removes the last fully connected layer of the standard pre-trained ResNet-50 network, and uses the second to last layer as a potential feature mapping layer; Step S310 includes: Step S311: Use a regular n×n grid to separate the training image to obtain a training patch image Step S312: According to S i The pseudo labels of the image are used to shuffle the patches to obtain shuffled image blocks, and the shuffled image blocks are sent to the variational autoencoder network; The potential features corresponding to each image block in step S320 obey the posterior distribution, and the prior distribution is introduced. The posterior distribution of the potential features corresponding to each image block is obtained according to the encoder inference, and the prior distribution and the posterior distribution are fitted by the Wasserstein distance, specifically: Introducing t distribution As each grid patch x k The prior distribution of the latent features p(z k ): Where v represents the number of degrees of freedom, Γ is the gamma function; The variational autoencoder network is used to infer the received shuffled image blocks to obtain the posterior distribution q(z) of the potential features corresponding to each image block. k ∣x k ); According to the Wasserstein distance, the prior distribution p(z k ) and the posterior distribution q(z k ∣x k ) distribution differences between them.

2. The method according to claim 1, characterized in that The prior distribution p(z k ) and the posterior distribution q(z k ∣x k The specific distribution differences between them are: in, represents the d-dimensional unit sphere. For a fixed value of θ, Indicates p (x) The marginal distribution of W p is the p-wasserstein distance.

3. The method according to claim 2, characterized in that In step S300, the potential features corresponding to each block are input into the decoder network for jigsaw reconstruction to obtain a reconstructed training image, including: The decoder network reorders the potential features corresponding to each received block, wherein the decoder network is constructed as a plurality of blocks consisting of Upsample-Conv-BN-ReLU layers.

4. The method according to claim 3, characterized in that The preset loss function is: in Among them, λ1 and λ2 are hyperparameters, is the mean square error between the input data and the reconstructed data, x i is the i-th input image, is the reconstructed image corresponding to the i-th input image, is the inference distribution loss, represents the permutation classification error, S i is the label, z k is the potential feature of the kth image patch, Represents the solution z k The corresponding labels are probability.

5. The method according to claim 4, characterized in that In step S400, the defect detection result is obtained according to the reconstruction test error of the entire image, the reconstruction test error of each patch image and the preset corresponding error threshold, including: When the reconstruction test error of the entire image is greater than or equal to a preset first threshold, the defect detection result is that the input is an abnormal input; When the reconstruction test error of the entire image is less than or equal to a preset second threshold and the reconstruction test error of each patch image is less than or equal to a preset third threshold, the defect detection result is that the input is a normal input.

6. The method according to claim 5, characterized in that When the reconstruction test error of the entire image is less than or equal to a preset first threshold ∈0 and the reconstruction test error of each patch image is less than or equal to a preset second threshold ∈ k When , the defect detection result is that the input is normal input, specifically: in, is the kth image patch of the ith input image, is the reconstructed image corresponding to the kth image block of the ith input image, ∈0, ∈ k They are respectively a preset first threshold and a preset second threshold.