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

Why is pre-activation output used for computing vanilla saliency map? #237

Open
preethiseshadri518 opened this issue Sep 11, 2021 · 0 comments

Comments

@preethiseshadri518
Copy link

I have a conceptual question based on the mnist example usage notebook: https://github.com/raghakot/keras-vis/blob/master/examples/mnist/attention.ipynb. I am trying to understand why to use pre-activation output for computing standard saliency maps? This is achieved by changing the activation of the network to linear as in cell 3.

from vis.visualization import visualize_saliency
from vis.utils import utils
from keras import activations

# Utility to search for layer index by name. 
# Alternatively we can specify this as -1 since it corresponds to the last layer.
layer_idx = utils.find_layer_idx(model, 'preds')

# Swap softmax with linear
model.layers[layer_idx].activation = activations.linear
model = utils.apply_modifications(model)

grads = visualize_saliency(model, layer_idx, filter_indices=class_idx, seed_input=x_test[idx])

The notebook says, "to visualize activation over final dense layer outputs, we need to switch the softmax activation out for linear since gradient of output node will depend on all the other node activations. Doing this in keras is tricky, so we provide utils.apply_modifications to modify network parameters and rebuild the graph.".

Is this a standard component of producing saliency maps, or is this something that can be adopted because it works well in practice? The model output is impacted by final activation, so isn't it reasonable to include that in computing the saliency map?

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

No branches or pull requests

1 participant