raghakot / keras-vis

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

Issues with saliency map for 1d input #135

Closed subhashis closed 5 years ago

subhashis commented 5 years ago

I have a fully connected network with 1d input of size 35 and generates 1d output of size 50. I wanted to compute the saliency map for given inputs for this network. However, the output of the visualize_saliency(... ) function is just returning me an array of size 3 (instead for size 35 i.e. my input size).

my model structure

M1.summary()

Layer (type) Output Shape Param #


input_2 (InputLayer) (None, 35) 0


dense_37 (Dense) (None, 64) 2304


activation_25 (Activation) (None, 64) 0


dense_38 (Dense) (None, 100) 6500


activation_26 (Activation) (None, 100) 0


dense_39 (Dense) (None, 50) 5050


Total params: 13,854 Trainable params: 13,854 Non-trainable params: 0


layer_idx = utils.find_layer_idx(M1, 'dense_39') sm1 = visualize_saliency(M1, layer_idx, seed_input=new_seed_input, filter_indices=None) #new_seed_input is of shape (1,35) print sm1 [0 0 127]

Not sure where is the problem. Any help would be really appreciated. Thanks!

keisen commented 5 years ago

Currently, keras-vis in PyPI is quite old. The cause of your problem is the bug of keras-vis in old version.

Please re-install keras-vis of currently master branch, as follows:

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

or

$ git clone https://github.com/raghakot/keras-vis.git
$ cd keras-vis
$ python setup.py install
subhashis commented 5 years ago

I updated my keras-vis version to the latest version. The output of the visualize_saliency( ) is now just a single scalar value instead of the vector of size 35 (which is the size of my input vector). @keisen is this the expected outcome for the api call I made (above)

keisen commented 5 years ago

@subhashis , it's good. Do you have any problem yet? If there is no problem, please close this issue.

subhashis commented 5 years ago

@keisen I don't think the problem has been solved yet.

With an input vector of size 35 the expected dimension of the saliency map is 35 as well. But currently, it is returning just a single scalar value.

On inspecting the visualize_saliency_with_losses( ) function I saw that the last two lines are grads = np.max(grads, axis=channel_idx)

return utils.normalize(grads)[0]

before updating grads, its dimension was (1,35), which actually matches with my input vector dimension.

keisen commented 5 years ago

@subhashis , Thanks!

I created the PR #137 to fix this issue. So please make sure of what there is no your problem in this PR.

keisen commented 5 years ago

Sorry, I forgot to mention one thing.