Skip to content

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
Contributor

@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
Contributor

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.

2 participants