Skip to content

Commit

Permalink
Return raw anomaly maps as metadata (#2217)
Browse files Browse the repository at this point in the history
* return raw anomaly map instead of colormap

* return raw heatmap in openvino inference

* Update changelog

* convert anomaly map to numpy
  • Loading branch information
djdameln authored Jun 2, 2023
1 parent 250dd92 commit 3ae37de
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Bug fixes

- Return raw anomaly map instead of colormap as metadata to prevent applying colormap conversion twice (<https://github.com/openvinotoolkit/training_extensions/pull/2217>)
- Hotfix: use 0 confidence threshold when computing best threshold based on F1

## \[v1.2.2\]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import pytorch_lightning as pl
import torch
from anomalib.models import AnomalyModule
from anomalib.post_processing import anomaly_map_to_color_map
from pytorch_lightning.callbacks import Callback
from torch import Tensor

Expand Down Expand Up @@ -82,7 +81,7 @@ def on_predict_epoch_end(self, _trainer: pl.Trainer, _pl_module: AnomalyModule,
name="Anomaly Map",
type="anomaly_map",
annotation_scene=dataset_item.annotation_scene,
numpy=anomaly_map_to_color_map(anomaly_map.squeeze().numpy(), normalize=False),
numpy=(anomaly_map * 255).cpu().numpy().astype(np.uint8),
)
)

Expand Down
3 changes: 1 addition & 2 deletions otx/algorithms/anomaly/tasks/openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import numpy as np
from addict import Dict as ADDict
from anomalib.deploy import OpenVINOInferencer
from anomalib.post_processing import anomaly_map_to_color_map
from compression.api import DataLoader
from compression.engines.ie_engine import IEEngine
from compression.graph import load_model, save_model
Expand Down Expand Up @@ -193,7 +192,7 @@ def infer(self, dataset: DatasetEntity, inference_parameters: InferenceParameter
raise ValueError(f"Unknown task type: {self.task_type}")

dataset_item.append_labels([ScoredLabel(label=label, probability=float(probability))])
anomaly_map = anomaly_map_to_color_map(image_result.anomaly_map, normalize=False)
anomaly_map = (image_result.anomaly_map * 255).astype(np.uint8)
heatmap_media = ResultMediaEntity(
name="Anomaly Map",
type="anomaly_map",
Expand Down

0 comments on commit 3ae37de

Please sign in to comment.