Skip to content

Tensorflow version? #231

@ZehanDai

Description

@ZehanDai
  • [√] Check that you are up-to-date with the master branch of keras-vis. You can update with:
    pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps

  • [√] If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:
    pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps

  • Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

Hi all,

When I tried the script in this page on test image in reference to the ipynb script below, I got an error: tensorflow.python.framework.errors_impl.InvalidArgumentError: No such callable handle: 140395736213952
while the script reached this line img = visualize_activation(model, layer_idx, filter_indices=20)

I don't have a clue on how to fix it. Is it possibly caused by the tensorflow version? I am using a very old one (tensorflow 1.10.0).

Actually I tried newest version of tensorflow and keras at the beginning. But I came across an issue https://github.com/raghakot/keras-vis/issues/228 and solved by following AniketSawale's advice https://github.com/raghakot/keras-vis/issues/228#issuecomment-670492169

My script is:
`from keras.applications import VGG16
from vis.utils import utils
from keras import activations

'# Build the VGG16 network with ImageNet weights
model = VGG16(weights='imagenet', include_top=True)

'# 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, 'predictions')

'# Swap softmax with linear
model.layers[layer_idx].activation = activations.linear
model = utils.apply_modifications(model)

from vis.visualization import visualize_activation
from matplotlib import pyplot as plt
import cv2 as cv
'# %matplotlib inline
plt.rcParams['figure.figsize'] = (18, 6)

'# 20 is the imagenet category for 'ouzel'
img = visualize_activation(model, layer_idx, filter_indices=20)
'# plt.imshow(img)
'# plt.imsave('test.jpg')
print(type(img))
'#plt.savefig('test.png')` which is in reference to this ipynb file. https://github.com/raghakot/keras-vis/blob/master/examples/vggnet/activation_maximization.ipynb

The whole log message:
`/keras-vis-master/examples/vggnet$ python3 test.py
Using TensorFlow backend.
2020-08-19 23:04:29.632666: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/keras/engine/saving.py:269: UserWarning: No training configuration found in save file: the model was not compiled. Compile it manually.
warnings.warn('No training configuration found in save file: '
Traceback (most recent call last):
File "test.py", line 28, in
img = visualize_activation(model, layer_idx, filter_indices=20)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/vis/visualization/activation_maximization.py", line 107, in visualize_activation
return visualize_activation_with_losses(model.input, losses, seed_input, input_range, **optimizer_params)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/vis/visualization/activation_maximization.py", line 41, in visualize_activation_with_losses

img = opt.minimize(**optimizer_params)[0]

File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/vis/optimizer.py", line 143, in minimize
computed_values = self.compute_fn([seed_input, 0])
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2666, in call
return self._call(inputs)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2635, in _call
session)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2587, in _make_callable
callable_fn = session._make_callable_from_options(callable_opts)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1414, in _make_callable_from_options
return BaseSession._Callable(self, callable_options)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1368, in init
session._session, options_ptr, status)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: input_1_1:0 is both fed and fetched.
Exception ignored in: <bound method BaseSession._Callable.del of <tensorflow.python.client.session.BaseSession._Callable object at 0x7fb184a0eef0>>
Traceback (most recent call last):
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1398, in del
self._session._session, self._handle, status)
File "/mnt/d/Programming/py3-vir-env/keras-vis-python3.6.5-ActiveTcl/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: No such callable handle: 140395736213952
/keras-vis-master/examples/vggnet$ `

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions