• Stars
    star
    257
  • Rank 157,827 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created about 2 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[ECCV2022 Oral] Registration based Few-Shot Anomaly Detection

Registration based Few-Shot Anomaly Detection

This is an official implementation of โ€œRegistration based Few-Shot Anomaly Detectionโ€ (RegAD) with PyTorch, accepted by ECCV 2022 (Oral).

Paper Link

@inproceedings{huang2022regad,
  title={Registration based Few-Shot Anomaly Detection}
  author={Huang, Chaoqin and Guan, Haoyan and Jiang, Aofan and Zhang, Ya and Spratlin, Michael and Wang, Yanfeng},
  booktitle={European Conference on Computer Vision (ECCV)},
  year={2022}
}

Abstract: This paper considers few-shot anomaly detection (FSAD), a practical yet under-studied setting for anomaly detection (AD), where only a limited number of normal images are provided for each category at training. So far, existing FSAD studies follow the one-model-per-category learning paradigm used for standard AD, and the inter-category commonality has not been explored. Inspired by how humans detect anomalies, i.e., comparing an image in question to normal images, we here leverage registration, an image alignment task that is inherently generalizable across categories, as the proxy task, to train a category-agnostic anomaly detection model. During testing, the anomalies are identified by comparing the registered features of the test image and its corresponding support (normal) images. As far as we know, this is the first FSAD method that trains a single generalizable model and requires no re-training or parameter fine-tuning for new categories.

Keywords: Anomaly Detection, Few-Shot Learning, Registration

Get Started

Environment

  • python >= 3.7.11
  • pytorch >= 1.11.0
  • torchvision >= 0.12.0
  • numpy >= 1.19.5
  • scipy >= 1.7.3
  • skimage >= 0.19.2
  • matplotlib >= 3.5.2
  • kornia >= 0.6.5
  • tqdm

Files Preparation

  1. Download the MVTec dataset here.
  2. Download the support dataset for few-shot anomaly detection on Google Drive or Baidu Disk (i9rx) and unzip the dataset. For those who have problem downloading the support set, please optional download categories of capsule and grid on Baidu Disk (pll9) and Baidu Disk (ns0n).
    tar -xvf support_set.tar
    
    We hope the followers could use these support datasets to make a fair comparison between different methods.
  3. Download the pre-train models on Google Drive or Baidu Disk (4qyo) and unzip the checkpoint files.
    tar -xvf save_checkpoints.tar
    

After the preparation work, the whole project should have the following structure:

./RegAD
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ train.py                                  # training code
โ”œโ”€โ”€ test.py                                   # testing code
โ”œโ”€โ”€ MVTec                                     # MVTec dataset files
โ”‚   โ”œโ”€โ”€ bottle
โ”‚   โ”œโ”€โ”€ cable
โ”‚   โ”œโ”€โ”€ ...                  
โ”‚   โ””โ”€โ”€ zippper
โ”œโ”€โ”€ support_set                               # MVTec support dataset files
โ”‚   โ”œโ”€โ”€ 2
โ”‚   โ”œโ”€โ”€ 4                 
โ”‚   โ””โ”€โ”€ 8
โ”œโ”€โ”€ models                                    # models and backbones
โ”‚   โ”œโ”€โ”€ stn.py  
โ”‚   โ””โ”€โ”€ siamese.py
โ”œโ”€โ”€ losses                                    # losses
โ”‚   โ””โ”€โ”€ norm_loss.py  
โ”œโ”€โ”€ datasets                                  # dataset                      
โ”‚   โ””โ”€โ”€ mvtec.py
โ”œโ”€โ”€ save_checkpoints                          # model checkpoint files                  
โ””โ”€โ”€ utils                                     # utils
    โ”œโ”€โ”€ utils.py
    โ””โ”€โ”€ funcs.py

Quick Start

python test.py --obj $target-object --shot $few-shot-number --stn_mode rotation_scale

For example, if run on the category bottle with k=2:

python test.py --obj bottle --shot 2 --stn_mode rotation_scale

Training

python train.py --obj $target-object --shot $few-shot-number --data_type mvtec --data_path ./MVTec/ --epochs 50 --batch_size 32 --lr 0.0001 --momentum 0.9 --inferences 10 --stn_mode rotation_scale 

