class_docstr: Saves a series of images.
  
  The `.add()` method takes a ``(N,..., C, H, W)`` array as an input,
  and ``num_images`` of ``[H, W, :min(3, C)]`` are saved into
  the monitor folder for each interval.
  
  The values are displayed and/or output to the file
  ``<name>/{iter}-{image index}.png``.
  
  Example:
  
  .. code-block:: python
  
      import numpy as np
      m = Monitor('tmp.monitor')
      mi = MonitorImage('noise', m, interval=2, num_images=2)
      x = np.random.randn(10, 3, 8, 8)
      for i in range(10):
          mi.add(i, x)
  
  Args:
      name (str): Name of the monitor. Used in the log.
      monitor (~nnabla.monitor.Monitor): Monitor class instance.
      interval (int): Interval of flush the outputs.
      num_images (int): Number of images to be saved in each iteration.
      normalize_method (function): A function that takes a NCHW format image minibatch
          as :obj:`numpy.ndarray`. The function should define a normalizer which
          map any inputs to a range of [0, 1]. The default normalizer normalizes
          the images into min-max normalization.
class_docstr_tok: ["Saves","a","series","of","images",".","The","`",".add","(",")","`","method","takes","a","``","(","N",",","...",",","C",",","H",",","W",")","``","array","as","an","input",",","and","``","num_images","``","of","``","[","H",",","W",",",":","min","(","3",",","C",")","]","``","are","saved","into","the","monitor","folder","for","each","interval",".","The","values","are","displayed","and\/or","output","to","the","file","``","<","name",">","\/","{","iter","}","-","{","image","index","}",".png","``",".","Example",":","..","code-block",":",":","python","import","numpy","as","np","m","=","Monitor","(","'tmp.monitor","'",")","mi","=","MonitorImage","(","'noise","'",",","m",",","interval=2",",","num_images=2",")","x","=","np.random.randn","(","10",",","3",",","8",",","8",")","for","i","in","range","(","10",")",":","mi.add","(","i",",","x",")","Args",":","name","(","str",")",":","Name","of","the","monitor",".","Used","in","the","log",".","monitor","(","~nnabla.monitor.Monitor",")",":","Monitor","class","instance",".","interval","(","int",")",":","Interval","of","flush","the","outputs",".","num_images","(","int",")",":","Number","of","images","to","be","saved","in","each","iteration",".","normalize_method","(","function",")",":","A","function","that","takes","a","NCHW","format","image","minibatch","as",":","obj",":","`","numpy.ndarray","`",".","The","function","should","define","a","normalizer","which","map","any","inputs","to","a","range","of","[","0",",","1","]",".","The","default","normalizer","normalizes","the","images","into","min-max","normalization","."]
docstr: Add a minibatch of images to the monitor.
  
  Args:
      index (int): Index.
      var (:obj:`~nnabla.Variable`, :obj:`~nnabla.NdArray`, or :obj:`~numpy.ndarray`):
          A minibatch of images with ``(N, ..., C, H, W)`` format.
          If C == 2, blue channel is appended with ones. If C > 3,
          the array will be sliced to remove C > 3 sub-array.
docstr_tok: ["Add","a","minibatch","of","images","to","the","monitor",".","Args",":","index","(","int",")",":","Index",".","var","(",":","obj",":","`","~nnabla.Variable","`",",",":","obj",":","`","~nnabla.NdArray","`",",","or",":","obj",":","`","~numpy.ndarray","`",")",":","A","minibatch","of","images","with","``","(","N",",","...",",","C",",","H",",","W",")","``","format",".","If","C","==","2",",","blue","channel","is","appended","with","ones",".","If","C",">","3",",","the","array","will","be","sliced","to","remove","C",">","3","sub-array","."]
code: def add(self, index, var):
      """Add a minibatch of images to the monitor.
  
      Args:
          index (int): Index.
          var (:obj:`~nnabla.Variable`, :obj:`~nnabla.NdArray`, or :obj:`~numpy.ndarray`):
              A minibatch of images with ``(N, ..., C, H, W)`` format.
              If C == 2, blue channel is appended with ones. If C > 3,
              the array will be sliced to remove C > 3 sub-array.
  
      """
      import nnabla as nn
      from nnabla.utils.image_utils import imsave
  
      if index != 0 and (index + 1) % self.interval != 0:
          return
      if isinstance(var, nn.Variable):
          data = var.d.copy()
      elif isinstance(var, nn.NdArray):
          data = var.data.copy()
      else:
          assert isinstance(var, np.ndarray)
          data = var.copy()
      assert data.ndim > 2
      channels = data.shape[-3]
      data = data.reshape(-1, *data.shape[-3:])
      data = data[: min(data.shape[0], self.num_images)]
      data = self.normalize_method(data)
      if channels > 3:
          data = data[:, :3]
      elif channels == 2:
          data = np.concatenate(
              [data, np.ones((data.shape[0], 1) + data.shape[-2:])],
              axis=1,
          )
      path_tmpl = os.path.join(self.save_dir, "{:06d}-{}.png")
      for j in range(min(self.num_images, data.shape[0])):
          img = data[j].transpose(1, 2, 0)
          if img.shape[-1] == 1:
              img = img[..., 0]
          path = path_tmpl.format(index, "{:03d}".format(j))
          imsave(path, img)
      if self.verbose:
          logger.info(
              "iter={} {{{}}} are written to {}.".format(
                  index, self.name, path_tmpl.format(index, "*")
              )
          )
  
imports: from __future__ import print_function
  import numpy
  import os
  import time
  from nnabla.logger import logger
label_desc: Use image node_id 3 for calling the MonitorImage obj's underlying member method code with example usage: obj.add(index, var) without return types