Last active
April 18, 2019 18:09
-
-
Save saurabhpal97/4728bb6939449efc20888ac44bbf3bc3 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_cam | |
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, 'predictions') | |
#read the image and plot it | |
image = io.imread('car.jpeg') | |
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
# Swap softmax with linear | |
model.layers[layer_idx].activation = activations.linear | |
model = utils.apply_modifications(model) | |
grads = visualize_cam(model, layer_idx,filter_indices=644,seed_input=image,backprop_modifier='guided') | |
# Plot with 'jet' colormap to visualize as a heatmap. | |
#grads = grads/grads.max() | |
plt.imshow(grads, cmap='jet') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment