raghakot / keras-vis

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

Cannot visualize more than one filter #78

Open ghost opened 6 years ago

ghost commented 6 years ago

I build the following model

    InputLayer(input_shape=[1, 28, 28]),
    Conv2D(6, kernel_size=[3, 3], activation='relu', padding='same', data_format='channels_first'),
    Conv2D(12, kernel_size=[3, 3], activation='relu', padding='same', data_format='channels_first'),
    Flatten(),
    Dense(10, activation='softmax'),
])```

and i try to visualize the saliency map for the second convolution output, so i run this code

```bg = BatchGenerator(data_path, batch_size=32)
img, label = next(bg.next_batch())
r = visualize_saliency(model,
                  layer_idx=2,
                  #penultimate_layer_idx=1,
                  filter_indices=[0, 11],
                  seed_input=img[0])

print(type(r))
print(r.shape)

The first thing i observed is that even if i pass input sizes of [1, 28, 28] (MNIST), the r.shape is (28, 28, 3), but I guess this is intended behaviour since we need more than a gray image to visualize saliency. But if I choose to visualize all filters of the second layer, why i am getting back only one heatmap? I was expecting r.shape to be of size [12, 28, 28, 3], but i only get [28, 28, 3].

raghakot commented 6 years ago

Yea. Batching has a bunch of other consequences. Its been on my mind for a long time now to support batched operations. That is the first thing coming in the next release.

dsblank commented 6 years ago

I'm wondering if keras-vis's "saliency" and "filter" looks something like this:

https://jupyter.brynmawr.edu/services/public/dblank/Examples/conx/Sample%20Output%20in%20Conx.ipynb

Not competing with keras-vis, but making an easy to use system for keras non-experts. Happy to collaborate, too!