Python – Invalid parameter error: input_1_1:0 is both fed and fetched

Invalid parameter error: input_1_1:0 is both fed and fetched… here is a solution to the problem.

Invalid parameter error: input_1_1:0 is both fed and fetched

I use the visualize_activation function in keras-vis:

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])

However, this throws an error: InvalidArgumentError: input_1_1:0 is both fed and fetched.

How to solve it? I tried creating a copy of my_model using tf.identity but that didn’t work.

Solution

keras-vis seems to be broken on pip, try installing directly on the GitHub master branch:

pip uninstall vis
pip install git+https://github.com/raghakot/keras-vis.git -U

Using the version on pip, both the MNIST and ResNet examples output an error: InvalidArgumentError: input_1_1:0 is both fed and fetched. After updating, they all work well.

Related Problems and Solutions