code: def write_images(self, batch_data, output_data, epoch):
      for bidx in range(len(batch_data)):
          image = batch_data[bidx]["image"].detach().cpu().numpy()
          y = batch_data[bidx]["label"].detach().cpu().numpy()
          y_pred = output_data[bidx]["pred"].detach().cpu().numpy()
  
          # Only consider non-empty label in case single write
          if (
              self.batch_limit == 1
              and bidx < (len(batch_data) - 1)
              and np.sum(y) == 0
          ):
              continue
  
          tag_prefix = f"b{bidx} - " if self.batch_limit != 1 else ""
          tag_prefix = f"{self.tag_prefix}{tag_prefix}"
          img_tensor = make_grid(
              torch.from_numpy(image[:3] * 128 + 128), normalize=True
          )
          self.writer.add_image(
              tag=f"{tag_prefix}Image",
              img_tensor=img_tensor,
              global_step=epoch,
          )
  
          for region in range(y_pred.shape[0]):
              if (
                  region == 0
                  and y_pred.shape[0] != y.shape[0]
                  and y_pred.shape[0] > 1
              ):  # one-hot; background
                  continue
  
              if y_pred.shape[0] == y.shape[0]:
                  label = y[region][np.newaxis]
              else:
                  label = np.zeros(y.shape)
                  label[y == region] = region
  
              self.logger.info(
                  "{} - {} - Image: {}; Label: {} (nz: {}); Pred: {} (nz: {}); Sig: (pos-nz: {}, neg-nz: {})".format(
                      bidx,
                      region,
                      image.shape,
                      label.shape,
                      np.count_nonzero(label),
                      y_pred.shape,
                      np.count_nonzero(y_pred[region]),
                      np.count_nonzero(image[3])
                      if image.shape[0] == 5
                      else 0,
                      np.count_nonzero(image[4])
                      if image.shape[0] == 5
                      else 0,
                  )
              )
  
              tag_prefix = (
                  f"b{bidx}:l{region} - "
                  if self.batch_limit != 1
                  else f"l{region} - "
              )
              tag_prefix = f"{self.tag_prefix}{tag_prefix}"
  
              label_pred = [label, y_pred[region][None]]
              label_pred_tag = f"{tag_prefix}Label vs Pred:"
              if image.shape[0] == 5:
                  label_pred = [
                      label,
                      y_pred[region][None],
                      image[3][None],
                      image[4][None],
                  ]
                  label_pred_tag = (
                      f"{tag_prefix}Label vs Pred vs Pos vs Neg"
                  )
  
              img_tensor = make_grid(
                  tensor=torch.from_numpy(np.array(label_pred)),
                  nrow=4,
                  normalize=True,
                  pad_value=10,
              )
              self.writer.add_image(
                  tag=label_pred_tag,
                  img_tensor=img_tensor,
                  global_step=epoch,
              )
  
          if self.batch_limit == 1 or bidx == (self.batch_limit - 1):
              break
  
file_path: MONAILabel/monailabel/deepedit/handlers.py
imports: import logging
  from typing import TYPE_CHECKING, Any, Callable, Dict, Optional
  import numpy
  import torch
  from monai.config import IgniteInfo
  from monai.utils import min_version, optional_import
  from monai.visualize import plot_2d_or_3d_image
  from torch import distributed
  from torchvision.utils import make_grid
label_desc: Use image node_id 4 for calling the TensorBoard2DImageHandler obj's underlying member method code with example usage: obj.write_images(batch_data, output_data, epoch) without return types