Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add distinction between image and pixel threshold in postprocessor #50

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why you decided to remove the if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the threshold key is missing from the meta data, I'd rather have the code fail with an error than return the anomaly map without finishing the conversion to normalized scores (I learned the hard way).

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