How to correctly get layer weights from Conv2D in keras? : <p>I have Conv2D layer defines as: <br></p>

<pre><code>Conv2D(96, kernel_size=(5, 5),
             activation='relu',
             input_shape=(image_rows, image_cols, 1),
             kernel_initializer=initializers.glorot_normal(seed),
             bias_initializer=initializers.glorot_uniform(seed),
             padding='same',
             name='conv_1')
</code></pre>

<p>This is the first layer in my network. <br>
Input dimensions are 64 by 160, image is 1 channel. <br>
I am trying to visualize weights from this convolutional layer but not sure how to get them. <br>
Here is how I am doing this now: <br></p>

<p>1.Call</p>

<pre><code>layer.get_weights()[0]
</code></pre>

<p>This returs an array of shape (5, 5, 1, 96). 1 is because images are 1-channel.<br></p>

<p>2.Take 5 by 5 filters by</p>

<pre><code>layer.get_weights()[0][:,:,:,j][:,:,0]
</code></pre>

<p>Very ugly but I am not sure how to simplify this, any comments are very appreciated. <br></p>

<p>I am not sure in these 5 by 5 squares. Are they filters actually? <br>
If not could anyone please tell how to correctly grab filters from the model?<br></p>
