This is the official code that implements the chapter A Contrario multi-scale anomaly detection method for industrial quality inspection, of the book Deep Learning Applications, Volume 4
The algorithm is completely unsupervised and intends to detect anomalies in textured images.
For each textured dataset in MVTec AD (carpet, grid, leather, tile, and wood), we show one image with each type of defect and their corresponding anomaly maps with the ResNet+RegionNFA method. The ground truth in is shown green, and the detection with log-NFA=0 in blue, superimposed to the original image.
First, download repo, create virtual environment and install dependencies
# clone project
git clone https://github.com/mtailanian/nfa_anomaly_detection.git
cd nfa_anomaly_detection
# Create virtualenv and activate it
virtualenv -p python3 .env
source .env/bin/activate
# install dependencies
pip install -r requirements.txt
Next, run it using main.py
, and passing the image path.
A test image is provided in ./images/test_image_01.jpg
For example:
python main.py images/test_image_01.jpg
Other additional optional arguments:
Argument short name | Argument long name | Description | Default value |
---|---|---|---|
image_path | image_path | Path of the image to process | None (mandatory argument) |
-thr | --log_nfa_threshold | Threshold over the computed NFA map, for final segmentation. | 0 |
-dist_thr | --distance_threshold | Threshold over the squared Mahalanobis distances, for computing the candidate regions. | 0.5 |
-s | --size | Input size for ResNet. Must be divisible by 32. | 256 |
-pca | --pca_std | If float: the percentage of the variance to keep in PCA. If int: the number of components to keep. | 35 |
Conference paper:
@inproceedings{tailanian2021multi,
title={A Multi-Scale A Contrario method for Unsupervised Image Anomaly Detection},
author={Tailani{\'a}n, Mat{\'\i}as and Mus{\'e}, Pablo and Pardo, {\'A}lvaro},
booktitle={2021 20th IEEE International Conference on Machine Learning and Applications (ICMLA)},
pages={179--184},
year={2021},
organization={IEEE}
}
Book chapter:
@incollection{tailanian2023contrario,
title={A Contrario multi-scale anomaly detection method for industrial quality inspection},
author={Tailanian, Mat{\'\i}as and Mus{\'e}, Pablo and Pardo, {\'A}lvaro},
booktitle={Deep Learning Applications, Volume 4},
pages={193--216},
year={2023},
publisher={Springer}
}
Copyright (c) 2021-2022 Matias Tailanian [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.