title: getting axes don't match array error when trying to visualize all layers in caffe using classification.ipny
body: <p>I am a newbie in python and have a very basic knowledge of the language, having said that, I'm trying to get the visualization for all layers both for weights and their filters.For this instead of repeating:  </p>
  
  <pre><code># the parameters are a list of [weights, biases]
  filters = net.params['conv1'][0].data
  vis_square(filters.transpose(0, 2, 3, 1))
  </code></pre>
  
  <p>and changing layer name, I tried using a loop like this : </p>
  
  <pre><code> for layer_name, param in net.params.iteritems():
      # the parameters are a list of [weights, biases]
      filters = net.params[layer_name][0].data
      vis_square(filters.transpose(0, 2, 3, 1))
  </code></pre>
  
  <p>now it works fine for the first layer, but gives this error and stops running: </p>
  
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-16-cf7d5999a45c&gt; in &lt;module&gt;()
        2     # the parameters are a list of [weights, biases]
        3     filters = net.params[layer_name][0].data
  ----&gt; 4     vis_square(filters.transpose(0, 2, 3, 1))
  
  ValueError: axes don't match array
  </code></pre>
  
  <p>And this is the definition of <code>vis_square()</code> (defined in classification.ipny in example directory of caffe):</p>
  
  <pre><code>def vis_square(data):
      """Take an array of shape (n, height, width) or (n, height, width, 3)
         and visualize each (height, width) thing in a grid of size approx. sqrt(n) by sqrt(n)"""
  
      # normalize data for display
      data = (data - data.min()) / (data.max() - data.min())
  
      # force the number of filters to be square
      n = int(np.ceil(np.sqrt(data.shape[0])))
      padding = (((0, n ** 2 - data.shape[0]),
                 (0, 1), (0, 1))                 # add some space between filters
                 + ((0, 0),) * (data.ndim - 3))  # don't pad the last dimension (if there is one)
      data = np.pad(data, padding, mode='constant', constant_values=1)  # pad with ones (white)
  
      # tile the filters into an image
      data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
      data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])
  
      plt.imshow(data); plt.axis('off')
  </code></pre>
  
  <p>What is wrong here?<br>
  I'd be grateful if anyone could give me a hand on this.  </p>