Skip to content

Commit

Permalink
add distinction between image and pixel threshold in postprocessor (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
djdameln committed Dec 27, 2021
1 parent 17f9616 commit be07504
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions anomalib/core/model/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,13 @@ def post_process(self, predictions: np.ndarray, meta_data: Optional[Dict] = None
anomaly_map = np.log(anomaly_map)
anomaly_map = (anomaly_map - meta_data["pixel_mean"]) / meta_data["pixel_std"]
anomaly_map -= (meta_data["image_mean"] - meta_data["pixel_mean"]) / meta_data["pixel_std"]
if "threshold" in meta_data.keys():
anomaly_map = norm.cdf(anomaly_map - meta_data["threshold"])
anomaly_map = norm.cdf(anomaly_map - meta_data["pixel_threshold"])

# standardize image scores
if "image_mean" in meta_data.keys() and "image_std" in meta_data.keys():
pred_score = np.log(pred_score)
pred_score = (pred_score - meta_data["image_mean"]) / meta_data["image_std"]
if "threshold" in meta_data.keys():
pred_score = norm.cdf(pred_score - meta_data["threshold"])
pred_score = norm.cdf(pred_score - meta_data["image_threshold"])

if "image_shape" in meta_data and anomaly_map.shape != meta_data["image_shape"]:
anomaly_map = cv2.resize(anomaly_map, meta_data["image_shape"])
Expand Down

0 comments on commit be07504

Please sign in to comment.