keras-vis icon indicating copy to clipboard operation
keras-vis copied to clipboard

AttributeError: 'int' object has no attribute 'dtype'

Open jntorres opened this issue 5 years ago • 1 comments

  • [ ] 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).

Hello, I am trying to run through the Attention on MNIST (Saliency and grad-CAM) example and I am running into the following issue.


AttributeError Traceback (most recent call last) in 11 model = utils.apply_modifications(model) 12 ---> 13 grads = visualize_saliency(model, layer_idx, filter_indices=class_idx, seed_input=x_test[idx]) 14 # Plot with 'jet' colormap to visualize as a heatmap. 15 plt.imshow(grads, cmap='jet')

~/jessica/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/vis/visualization/saliency.py in visualize_saliency(model, layer_idx, filter_indices, seed_input, wrt_tensor, backprop_modifier, grad_modifier, keepdims) 132 (ActivationMaximization(model.layers[layer_idx], filter_indices), -1) 133 ] --> 134 return visualize_saliency_with_losses(model.input, losses, seed_input, wrt_tensor, grad_modifier, keepdims) 135 136

~/jessica/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/vis/visualization/saliency.py in visualize_saliency_with_losses(input_tensor, losses, seed_input, wrt_tensor, grad_modifier, keepdims) 77 """ 78 opt = Optimizer(input_tensor, losses, wrt_tensor=wrt_tensor, norm_grads=False) ---> 79 grads = opt.minimize(seed_input=seed_input, max_iter=1, grad_modifier=grad_modifier, verbose=False)[1] 80 81 if not keepdims:

~/jessica/anaconda3/envs/tf_gpu/lib/python3.7/site-packages/vis/optimizer.py in minimize(self, seed_input, max_iter, input_modifiers, grad_modifier, callbacks, verbose) 151 152 # 0 learning phase for 'test' --> 153 computed_values = self.compute_fn([seed_input, 0]) 154 losses = computed_values[:len(self.loss_names)] 155 named_losses = list(zip(self.loss_names, losses))

~/.local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in call(self, inputs) 2713 return self._legacy_call(inputs) 2714 -> 2715 return self._call(inputs) 2716 else: 2717 if py_any(is_tensor(x) for x in inputs):

~/.local/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in _call(self, inputs) 2653 array_vals.append( 2654 np.asarray(value, -> 2655 dtype=tf.as_dtype(tensor.dtype).as_numpy_dtype)) 2656 if self.feed_dict: 2657 for key in sorted(self.feed_dict.keys()):

AttributeError: 'int' object has no attribute 'dtype'

jntorres avatar Aug 06 '19 06:08 jntorres

I've run the example notebook, but could NOT reproduce the issue. Did you modify the example notebook ? If not, there may be the environmental issue. Please let me know the result of pip freeze and keras-vis version(or git-commit-id) of example notebook you use.

keisen avatar Dec 20 '19 05:12 keisen