/RememberingNormality

Unofficial implementation of "Remembering Normality: Memory-guided Knowledge Distillation for Unsupervised Anomaly Detection"

Primary LanguagePython

Remembering Normality

Unofficial implementation of the paper : "Remembering Normality: Memory-guided Knowledge Distillation for Unsupervised Anomaly Detection" Article

We designed the code following the guidelines of the official Paper and its Supplementary materials

Getting Started

You will need Python 3.10+ and the packages specified in requirements.txt.

Install packages with:

$ pip install -r requirements.txt

Configure and Run

To run the code, please download the MVTEC AD dataset and add the path in the config.yaml file Link to download the dataset : https://www.mvtec.com/company/research/datasets/mvtec-ad

To run train and test the model :
With STPM backbone (Article)

python trainRM_ST.py  

With RD backbone (Article)

python trainRM_RD.py  

To modify the object categories or hyperparameters, you can modify the config.yaml file.

  • data_path (STR): The path to the dataset
  • dataset (STR): The dataset used (mvtec, visa, mvtec3d or eyecandies)
  • backbone (STR): The name of the model backbone (either resnet18 or wide_resnet50_2)
  • obj (STR): The object category
  • phase (STR): Either train or test
  • save_path (STR): The path to save the model weights
  • visu (BOOL): Wheter to calculate the localization score and save images of segmentation
  • training_data:
    • epoch : number of epoch for training
    • batch_size : the minibatch size
    • lr : the learning rate img_size
    • img_size : Size for the image resizing
    • crop_size : Size for the image cropping (if equal to img_size, no cropping)
    • embed_dim : The parameter L from the paper (number of keys and values)
    • n_embed : The parameter N from the paper, the number of normal sample for normality embedding learning
    • lambda1 : The parameter lambda1 from the paper (ponderation of the lossNM)
    • lambda2 : The parameter lambda2 from the paper (ponderation of the lossORTH)

Datasets

To download the datasets, please refer to the following links:
mvtec ad
visa
mvtec3d-ad
eyecandies

List of TODOs

  • Implement cosine similarity for score calculation
  • Implement RD
  • Implement VisA dataset
  • Implement MVTec 3D-AD dataset
  • Implement eyecandies datasets
  • Implement visualisation

Feel free to ask for any improvements need in the code :)

License

This project is licensed under the MIT License.