hcw-00 / PatchCore_anomaly_detection

Unofficial implementation of PatchCore anomaly detection
Apache License 2.0
317 stars 95 forks source link

torch.cdist works faster than distance_matrix. #30

Closed paining closed 2 years ago

paining commented 2 years ago

and it needs more small gpu-memory.

There is a memory overload in torch.pow(x-y,p).sum() When I try with this code, I already reserve 8GB and try to allocate another 8GB.

I have a RTX 3080 GPU with 10GB memory. And when I input big image (3,896,896), distance matrix needs 14.36GB but torch.cdist works well.

It means we can use more large sampling rates by using torch.cdist function. I can run sampling rate = 0.01 with torch.cdist but I got CUDA out of memory with distance_matrix.


Actual GPU memory usages with MVTec AD. https://github.com/hcw-00/PatchCore_anomaly_detection/issues/19#issuecomment-962706455

royarahimzadeh commented 2 years ago

Great, I can run with a higher sampling rate too. I have a problem, not sure if it is related to the current higher sampling rate. I see that the false negative rate is higher than before. Any suggestions for improving?

paining commented 2 years ago

Great, I can run with a higher sampling rate too. I have a problem, not sure if it is related to the current higher sampling rate. I see that the false negative rate is higher than before. Any suggestions for improving?

Humm... That is interesting... I don't know why the false negative rate become higher. But as you said, I guess the higher sampling rate makes the high false negative rate too. I think too many samples decrease the distance between new test features (it may be normal or defect) and sampled features. Variance of distance become smaller, it makes bigger trade-off problem.

We can see the table 4 in PatchCore paper, 10% sampling rate has higher pixel AUROC and PRO score than 25%.

That is my best guess..... Another person can give us more clear solution!

hcw-00 commented 2 years ago

Thank you!