Last active
July 27, 2022 17:53
-
-
Save michelkana/b8a5176b3ac7db09b48ef4264f4e16fa 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
# pip install scipy==1.1.0 | |
# pip install keras-vis | |
from vis.visualization import visualize_saliency | |
def plot_saliency(img_idx=None): | |
img_idx = plot_features_map(img_idx) | |
grads = visualize_saliency(cnn_saliency, -1, filter_indices=ytest[img_idx][0], | |
seed_input=x_test[img_idx], backprop_modifier=None, | |
grad_modifier="absolute") | |
predicted_label = labels[np.argmax(cnn.predict(x_test[img_idx].reshape(1,32,32,3)),1)[0]] | |
fig, ax = plt.subplots(1,2, figsize=(10,5)) | |
ax[0].imshow(x_test[img_idx]) | |
ax[0].set_title('original img id {} - {}'.format(img_idx, labels[ytest[img_idx][0]])) | |
ax[1].imshow(grads, cmap='jet') | |
ax[1].set_title('saliency - predicted {}'.format(predicted_label)) | |
plot_saliency() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment