remmarp / PaDiM-TF

[TF 2.x] PaDiM - unofficial tensorflow implementation of the paper 'a Patch Distribution Modeling Framework for Anomaly Detection and Localization'.
16 stars 2 forks source link

Pixel-level localization/mask #2

Open HoseinHashemi opened 2 years ago

HoseinHashemi commented 2 years ago

I'm trying to reproduce this implementation. Although the image level detection works well, I get weird results for the pixel-level localization/mask. Seems like I get a lot of False Positives. Please see attached photos. I do not change any code nor requirements. So everything is as recommended in this repo.
Could you please comment if I'm missing anything.

Thanks.

leather_47 leather_93

GitGhidorah commented 2 years ago

I met the same problem. In addition, I got good results when I tried to run "python main.py --arch resnet18" by the code of the following github by described this readme. https://github.com/xiahaifeng1995/PaDiM-Anomaly-Detection-Localization-master I don't understand the differences between two.

HoseinHashemi commented 2 years ago

Yes, I also have good results from the Pytorch implementation. But unsure why this TF one does not perform as reported.

remmarp commented 2 years ago

I presume the difference between TF and Pytorch comes from backbone networks. When looking at some anomaly localization examples, I found performance differences between TF and Pytorch versions. The two versions of the backbone network showed similar classification performance, but the feature representation performance might be different.

As representations from the two versions are different, we may have to find an appropriate hyperparameter set for the TF version. When changing the hyperparameter, I've observed better or worse results depending on my choices. For example, you can change the sampling layer (e.g. block5a_activation) or gaussian sampling sigma.

gnscc commented 1 year ago

I am one year late but for anyone who may experience this issue you could begin testing the EfficientNet model with a_expand_activation layers. With these layers you get much better localization than the ones by default.

In padim.py

# layer1 = model.get_layer(name='block5a_activation').output
# layer2 = model.get_layer(name='block6a_activation').output
# layer3 = model.get_layer(name='block7a_activation').output

layer1 = model.get_layer(name='block5a_expand_activation').output
layer2 = model.get_layer(name='block6a_expand_activation').output
layer3 = model.get_layer(name='block7a_expand_activation').output