我正在keras-vis中使用visualize_activation函数:
from vis.visualization import visualize_activation, visualize_cam
from vis.utils import utils
from keras import activations
from matplotlib import pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = (18, 6)
# 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(my_model, 're_lu_3')
patches = np.expand_dims(patches,axis=3)
# This is the output node we want to maximize.
filter_idx = None
img = visualize_activation(my_model, layer_idx, filter_indices=filter_idx,
seed_input=patches[0])
plt.imshow(img[..., 0])
但是,这将引发错误:InvalidArgumentError:输入_1_1:0被同时获取和获取。
该如何解决?我尝试使用tf.identity创建my_model的副本,但这没用。
答案 0 :(得分:0)
keras-vis
在pip上似乎坏了,请尝试直接在GitHub master分支上安装:
pip uninstall vis
pip install git+https://github.com/raghakot/keras-vis.git -U
使用pip上的版本,MNIST和ResNet示例都将输出错误:InvalidArgumentError: input_1_1:0 is both fed and fetched.
。更新后,它们都可以正常工作。