I am trying to replicate the results from: https://github.com/raghakot/keras-vis/blob/master/examples/mnist/attention.ipynb to produce a saliency map of zero. I put in the exact same code, and as suggested, used:
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])
# Plot with 'jet' colormap to visualize as a heatmap.
plt.imshow(grads, cmap='jet')
However, I keep getting the following error:
InvalidArgumentError: conv2d_1_input_3:0 is both fed and fetched.
I looked elsewhere and have seen suggestions to upgrade keras-vis, I have done this but the same error shows up. The error appears to be in
grads = visualize_saliency(model, layer_idx, filter_indices=class_idx,seed_input=x_test[idx])
as when I comment this line out, no error shows.
How can I solve this?