From dc978c0725343e9d790669e16c24c074ddeb507f Mon Sep 17 00:00:00 2001 From: Samet Akcay Date: Thu, 27 Jan 2022 11:13:00 +0000 Subject: [PATCH] Fix Mix Data type issue on inferencer (#77) * Convert the data types * Black * added note to the change --- anomalib/deploy/inferencers/torch.py | 12 ++++++++++-- anomalib/models/cflow/README.md | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/anomalib/deploy/inferencers/torch.py b/anomalib/deploy/inferencers/torch.py index 62c5c3fb76..eb6efc1f46 100644 --- a/anomalib/deploy/inferencers/torch.py +++ b/anomalib/deploy/inferencers/torch.py @@ -138,8 +138,16 @@ 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() + # 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() + else: + anomaly_map, pred_score = predictions + pred_score = pred_score.detach().numpy() anomaly_map = anomaly_map.squeeze() diff --git a/anomalib/models/cflow/README.md b/anomalib/models/cflow/README.md index e213ff7258..3e8fe2e242 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") -