Skip to content

Commit

Permalink
Merge pull request #83 from orobix/feature/upgrade_anomalib_126
Browse files Browse the repository at this point in the history
Feature/upgrade anomalib 126
  • Loading branch information
AlessandroPolidori authored Nov 15, 2023
2 parents d263ab9 + e5137ef commit 4a10a8c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
# Changelog
All notable changes to this project will be documented in this file.

### [1.3.6]

#### Fixed

- Changed matplotlib backend in anomaly visualizer to solve slowdown on some devices

#### Updated

- Update anomalib to [v0.7.0+obx.1.2.6] (Efficient_ad now keeps maps always on gpu during forward)

### [1.3.5]

#### Fixed
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "quadra"
version = "1.3.5"
version = "1.3.6"
description = "Deep Learning experiment orchestration library"
authors = [
{ name = "Alessandro Polidori", email = "[email protected]" },
Expand Down Expand Up @@ -66,7 +66,7 @@ dependencies = [
"h5py==3.8.*",
"timm==0.6.12", # required by smp
"segmentation-models-pytorch==0.3.2",
"anomalib@git+https://github.com/orobix/[email protected]+obx.1.2.5",
"anomalib@git+https://github.com/orobix/[email protected]+obx.1.2.6",
"xxhash==3.2.*",
]

Expand Down Expand Up @@ -121,7 +121,7 @@ repository = "https://github.com/orobix/quadra"

# Adapted from https://realpython.com/pypi-publish-python-package/#version-your-package
[tool.bumpver]
current_version = "1.3.5"
current_version = "1.3.6"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "build: Bump version {old_version} -> {new_version}"
commit = true
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__ = "1.3.5"
__version__ = "1.3.6"


def get_version():
Expand Down
20 changes: 16 additions & 4 deletions quadra/callbacks/anomalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def add_image(self, image: np.ndarray, title: str, color_map: Optional[str] = No

def generate(self):
"""Generate the image."""
default_plt_backend = plt.get_backend()
plt.switch_backend("Agg")
num_cols = len(self.images)
figure_size = (num_cols * 3, 3)
self.figure, self.axis = plt.subplots(1, num_cols, figsize=figure_size)
Expand All @@ -58,6 +60,7 @@ def generate(self):
axis.axes.yaxis.set_visible(False)
axis.imshow(image_dict["image"], image_dict["color_map"], vmin=0, vmax=255)
axis.title.set_text(image_dict["title"])
plt.switch_backend(default_plt_backend)

def show(self):
"""Show image on a matplotlib figure."""
Expand Down Expand Up @@ -168,11 +171,17 @@ def on_test_batch_end(
normalize = True # raw anomaly maps. Still need to normalize

if self.threshold_type == "pixel":
threshold = pl_module.pixel_metrics.F1Score.threshold
if hasattr(pl_module.pixel_metrics.F1Score, "threshold"):
threshold = pl_module.pixel_metrics.F1Score.threshold
else:
raise AttributeError("Metric has no threshold attribute")
else:
threshold = pl_module.image_metrics.F1Score.threshold
if hasattr(pl_module.image_metrics.F1Score, "threshold"):
threshold = pl_module.image_metrics.F1Score.threshold
else:
raise AttributeError("Metric has no threshold attribute")

for (filename, image, true_mask, anomaly_map, gt_label, pred_label, anomaly_score) in tqdm(
for filename, image, true_mask, anomaly_map, gt_label, pred_label, anomaly_score in tqdm(
zip(
outputs["image_path"],
outputs["image"],
Expand All @@ -193,7 +202,10 @@ def on_test_batch_end(
continue

heat_map = superimpose_anomaly_map(anomaly_map, image, normalize=normalize)
pred_mask = compute_mask(anomaly_map, threshold)
if isinstance(threshold, float):
pred_mask = compute_mask(anomaly_map, threshold)
else:
raise TypeError("Threshold should be float")
vis_img = mark_boundaries(image, pred_mask, color=(1, 0, 0), mode="thick")
visualizer = Visualizer()

Expand Down

0 comments on commit 4a10a8c

Please sign in to comment.