我正在尝试从https://github.com/raghakot/keras-vis/blob/master/examples/mnist/attention.ipynb复制结果以产生显着性为零的图。我输入了完全相同的代码,并按建议使用了:
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')
但是,我不断收到以下错误:
InvalidArgumentError: conv2d_1_input_3:0 is both fed and fetched.
我在其他地方看过,并且看到了升级keras-vis的建议,虽然这样做了,但还是出现了相同的错误。错误似乎在
中grads = visualize_saliency(model, layer_idx, filter_indices=class_idx,seed_input=x_test[idx])
当我注释掉这一行时,没有错误显示。
我该如何解决?
答案 0 :(得分:1)
已解决!如果有人遇到此问题,请使用: pip安装git + git://github.com/raghakot/keras-vis.git --upgrade --no-deps