raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.97k stars 664 forks source link

InvalidArgumentError: input_1_1:0 is both fed and fetched. #145

Closed peterhsu2018 closed 5 years ago

peterhsu2018 commented 5 years ago

run example/resnet/attention.ipynb and change to the model with my custom resnet50 like this: model_path = os.path.join('../../../saved_models', 'res50transfer_learning.h5') model = load_model(model_path)

layer_idx = utils.find_layer_idx(model, 'dense_1')

my environment Keras 2.2.2 Tensorflow 1.10 Keras-vis 0.4.1

keisen commented 5 years ago

Hi @peterhsu2018 . Sorry, keras-vis was not released that this problem was fixed. So please directly re-install keras-vis via github.

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

This issue should have fixed by PR #120 , so I'll close this. But if I made mistaken, please feel free to reopen.

Thanks!

peterhsu2018 commented 5 years ago

Hi @peterhsu2018 . Sorry, keras-vis was not released that this problem was fixed. So please directly re-install keras-vis via github.

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

This issue should have fixed by PR #120 , so I'll close this. But if I made mistaken, please feel free to reopen.

Thanks!

Hi @keisen This is helpful for me Thanks a lot!

lrsoenksen commented 5 years ago

Hi @peterhsu2018 . Sorry, keras-vis was not released that this problem was fixed. So please directly re-install keras-vis via github.

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

This issue should have fixed by PR #120 , so I'll close this. But if I made mistaken, please feel free to reopen.

Thanks!

This response by @keisen worked for me too, but only after doing a fresh re-install

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

-then refresh env in jupyter notebook and done! It should be working =)

fsteiner commented 5 years ago

Hello @peterhsu2018 @keisen

It worked for me after reinstalling keras and tensorflow.

Many thanks for your help !

michiexile commented 5 years ago

Installed keras-vis from the github, and reinstalled both keras and tensorflow. I am still getting this error.

from tensorflow.keras import layers, models, datasets, utils

inp = layers.Input((28,28))
x = layers.Flatten()(inp)
x = layers.BatchNormalization()(x)
x = layers.Dense(1024, activation="relu")(x)
x = layers.Dense(512, activation="relu")(x)
x = layers.Dense(128, activation="relu")(x)
oup = layers.Dense(10, activation="softmax")(x)

model = models.Model(inputs=inp, outputs=oup)
model.compile("rmsprop", loss="categorical_crossentropy", metrics=["accuracy"])

(X_train,y_train),(X_test,y_test) = datasets.fashion_mnist.load_data()
y_train = utils.to_categorical(y_train)
y_test = utils.to_categorical(y_test)

model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=1)

from vis import visualization, utils
from keras import activations

layer_idx = -1

model.layers[layer_idx].activation = activations.linear
model.save("tmp.model")
model = models.load_model("tmp.model")

grads = visualization.visualize_saliency(model, 2, 
   filter_indices=0,
   seed_input=X_test[0])
indramal commented 5 years ago

Installed keras-vis from the github, and reinstalled both keras and tensorflow. I am still getting this error.

from tensorflow.keras import layers, models, datasets, utils

inp = layers.Input((28,28))
x = layers.Flatten()(inp)
x = layers.BatchNormalization()(x)
x = layers.Dense(1024, activation="relu")(x)
x = layers.Dense(512, activation="relu")(x)
x = layers.Dense(128, activation="relu")(x)
oup = layers.Dense(10, activation="softmax")(x)

model = models.Model(inputs=inp, outputs=oup)
model.compile("rmsprop", loss="categorical_crossentropy", metrics=["accuracy"])

(X_train,y_train),(X_test,y_test) = datasets.fashion_mnist.load_data()
y_train = utils.to_categorical(y_train)
y_test = utils.to_categorical(y_test)

model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=1)

from vis import visualization, utils
from keras import activations

layer_idx = -1

model.layers[layer_idx].activation = activations.linear
model.save("tmp.model")
model = models.load_model("tmp.model")

grads = visualization.visualize_saliency(model, 2, 
   filter_indices=0,
   seed_input=X_test[0])

First, remove all vis packages by the following code,

pip uninstall vis
pip uninstall keras-vis
pip uninstall keras-vis-temp

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