For example, to train a RegAD model on the MVTec dataset on bottle with k=2, simply run:

python train.py --obj bottle --shot 2 --data_type mvtec --data_path ./MVTec/ --epochs 50 --batch_size 32 --lr 0.0001 --momentum 0.9 --inferences 10 --stn_mode rotation_scale 

Then you can run the evaluation using:

python test.py --obj bottle --shot 2 --stn_mode rotation_scale

Results

Results of few-shot anomaly detection and localization with k=2:

AUC (%) Detection Localization
K=2 RegAD Inplementation RegAD Inplementation
bottle 99.4 99.7 98.0 98.6
cable 65.1 69.8 91.7 94.2
capsule 67.5 68.6 97.3 97.6
carpet 96.5 96.7 98.9 98.9
grid 84.0 79.1 77.4 77.5
hazelnut 96.0 96.3 98.1 98.2
leather 99.4 100 98.0 99.2
metal_nut 91.4 94.2 96.9 98.0
pill 81.3 66.1 93.6 97.0
screw 52.5 53.9 94.4 94.1
tile 94.3 98.9 94.3 95.1
toothbrush 86.6 86.8 98.2 98.2
transistor 86.0 82.2 93.4 93.3
wood 99.2 99.8 93.5 96.5
zipper 86.3 90.9 95.1 98.3
average 85.7 85.5 94.6 95.6

Results of few-shot anomaly detection and localization with k=4:

AUC (%) Detection Localization
K=4 RegAD Inplementation RegAD Inplementation
bottle 99.4 99.3 98.4 98.5
cable 76.1 82.9 92.7 95.5
capsule 72.4 77.3 97.6 98.3
carpet 97.9 97.9 98.9 98.9
grid 91.2 87 85.7 85.7
hazelnut 95.8 95.9 98.0 98.4
leather 100 99.9 99.1 99
metal_nut 94.6 94.3 97.8 96.5
pill 80.8 74.0 97.4 97.4
screw 56.6 59.3 95.0 96.0
tile 95.5 98.2 94.9 92.6
toothbrush 90.9 91.1 98.5 98.5
transistor 85.2 85.5 93.8 93.5
wood 98.6 98.9 94.7 96.3
zipper 88.5 95.8 94.0 98.6
average 88.2 89.2 95.8 96.2

Results of few-shot anomaly detection and localization with k=8:

AUC (%) Detection Localization
K=8 RegAD Inplementation RegAD Inplementation
bottle 99.8 99.8 97.5 98.5
cable 80.6 81.5 94.9 95.8
capsule 76.3 78.4 98.2 98.4
carpet 98.5 98.6 98.9 98.9
grid 91.5 91.5 88.7 88.7
hazelnut 96.5 97.3 98.5 98.5
leather 100 100 98.9 99.3
metal_nut 98.3 98.6 96.9 98.3
pill 80.6 77.8 97.8 97.7
screw 63.4 65.8 97.1 97.3
tile 97.4 99.6 95.2 96.1
toothbrush 98.5 96.6 98.7 99.0
transistor 93.4 90.3 96.8 95.9
wood 99.4 99.5 94.6 96.5
zipper 94.0 93.4 97.4 97.4
average 91.2 91.2 96.8 97.1

Visualization

Acknowledgement

We borrow some codes from SimSiam, STN and PaDiM

Contact

If you have any problem with this code, please feel free to contact [email protected].

More Repositories

1

MING

ๆ˜ŽๅŒป (MING)๏ผšไธญๆ–‡ๅŒป็–—้—ฎ่ฏŠๅคงๆจกๅž‹
Python
812
star
2

FACT

Python
155
star
3

Where2comm

Python
139
star
4

MedKLIP

The official code for MedKLIP: Medical Knowledge Enhanced Language-Image Pre-Training in Radiology. We propose to leverage medical specific knowledge enhancing language-image pre-training method, significantly advancing the ability of pre-trained models to handle unseen diseases on zero-shot classification and grounding tasks.
Python
134
star
5

LED

[CVPR2023] Leapfrog Diffusion Model for Stochastic Trajectory Prediction
Jupyter Notebook
130
star
6

MemoNet

