Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with patchcore anomaly score for large confidence scores #324

Closed
bsl546 opened this issue May 19, 2022 · 2 comments · Fixed by #549
Closed

Issue with patchcore anomaly score for large confidence scores #324

bsl546 opened this issue May 19, 2022 · 2 comments · Fixed by #549
Assignees

Comments

@bsl546
Copy link
Contributor

bsl546 commented May 19, 2022

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))

@djdameln
Copy link
Contributor

djdameln commented Sep 6, 2022

Hi, thanks for spotting this and apologies for the late response. I agree that the latter solution, replacing by 1 - torch.max(torch.nn.Softmax()(confidence)), would be the best way to address this. Would you be interested in submitting a PR for this so you could become a contributor?

@djdameln djdameln self-assigned this Sep 6, 2022
@bsl546
Copy link
Contributor Author

bsl546 commented Sep 8, 2022

Yes sure, I will do it today if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants