This project proposes an end-to-end framework for unsupervised Anomaly Detection and Localization in images based on Convolutional Auto-Encoders.
The proposed method employs a thresholded pixel-wise difference between reconstructed image and input image to localize anomaly. The threshold is determined by using a subset of anomalous-free training images, i.e validation images, to determine a classification threshold to use at test-time.
It is inspired to by the papers MVTec AD — A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection and Improving Unsupervised Defect Segmentation by Applying Structural Similarity to Autoencoders. The method is devided in 3 steps: training, validating and testing.
There is a total of 5 models based on the Convolutional Auto-Encoder (CAE) architecture implemented in this project:
- mvtecCAE is the model implemented in the MVTec Paper
- baselineCAE is inspired by: https://github.com/natasasdj/anomalyDetection
- inceptionCAE is inspired by: https://github.com/natasasdj/anomalyDetection
- resnetCAE is inspired by: https://arxiv.org/pdf/1606.08921.pdf
- skipCAE is inspired by: https://arxiv.org/pdf/1606.08921.pdf
NOTE:
mvtecCAE, baselineCAE and inceptionCAE are comparable in performance.
WARNING:
resnetCAE and skipCAE, are still being tested, as they are prone to overfitting, which translates in the case of convolutional auto-encoders by copying its inputs without filtering out the defective regions.
The main libraries used in this project with their corresponding versions are listed below:
tensorflow == 2.1.0
ktrain == 0.21.3
scikit-image == 0.16.2
scikit-learn == 0.23.2
For more information, refer to requirement.txt
.
Before installing dependencies, we highly recommend setting up a virtual anvironment (e.g., anaconda environment).
- Make sure pip is up-to-date with:
pip install -U pip
- Install TensorFlow 2 if it is not already installed (e.g.,
pip install tensorflow==2.1
). - Install ktrain:
pip install ktrain
- Install scikit-image:
pip install scikit-image
- Install scikit-learn:
pip install scikit-learn
The above should be all you need on Linux systems and cloud computing environments like Google Colab and AWS EC2. If you are using ktrain on a Windows computer, you can follow the more detailed instructions provided here that include some extra steps.
To train with your own dataset, you need to have a comparable directory structure. For example:
├── class1
│ ├── test
│ │ ├── good
│ │ ├── defect_type_1
│ │ ├── defect_type_2
│ │ └── ...
│ │── train
│ │ └── good
│ └── val
│ └── good
├── class2
│ ├── test
│ │ ├── good
│ │ ├── defect_type_1
│ │ ├── defect_type_2
│ │ └── ...
│ │── train
│ │ └── good
│ └── val
│ └── good
...
- Adnene Boumessouer - https://github.com/AdneneBoumessouer
This project is licensed under the MIT License - see the LICENSE.md file for details
- Paul Bergmann, Michael Fauser, David Sattlegger and Carsten Steger, the authors of the MVTec paper which this project has been inspired by.
- François Chollet, author of Keras.
- Aurélien Géron, autor of the great book Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 2nd Edition.
- Arun S. Maiya, author of the ktrain deep learning library.
- Adrian Rosebrock, founder of the website pyimagesearch for computer vision.