Code Monkey home page Code Monkey logo

anomalydetection's Introduction

Anomaly Detection System for MVTec AD

This is a system capable of anomaly detection for two distinct products from the MVTec Anomaly Detection dataset, screw and metal nut. alt text The whole pipeline is implemented via pipeline.py.

Methods

The machine learning model is based on EfficientAD. https://arxiv.org/abs/2303.14535. The code is built based on https://github.com/nelson1425/EfficientAD.

By using Lightweight Student–Teacher + Autoencoder architecture for anomalies detection and Patch description networks (PDN) for feature extraction. The model enables a fast handling of anomalies with low error rate, making it a perfect choise for abnomaly detection in manufacturing industry.

Challenges

  1. Types and possible locations of defects are unknown --> Use Student–Teacher structure so that it perform well even trained only on normal images.

  2. Industrial settings requires strict runtime limits --> Reduce computational cost by drastically reducing depth for feature extractor, performing down-sampling early, and using light-weight S-T structure.

  3. Violations of logical constraints regarding the position, size, arrangement, etc. --> Use Autoencoder to detect logical anomalies.

Results

alt text

Mean anomaly detection AU-ROC percentages:

Product Model AU-ROC
screw EfficientAD-S 96.8
screw EfficientAD-M 97.4
metal nut EfficientAD-S 98.7
metal nut EfficientAD-M 99.3

Computational efficiency: Latency

Model GPU Latency
EfficientAD-S Quadro RTX 6000 4.0 ms
EfficientAD-M Quadro RTX 6000 5.9 ms

Setup

Packages

Python==3.10
numpy==1.18.5
torch==1.13.0
torchvision==0.14.0
scikit-learn==1.2.2
tifffile==2021.7.30
tqdm==4.56.0
Pillow==7.0.0
scipy==1.7.1
tabulate==0.8.7

Dataset

Download dataset (if you already have downloaded then set path to dataset (--mvtec_ad_path) when calling efficientad.py).

mkdir mvtec_anomaly_detection
cd mvtec_anomaly_detection
wget https://www.mydrive.ch/shares/38536/3830184030e49fe74747669442f0f282/download/420938113-1629952094/mvtec_anomaly_detection.tar.xz
tar -xvf mvtec_anomaly_detection.tar.xz
cd ..

Usage

Training and inference for screw and metal nut:

python mvtec_ad_training/efficientad_2objects.py --dataset mvtec_ad

Training with EfficientAD-M for two kinds of images:

python mvtec_ad_training/efficientad_2objects.py --model_size medium --weights models/teacher_medium.pth --dataset mvtec_ad

Evaluation with Mvtec evaluation code:

python mvtec_ad_evaluation/evaluate_experiment.py --anomaly_maps_dir './output/4/anomaly_maps/mvtec_ad/' --output_dir './output/4/metrics/mvtec_ad/' --evaluated_objects screw

Anomaly detection pipeline for one image:

python pipeline.py --sample_path './mvtec_anomaly_detection/metal_nut/test/scratch/000.png'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.