Skip to content

Commit

Permalink
fix: Fix visualizer callback showing wrong heatmaps after normalizati…
Browse files Browse the repository at this point in the history
…on score refactoring
  • Loading branch information
lorenzomammana committed Jun 5, 2024
1 parent 922621d commit 15d5ddc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion quadra/callbacks/anomalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from skimage.segmentation import mark_boundaries
from tqdm import tqdm

from quadra.utils.anomaly import MapOrValue


class Visualizer:
"""Anomaly Visualization.
Expand Down Expand Up @@ -204,14 +206,20 @@ def on_test_batch_end(
denormalized_image = Denormalize()(image.cpu())
current_true_mask = true_mask.cpu().numpy()
current_anomaly_map = anomaly_map.cpu().numpy()
# Normalize the map and rescale it to 0-1 range
# In this case we are saying that the anomaly map is in the range [normalized_th - 50, normalized_th + 50]
# This allow to have a stronger color for the anomalies and a lighter one for really normal regions
# It's also independent from the max or min anomaly score!
normalized_map: MapOrValue = (current_anomaly_map - (threshold - 50)) / 100
normalized_map = np.clip(normalized_map, 0, 1)

output_label_folder = "ok" if pred_label == gt_label else "wrong"

if self.plot_only_wrong and output_label_folder == "ok":
continue

heatmap = superimpose_anomaly_map(
current_anomaly_map, denormalized_image, normalize=not self.inputs_are_normalized
normalized_map, denormalized_image, normalize=not self.inputs_are_normalized
)

if isinstance(threshold, float):
Expand Down

0 comments on commit 15d5ddc

Please sign in to comment.