This function displays a grid of images to show full misclassification
  :param data: grid data of the form;
      [nb_classes : nb_classes : img_rows : img_cols : nb_channels]
  :return: if necessary, the matplot figure to reuse

def grid_visual(data):
  """
  This function displays a grid of images to show full misclassification
  :param data: grid data of the form;
      [nb_classes : nb_classes : img_rows : img_cols : nb_channels]
  :return: if necessary, the matplot figure to reuse
  """
  import matplotlib.pyplot as plt

  # Ensure interactive mode is disabled and initialize our graph
  plt.ioff()
  figure = plt.figure()
  figure.canvas.set_window_title('Cleverhans: Grid Visualization')

  # Add the images to the plot
  num_cols = data.shape[0]
  num_rows = data.shape[1]
  num_channels = data.shape[4]
  for y in range(num_rows):
    for x in range(num_cols):
      figure.add_subplot(num_rows, num_cols, (x + 1) + (y * num_cols))
      plt.axis('off')

      if num_channels == 1:
        plt.imshow(data[x, y, :, :, 0], cmap='gray')
      else:
        plt.imshow(data[x, y, :, :, :])

  # Draw the plot and return
  plt.show()
  return figure