From 8a6a686fc3a086fa9b0dee2675f5164112a2a45d Mon Sep 17 00:00:00 2001 From: bsl Date: Thu, 8 Sep 2022 22:05:00 +0200 Subject: [PATCH] patchcore: Solved nans issues for large discrepancies in anomaly map --- anomalib/models/patchcore/anomaly_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anomalib/models/patchcore/anomaly_map.py b/anomalib/models/patchcore/anomaly_map.py index 00e8eafbe0..086f44ff38 100644 --- a/anomalib/models/patchcore/anomaly_map.py +++ b/anomalib/models/patchcore/anomaly_map.py @@ -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