Visualizing learned filters at each layer

7,212 views
Skip to first unread message

Raunaq Vohra

unread,
Aug 25, 2015, 9:29:15 AM8/25/15
to Keras-users
Hi, I was wondering whether there's a way to visualize the filters my model has learned? I have the saved weights (from model.save_weights(), after model.evaluate()) and I also dump them at the end of my code, like so:

all_weights = []
for layer in model.layers:
   w
= layer.get_weights()
   all_weights
.append(w)

all_weights
= np.array(all_weights)
np
.save('all_weights.npy', all_weights)

How can I use them?

Thanks!

François Chollet

unread,
Aug 25, 2015, 2:08:28 PM8/25/15
to Raunaq Vohra, Keras-users
These weights are regular numpy arrays, which you can plot using Matplotlib for instance (or other libraries).


--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/e9c2a856-331f-4a32-8b1d-3b84ec8627b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raunaq Vohra

unread,
Aug 26, 2015, 9:50:41 AM8/26/15
to Keras-users, ronv...@gmail.com
Thanks François, exactly what I was looking for.

csi...@altius.org

unread,
Mar 28, 2017, 8:27:22 PM3/28/17
to Keras-users
So I think that the example here is no longer valid.

I used a 1D convolutional layer for my first layer:

```
    model = Sequential()
    model.add(Conv1D(3, 5, input_shape=(None, 4)))
```

then if I do
```
filters = model.layers[0].get_weights()[0]
np.shape(filters)
```
I get a shape of `(5, 4, 3)`! So the first argument is no longer the number of filters, rather filter i is `filters[:, :, i]`. Is that right?

Thanks.

pr...@cogent.co.jp

unread,
May 17, 2017, 3:55:09 AM5/17/17
to Keras-users, csi...@altius.org

abhig...@gmail.com

unread,
Sep 7, 2018, 8:08:14 AM9/7/18
to Keras-users
On a similar note , in a given layer for number of filters how to extract / visualize the filter which has the maximum magnitude or strongest activation map in the given filter layer .  

Ted Yu

unread,
Sep 7, 2018, 1:06:32 PM9/7/18
to abhig...@gmail.com, keras...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages