new_contents: # Copyright 2014-2017 The DIPP contributors
  #
  # This file is part of DIPP.
  #
  # This Source Code Form is subject to the terms of the Mozilla Public License,
  # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  # obtain one at https://mozilla.org/MPL/2.0/.
  
  """Utilities for pyTorch."""
  
  
  def show_image_matrix(image_batches, titles=None, indices=None, **kwargs):
      """Visualize a 2D set of images arranged in a grid.
  
      This function shows a 2D grid of images, where the i-th column
      shows images from the i-th batch. The typical use case is to compare
      results of different approaches with the same data, or to compare
      against a ground truth.
  
      Parameters
      ----------
      image_batches : sequence of `Tensor` or `Variable`
          List containing batches of images that should be displayed.
          Each tensor should have the same shape after squeezing, except
          for the batch axis.
      titles : sequence of str, optional
          Titles for the colums in the plot. By default, titles are empty.
      indices : sequence of int, optional
          Object to select the subset of the images that should be shown.
          The subsets are determined by slicing along the batch axis, i.e.,
          as ``displayed = image_batch[indices]``. The default is to show
          everything.
      kwargs :
          Further keyword arguments that are passed on to the Matplotlib
          ``imshow`` function.
      """
      import matplotlib.pyplot as plt
  
      if indices is None:
          displayed_batches = image_batches
      else:
          displayed_batches = [batch[indices] for batch in image_batches]
  
      nrows = len(displayed_batches[0])
      ncols = len(displayed_batches)
  
      if titles is None:
          titles = [''] * ncols
  
      figsize = 2
      fig, rows = plt.subplots(
          nrows, ncols, sharex=True, sharey=True,
          figsize=(ncols * figsize, figsize * nrows))
  
      if nrows == 1:
          rows = [rows]
  
      for i, row in enumerate(rows):
          if ncols == 1:
              row = [row]
          for name, batch, ax in zip(titles, displayed_batches, row):
              if i == 0:
                  ax.set_title(name)
              ax.imshow(batch[i].squeeze(), **kwargs)
              ax.set_axis_off()
      plt.show()
  
subject: add image matrix plotter for pytorch