Skip to content

Commit

Permalink
🐞 Bug Fix: Solve NaN values of anomaly scores for PatchCore model (#549)
Browse files Browse the repository at this point in the history
patchcore: Solved nans issues for large discrepancies in anomaly map
  • Loading branch information
bsl546 authored Sep 9, 2022
1 parent 8e465ee commit 9c1c2cc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion anomalib/models/patchcore/anomaly_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def compute_anomaly_score(patch_scores: torch.Tensor) -> torch.Tensor:
"""
max_scores = torch.argmax(patch_scores[:, 0])
confidence = torch.index_select(patch_scores, 0, max_scores)
weights = 1 - (torch.max(torch.exp(confidence)) / torch.sum(torch.exp(confidence)))
weights = 1 - torch.max(F.softmax(confidence, dim=-1))
score = weights * torch.max(patch_scores[:, 0])
return score

Expand Down

0 comments on commit 9c1c2cc

Please sign in to comment.