Smart Mining & Manufacturing: Anomaly Detection and localisation using Variational Autoencoder (VAE)

Download the Code

In the previous post we did a webinar on how you can perform Automated Vision-Based Inspection and Defect Detection using a 1-class Support Vector Machine (SVM) on image data. In this workflow we were able to identify the defective products however, there was no indication of what property of the product led to it being classified as defective. In this post we will show how you can detect as well as localise the defect using a Deep Neural Network (DNN), specifically a Variational Autoencoder (VAE). This workflow can be useful in instances where the process of correction is dependent on the type of defect identified.

During quality inspection for chemical materials, metals and minerals, packaging materials, automotive parts, food materials, clothing etc., it is necessary to detect defects and impurities in those products to ensure quality and consistency; and there may exist a vast variety of defects. Because of this variety it may be difficult to collect enough abnormal images to use for training a DNN as the dataset representing the abnormal class would need to be reflective of all possible  variations from a normal product that may constitute an abnormal one. In this article we will detect and localise different types of abnormalities on clothing material by training a DNN on normal image data. This method using only normal images for training may allow you to detect abnormalities that have never been seen before. Figure 1 and 2 are illustrations of what normal and abnormal clothing material looks like, respectively.

 

 

 

 

Figure 1: Image of normal clothing material

 

 

 

 

 

 

 

 

 

 

Figure 2: Sample images of abnormal/defective clothing material

A VAE is composed of two parts, the encoder and the decoder. The encoder takes an image input (the normal clothing material) and outputs a compressed representation (the latent representation). The decoder then takes the compressed representation, decodes it, and recreates the original image as illustrated in Figure 3.

 

 

Figure 3: High-level view of VAE network

VAEs differ from regular autoencoders in that they do not use the encoding-decoding process to reconstruct an input. Instead, the latent space learns the probability distribution of all the training data. Then, when a new image is input to the VAE, the output image is generated from the decoder so that it has the same probability distribution as the latent space (and hence the input data). Therefore, the VAE network is trained using only the normal images allowing it to pick up the properties representative of the normal image dataset. The network then tries to impose those “normal” properties on a test image. If the test image cannot be reconstructed successfully, this indicates an abnormality. This failure to reconstruct a test image arises because features not included in the training data cannot be generated accurately and successfully. Figure 4 illustrates a failure in accurately reconstructing the input image using the VAE. The difference between the input and output image is an indication and localisation of the abnormality.

This Live Script shows how you can use a VAE to detect and localise abnormalities so you can automate and potentially improve the accuracy of your quality inspection process.  

 

 

 

 

 

 

 

 

 

 

Figure 4: Anomaly detection and localisation

We have summarised the anomaly detection methods explored in this post as well as the previous one in the table below:

Table 1: Comparison of the anomaly detection methods

 

 

What Can I Do Next?

Follow us