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

Use batches for SmoothGrad #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

lenbrocki
Copy link

To speed up the computation for obtaining smoothed masks, the noisy samples are created first and gradients are obtained as a single batch for all the noisy samples. Afterwards the gradients (or their squares) are summed to give the final smoothed mask.

Copy link
Collaborator

@gkapish gkapish left a comment

Choose a reason for hiding this comment

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

@lenbrocki, thanks you for the pull request. The proposed GetSmoothedMask() implementation assumes that GetMask() of every saliency method can accept a batch of images. Unfortunately, it is not the case currently. Note, that SmoothGrad can be applied not only on vanilla gradients method but on other methods too.

grad = self.GetMask(x_plus_noise, call_model_function, call_model_args,
shape = (nsamples,) + x_value.shape
noisy_samples = np.zeros(shape)
for i in range(nsamples):
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could get rid of the loop completely if you used np.repeat(...) and generating the noise mask for the batched shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants