Skip to content

Fixing Visualization Normalization #458

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

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 4 additions & 3 deletions captum/attr/_utils/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ def _prepare_image(attr_visual: ndarray):


def _normalize_scale(attr: ndarray, scale_factor: float):
assert scale_factor != 0, "Cannot normalize by scale factor = 0"
if abs(scale_factor) < 1e-5:
warnings.warn(
"Attempting to normalize by value approximately 0, skipping normalization."
"This likely means that attribution values are all close to 0."
"Attempting to normalize by value approximately 0, visualized results"
"may be misleading. This likely means that attribution values are all"
"close to 0."
)
return np.clip(attr, -1, 1)
attr_norm = attr / scale_factor
return np.clip(attr_norm, -1, 1)

Expand Down