implement from paper Attention Map-Guided Two-stage Anomaly Detection using Hard Augmentation https://arxiv.org/pdf/1805.08318.pdf , l just implement Attention Network .
The Attention Network is able to generate Attention maps that show which part of region in image is anomaly and normal,
and able to find anomaly images by loss value, it means if loss value is greater than particular loss threshold, it will regard as anomaly image
but the acc is lower than skip-Attention GANomaly, so need ADGAN to further detect anomaly images.
below image ref. from paper https://arxiv.org/pdf/1805.08318.pdf
-Generate fake image have some black images
[Solution] G_loss add anomaly image loss , and theauc will low when adding this loss criteria
-Train attetion failed if the input_attn = 1, but succeed when input_attn=empty
-The cutout augmentation is not real, needs to further implement paper method
-Maybe it is not easy to implement in tensorflow2
-The loss function is not same as paper, maybe result in false result
l just implement cutout augmgnetation...
Generator + Discriminator model
- Attention-Map-Guided-Two-stage-Anomaly-Detection-using-Hard-Augmentation-Pytorch
- Implement-Issue
- Hard-Augmentation
- Requirement
- implement
- Train-on-custom-dataset
- Train
- Test
- Lose-value-distribution
- Reference
pip install -r requirements.txt
Tha base framework is GAnomaly, and modified Encoder-Decoder framework
Encoder-Decoder network modification
- Skip-GANomaly : add skip-connection
- Skip-CBAM-feature : Encoder features do CBAM Attetion network and then skip to Decoder
- Decoder-SelfAttention : Decoder feature do self-Attention and pass to next layer as input feature
- implement skip-CBAM-GANomaly first, and then start adding self-Attention into skip-CBAM-GANomaly network
below image is self-Attention network , ref. from paper https://arxiv.org/pdf/1805.08318.pdf
Custom Dataset
├── test
│ ├── 0.normal
│ │ └── normal_tst_img_0.png
│ │ └── normal_tst_img_1.png
│ │ ...
│ │ └── normal_tst_img_n.png
│ ├── 1.abnormal
│ │ └── abnormal_tst_img_0.png
│ │ └── abnormal_tst_img_1.png
│ │ ...
│ │ └── abnormal_tst_img_m.png
├── train
│ ├── 0.normal
│ │ └── normal_tst_img_0.png
│ │ └── normal_tst_img_1.png
│ │ ...
│ │ └── normal_tst_img_t.png
python train.py --img-dir "[train dataset dir]" --batch-size 64 --img-size 32 --epoch 20
python test.py --nomal-dir "[test normal dataset dir]" --abnormal-dir "[test abnormal dataset dir]" --view-img --img-size 32
Blue : normal dataset
Orange : abnormal dataset
GANomaly: Semi-Supervised Anomaly Detection via Adversarial Training
https://arxiv.org/abs/1805.06725
Skip-GANomaly: Skip Connected and Adversarially Trained Encoder-Decoder Anomaly Detection
https://arxiv.org/pdf/1901.08954.pdf
Attention Map-Guided Two-stage Anomaly Detection using Hard Augmentation