Giter Site home page Giter Site logo

draem-tensoflow's Introduction

DRAEM-Tensorflow

Tensorflow Implementation of DRAEM - ICCV2021:

@InProceedings{Zavrtanik_2021_ICCV,
    author    = {Zavrtanik, Vitjan and Kristan, Matej and Skocaj, Danijel},
    title     = {DRAEM - A Discriminatively Trained Reconstruction Embedding for Surface Anomaly Detection},
    booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
    month     = {October},
    year      = {2021},
    pages     = {8330-8339}
}

A discriminatively trained reconstruction embedding for surface anomaly detection. DRÆM (Discriminatively Trained Reconstruction Embedding for Surface Anomaly Detection) is a method for detecting anomalies in surfaces, such as defects or damage, using a combination of reconstruction and classification techniques.

Anomaly Detection Process

Datasets

To train on the MVtec Anomaly Detection dataset download the data and extract it. The Describable Textures dataset was used as the anomaly source image set in most of the experiments in the paper. You can run the download_dataset.sh script from the project directory to download the MVTec and the DTD datasets to the datasets folder in the project directory:

./scripts/download_dataset.sh

Requirements

Code was Tested on :

tensorflow                    2.9.2
keras                         2.9.0
Keras-Preprocessing           1.1.2
tensorflow-addons             0.19.0
matplotlib                    3.2.2
glob2                         0.7
regex                         2022.6.2
numpy                         1.21.6

Training

The DRAEM system employs a dual-model approach, consisting of a reconstructive model and a discriminative model. The reconstructive model is responsible for reconstructing augmented images, while the discriminative model predicts an anomaly mask.

To train the reconstructive model, the training dataset must be passed to the 'Train_model_1.py' script as the '--data_path' argument, and the folder containing the anomaly source images must be provided as the '--anomaly_source_path' argument. Additionally, the script requires the specification of the learning rate ('--lr'), the number of training epochs ('--epochs'), the path to store checkpoints ('--checkpoint_path'), and the object name ('--object_name'). If the reconstructive model has been previously trained, and training is to be continued, the '--load_epoch' argument must also be provided. By default, the training starts from the first epoch (0).

Example:

python Train_model_1.py --object_name 'bottle' --lr 0.0001  --epochs 700 --load_epoch 100 --data_path ./datasets/mvtec/ --anomaly_source_path ./datasets/dtd/images/ --checkpoint_path ./checkpoints/ 

For example, after 50 training epochs, the model will be saved in the specified 'checkpoints_path' directory.

The next step is to train the discriminative model, which automatically loads the latest trained reconstructive model from the 'checkpoints_path' directory. The '--load_epoch' argument can be used to specify a previously trained model, if training is to be continued. By default, the training starts from the first epoch (0).

Example :

!python Train_model_2.py --data_path ./datasets/mvtec/ --object_name 'bottle' --anomaly_source_path ./datasets/dtd/images/  --checkpoint_path ./checkpoints/ --load_epoch 100

PreTrained Models

For Now only two classes ['Bottle','Carpet'] were trained on a few Images with 100 epochs on both Models. It is recommended to Train it properly but for Inference our models can be used. PreTrained Models are available here We might add more Models in Future

Inference

To test the Trained Models use the following script. The script automatically Loads the Latest(highest epochs) Models from checkpoint_path and Displays Images and their respective Predicted Heatmaps. Example:

!python Test.py --data_path ./datasets/mvtec/  --object_name 'bottle'  --checkpoint_path ./checkpoints/

Results

Both Models were Trained For 100 epochs and only on few Images for Testing Purposes.

draem-tensoflow's People

Contributors

hamzakhalil798 avatar farazbhatti avatar

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.