code: def plot_conv_activity(layer, x, figsize=(6, 8)):
      
      if x.shape[0] != 1:
          raise ValueError("Only one sample can be plotted at a time.")
  
      # compile theano function
      xs = T.tensor4('xs').astype(theano.config.floatX)
      get_activity = theano.function([xs], get_output(layer, xs))
  
      activity = get_activity(x)
      shape = activity.shape
      nrows = np.ceil(np.sqrt(shape[1])).astype(int)
      ncols = nrows
  
      figs, axes = plt.subplots(nrows + 1, ncols, figsize=figsize, squeeze=False)
      axes[0, ncols // 2].imshow(1 - x[0][0], cmap='gray',
                                 interpolation='none')
      axes[0, ncols // 2].set_title('original')
  
      for ax in axes.flatten():
          ax.set_xticks([])
          ax.set_yticks([])
          ax.axis('off')
  
      for i, (r, c) in enumerate(product(range(nrows), range(ncols))):
          if i >= shape[1]:
              break
          ndim = activity[0][i].ndim
          if ndim != 2:
              raise ValueError("Wrong number of dimensions, image data should "
                               "have 2, instead got {}".format(ndim))
          axes[r + 1, c].imshow(-activity[0][i], cmap='gray',
                                interpolation='none')
      return plt
docs: Plot the acitivities of a specific layer.
  
      Only really makes sense with layers that work 2D data (2D
      convolutional layers, 2D pooling layers ...).
  
      Parameters
      ----------
      layer : lasagne.layers.Layer
  
      x : numpy.ndarray
        Only takes one sample at a time, i.e. x.shape[0] == 1.