raghakot / keras-vis

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

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

Open jntorres opened 4 years ago

jntorres commented 4 years ago

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'
keisen commented 4 years ago

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.