anomalib
anomalib copied to clipboard
Issue with patchcore anomaly score for large confidence scores
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))