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 (#121)

* fix: Fix visualizer callback showing wrong heatmaps after normalization score refactoring

* build: Upgrade version, update changelog
  • Loading branch information
lorenzomammana authored Jun 5, 2024
1 parent 922621d commit 44c0a4f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# Changelog
All notable changes to this project will be documented in this file.

### [2.1.10]

#### Fixed

- Fix anomaly visualizer callback showing wrong heatmaps after anomaly score refactoring

### [2.1.9]

#### Updated
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "quadra"
version = "2.1.9"
version = "2.1.10"
description = "Deep Learning experiment orchestration library"
authors = [
"Federico Belotti <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion quadra/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.1.9"
__version__ = "2.1.10"


def get_version():
Expand Down
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 44c0a4f

Please sign in to comment.