code: def add(self, index, var):
          
          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, '*')))
docs: 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.