[CVPR2022] Remember Intentions: Retrospective-Memory-based Trajectory Prediction
Python
118
star
7

EqMotion

[CVPR2023] EqMotion: Equivariant Multi-agent Motion Prediction with Invariant Interaction Reasoning
Python
112
star
8

BCL

[ICML2022] Contrastive Learning with Boosted Memorization
Python
110
star
9

GroupNet

[CVPR22] GroupNet: Multiscale Hypergraph Neural Networks for Trajectory Prediction with Relational Reasoning
Python
108
star
10

MVFA-AD

[CVPR2024 Highlight] Adapting Visual-Language Models for Generalizable Anomaly Detection in Medical Images
Python
106
star
11

TBP-Former

78
star
12

CoCa3D

Python
70
star
13

GenMedicalEval

69
star
14

CoBEVFlow

[NeurIPS 2023] Asynchrony-Robust Collaborative Perception via Birdโ€™s Eye View Flow
Python
65
star
15

FedDisco

Python
60
star
16

RECORDS-LTPLL

[ICLR 2023] PyTorch implementation for "Long-Tailed Partial Label Learning via Dynamic Rebalancing"
Python
54
star
17

FedDG-GA

[CVPR 2023] Federated Domain Generalization with Generalization Adjustment
Python
37
star
18

SyncNet

[ECCV2022] Latency-Aware Collaborative Perception
Python
33
star
19

SPGSN

The source codes of 'Skeleton-parted graph scattering networks for 3D human motion prediction'. ECCV 2022
Python
29
star
20

AuxFormer

[ICCV2023] Auxiliary Tasks Benefit 3D Skeleton-based Human Motion Prediction
Python
25
star
21

pFedGraph

Python
23
star
22

BE-SSL

Codes for our paper "Boundary-Enhanced Self-Supervised Learningfor Brain Structure Segmentation"
Python
23
star
23

JRTransformer

[ICCV2023] Joint-Relation Transformer for Multi-Person Motion Prediction
Python
22
star
24

Geometric-Harmonization

[NeurIPS 2023 Spotlight] Combating Representation Learning Disparity with Geometric Harmonization
Python
19
star
25

Collaborative-Uncertainty

Python
19
star
26

GPFL-GRACE

[MICCAI 2023] GRACE: Enhancing Federated Learning for Medical Imaging with Generalized and Personalized Gradient Correction
Python
15
star
27

ECGAD

[MICCAI2023 Early Accept] Multi-scale Cross-restoration Framework for Electrocardiogram Anomaly Detection
Python
15
star
28

LoRKD

Python
12
star
29

K-Diag

Python
10
star
30

MoLA

Python
10
star
31

CoFormer

Python
10
star
32

FedGELA

[NeurIPS 2023]Federated Learning with Bilateral Curation for Partially Class-Disjoint Data
Python
10
star
33

FedLESAM

[ICML 2024 spotlight] This repository contains the implementation details for the paper "Locally Estimated Global Perturbations are Better than Local Perturbations for Federated Sharpness-aware Minimization"
Python
9
star
34

FedSkip

FedSkip-Combatting-Statistical-Heterogeneity-with-Federated-Skip-Aggregation official code
Python
7
star
35

OC_LT

Official code base for "Long-Tailed Diffusion Models With Oriented Calibration" ICLR2024
Python
6
star
36

DISAM

This repository contains the implementation details for the paper "Domain-Inspired Sharpness-Aware Minimization Under Domain Shifts," accepted at the ICLR 2024.
Python
6
star
37

CaT

[ICCV2021] CaT: Weakly Supervised Object Detection with Category Transfer
5
star
38

ECISQA

[NeurIPS 2023] Emergent communication in interactive sketch question answering
Jupyter Notebook
5
star
39

FedMR

[TMLR 2023]Federated Learning under Partially Class-Disjoint Data via Manifold Reshaping
Python
4
star
40

GSC

Python
4
star
41

SSM

[TMM 2022] Self-Supervised Masking for Unsupervised Anomaly Detection and Localization
Python
4
star
42

FreeAlign

Python
3
star
43

ITES

Python
1
star
44

NMMP

Python
1
star
45

mediabrain-sjtu.github.io

TeX
1
star