Last active
April 18, 2019 17:58
-
-
Save saurabhpal97/6cc03c437b2fee7f8422a545a29ba633 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vis.visualization import visualize_saliency | |
from vis.utils import utils | |
from keras import activations | |
#read the image | |
image = io.imread('car.jpeg') | |
#plot the image | |
io.imshow(image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, 'predictions') | |
# Swap softmax with linear | |
model.layers[layer_idx].activation = activations.linear | |
model = utils.apply_modifications(model) | |
#generating saliency map with unguided backprop | |
grads1 = visualize_saliency(model, layer_idx,filter_indices=None,seed_input=image) | |
#plotting the unguided saliency map | |
plt.imshow(grads1,cmap='jet') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#generating saliency map with guided backprop | |
grads2 = visualize_saliency(model, layer_idx,filter_indices=None,seed_input=image,backprop_modifier='guided') | |
#plotting the saliency map as heatmap | |
plt.imshow(grads2,cmap='jet') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment