From eeaa96a3b8dcd6fc46ef5d61b307397d2550f0cb Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Tue, 18 Jan 2022 01:00:23 -0700 Subject: [PATCH 1/3] Convert the data types --- anomalib/deploy/inferencers/torch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/anomalib/deploy/inferencers/torch.py b/anomalib/deploy/inferencers/torch.py index 62c5c3fb76..48368dde6d 100644 --- a/anomalib/deploy/inferencers/torch.py +++ b/anomalib/deploy/inferencers/torch.py @@ -138,8 +138,12 @@ def post_process( anomaly_map = predictions pred_score = anomaly_map.reshape(-1).max() else: - anomaly_map, pred_score = predictions - pred_score = pred_score.detach().cpu().numpy() + if isinstance(predictions[1],( Tensor)): + anomaly_map, pred_score = predictions + pred_score = pred_score.detach() + else: + anomaly_map, pred_score = predictions + pred_score = pred_score.detach().numpy() anomaly_map = anomaly_map.squeeze() From 6ea7b02aa32187dcd2c648224a88b1d271ac645b Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Tue, 18 Jan 2022 01:10:32 -0700 Subject: [PATCH 2/3] Black --- anomalib/deploy/inferencers/torch.py | 2 +- anomalib/models/cflow/README.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/anomalib/deploy/inferencers/torch.py b/anomalib/deploy/inferencers/torch.py index 48368dde6d..f43373d56a 100644 --- a/anomalib/deploy/inferencers/torch.py +++ b/anomalib/deploy/inferencers/torch.py @@ -138,7 +138,7 @@ def post_process( anomaly_map = predictions pred_score = anomaly_map.reshape(-1).max() else: - if isinstance(predictions[1],( Tensor)): + if isinstance(predictions[1], (Tensor)): anomaly_map, pred_score = predictions pred_score = pred_score.detach() else: diff --git a/anomalib/models/cflow/README.md b/anomalib/models/cflow/README.md index e3aae7d153..da7c739ec3 100644 --- a/anomalib/models/cflow/README.md +++ b/anomalib/models/cflow/README.md @@ -47,4 +47,3 @@ All results gathered with seed `42`. ![Sample Result 2](../../../docs/source/images/cflow/results/1.png "Sample Result 2") ![Sample Result 3](../../../docs/source/images/cflow/results/2.png "Sample Result 3") - From faa818c48f7945145cb87a857e5299c46fd1a8aa Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Wed, 26 Jan 2022 13:27:50 -0700 Subject: [PATCH 3/3] added note to the change --- anomalib/deploy/inferencers/torch.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/anomalib/deploy/inferencers/torch.py b/anomalib/deploy/inferencers/torch.py index f43373d56a..eb6efc1f46 100644 --- a/anomalib/deploy/inferencers/torch.py +++ b/anomalib/deploy/inferencers/torch.py @@ -138,6 +138,10 @@ def post_process( anomaly_map = predictions pred_score = anomaly_map.reshape(-1).max() else: + # NOTE: Patchcore `forward`` returns heatmap and score. + # We need to add the following check to ensure the variables + # are properly assigned. Without this check, the code + # throws an error regarding type mismatch torch vs np. if isinstance(predictions[1], (Tensor)): anomaly_map, pred_score = predictions pred_score = pred_score.detach()