title: weight visualization of 3d convolutional kernel
body: <p>I am using  3d kernel of size 3x3x3 for the convoution layer and would like to plot the weights of the layer.</p>
  
  <p>Since plotting in 3d is not possible i tried to split the kernels into 3 3×3 for plotting.
  Is this approach correct?</p>
  
  <p>The conv layer consists of 5 layers #model.add(layers.Conv3D(5, (3, 3, 3), padding=’same’))</p>
  
  <p>Please find below the code I used to plot the weights</p>
  
  <pre><code>from keras.models import load_model
  mymodel = load_model(‘model.hdf5′)
  
  from matplotlib import pyplot as plt
  # load the model
  
  # retrieve weights from the 1st conv layer layer
  filters, biases = mymodel.layers[0].get_weights()
  # normalize filter values to 0-1 so we can visualize them
  f_min, f_max = filters.min(), filters.max()
  filters = (filters – f_min) / (f_max – f_min)
  #shape of filters (3, 3, 3, 1, 5)
  n_filters, ix = 5, 1
  for i in range(n_filters):
  # get the filter
  f = filters[:,:, :, :, i]
  f = f[:,:,:,0]
  # kernel shape 3x3x3 but to plot it converting into 3 3×3 filters
  for j in range(3):
  # specify subplot and turn of axis
  ax = plt.subplot(n_filters, 3, ix)
  ax.set_xticks([])
  ax.set_yticks([])
  # plot filter channel in grayscale
  plt.imshow(f[:, :, j], cmap=’gray’)
  ix += 1
  # show the figure
  plt.show()
  
  </code></pre>
  
  <p>Is this method correct or is there any better way in which this can be done?</p>
  
  <p>Looking forward to your reply</p>