TooTouch / MemSeg

Unofficial re-implementation of MemSeg for Anomaly Detection
MIT License
184 stars 31 forks source link

Vanishing detection scores and fluctuating results #15

Closed SamuelllG closed 1 year ago

SamuelllG commented 1 year ago

Hey there,

first of all thanks for the code! I've been using MemSeg for quite a while now. Unfortunately for my datasets, it doesn't achieve nearly as good rates as for MVTec. On average, 60-80% AUROC image/pixelwise for multiple categories and test runs.

One thing I noticed is that the predictions made are getting smaller and smaller, the longer the training, until they finally reach a value near 0. Do you have any explanation for that? It seems harmful to the AUROC?

As for my second question: I mostly get very fluctuating results. So the best rates for one dataset can vary between e.g. 44% and 94% for repeated trainings. Also, the maximum is mostly reached quite early in the training process, e.g. at iteration 100. Rates are then decreasing. I wonder if it's some kind of overfitting, but I'm using the original hyperparameters (with decreased learning rate) with similar sized datasets.

Any help or suggestions are highly appreciated :)

Take care!

TooTouch commented 1 year ago

@SamuelllG

I'm sorry to late reply. I think that the problem is in anomaly synthesis process. To generate an anomaly image, you first need to make sure that the foreground mask of the image is extracted well. If you are using a custom dataset, you will need to set a threshold for the dataset, such as self.bg_threshold in the code below.

https://github.com/TooTouch/MemSeg/blob/7c04dd2d49b771a96b53cf25bfca11c122a099f5/data/dataset.py#L191-L205

You can set the threshold by referring to ./anomaly_mask.json, and make sure that the threshold you define works well with the dataset you actually use to generate anomalies.