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 = output_data[bidx]["label"].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"{self.tag_name} - b{bidx} - "
              if self.batch_limit != 1
              else ""
          )
          img_np = image[:3] * 128 + 128
          img_tensor = make_grid(
              torch.from_numpy(img_np), normalize=True
          )
          self.writer.add_image(
              tag=f"{tag_prefix}Image",
              img_tensor=img_tensor,
              global_step=epoch,
          )
  
          y_pred = output_data[bidx]["pred"].detach().cpu().numpy()
  
          for region in range(y_pred.shape[0]):
              if (
                  region == 0 and y_pred.shape[0] > 1
              ):  # one-hot; background
                  continue
  
              cl = np.count_nonzero(y[region])
              cp = np.count_nonzero(y_pred[region])
              self.logger.info(
                  "{} => {} - {} - Image: {};"
                  " Label: {} (nz: {});"
                  " Pred: {} (nz: {});"
                  " Diff: {:.2f}%; ".format(
                      self.tag_name,
                      bidx,
                      region,
                      image.shape,
                      y.shape,
                      cl,
                      y_pred.shape,
                      cp,
                      100 * (cp - cl) / (cl + 1),
                  )
              )
  
              tag_prefix = (
                  f"{self.tag_name} - b{bidx}:l{region} - "
                  if self.batch_limit != 1
                  else f"{self.tag_name} - l{region} - "
              )
  
              label_pred = [y[region][None], y_pred[region][None]]
              label_pred_tag = f"{tag_prefix}Label vs Pred:"
              img_tensor = make_grid(
                  tensor=torch.from_numpy(np.array(label_pred)),
                  nrow=2,
                  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
  
imports: import logging
  import math
  import statistics
  from typing import TYPE_CHECKING, Any, Callable, Dict, Optional
  import numpy
  import torch
  import torch.distributed
  from monai.config import IgniteInfo
  from monai.metrics import compute_dice
  from monai.utils import min_version, optional_import
label_desc: Use image node_id 4 for calling the TensorBoardImageHandler obj's underlying member method code with example usage: obj.write_images(batch_data, output_data, epoch) without return types