anomalib icon indicating copy to clipboard operation
anomalib copied to clipboard

Issue with patchcore anomaly score for large confidence scores

Open bsl546 opened this issue 3 years ago • 0 comments

Describe the bug When the confidence is very high for images treated by the patchcore model, the anomaly score can be nan. This is due to the formula: weights = 1 - (torch.max(torch.exp(confidence)) / torch.sum(torch.exp(confidence))) in anomaly_map.py, torch.exp() gives nan for values too large.

Expected behavior Two possible solutions:

  • Either a threshold should be set on the tensors, like confidence[confidence>thres] = thres Possible values for thres are e.g., 50.0.

  • Or, even cleaner, replace 1- (torch.max(torch.exp(confidence)) / torch.sum(torch.exp(confidence))) by 1-torch.max(torch.nn.Softmax()(confidence))

bsl546 avatar May 19 '22 09:05 bsl546