class_docstr: TensorBoardImageHandler is an Ignite Event handler that can visualize images, labels and outputs as 2D/3D images.
  2D output (shape in Batch, channel, H, W) will be shown as simple image using the first element in the batch,
  for 3D to ND output (shape in Batch, channel, H, W, D) input, each of ``self.max_channels`` number of images'
  last three dimensions will be shown as animated GIF along the last axis (typically Depth).
  And if writer is from TensorBoardX, data has 3 channels and `max_channels=3`, will plot as RGB video.
  
  It can be used for any Ignite Engine (trainer, validator and evaluator).
  User can easily add it to engine for any expected Event, for example: ``EPOCH_COMPLETED``,
  ``ITERATION_COMPLETED``. The expected data source is ignite's ``engine.state.batch`` and ``engine.state.output``.
  
  Default behavior:
      - Show y_pred as images (GIF for 3D) on TensorBoard when Event triggered,
      - Need to use ``batch_transform`` and ``output_transform`` to specify
        how many images to show and show which channel.
      - Expects ``batch_transform(engine.state.batch)`` to return data
        format: (image[N, channel, ...], label[N, channel, ...]).
      - Expects ``output_transform(engine.state.output)`` to return a torch
        tensor in format (y_pred[N, channel, ...], loss).
  
  Usage example is available in the tutorial:
  https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/unet_segmentation_3d_ignite.ipynb.
class_docstr_tok: ["TensorBoardImageHandler","is","an","Ignite","Event","handler","that","can","visualize","images",",","labels","and","outputs","as","2D\/3D","images",".","2D","output","(","shape","in","Batch",",","channel",",","H",",","W",")","will","be","shown","as","simple","image","using","the","first","element","in","the","batch",",","for","3D","to","ND","output","(","shape","in","Batch",",","channel",",","H",",","W",",","D",")","input",",","each","of","``","self.max_channels","``","number","of","images'","last","three","dimensions","will","be","shown","as","animated","GIF","along","the","last","axis","(","typically","Depth",")",".","And","if","writer","is","from","TensorBoardX",",","data","has","3","channels","and","`","max_channels=3","`",",","will","plot","as","RGB","video",".","It","can","be","used","for","any","Ignite","Engine","(","trainer",",","validator","and","evaluator",")",".","User","can","easily","add","it","to","engine","for","any","expected","Event",",","for","example",":","``","EPOCH_COMPLETED","``",",","``","ITERATION_COMPLETED","``",".","The","expected","data","source","is","ignite","'s","``","engine.state.batch","``","and","``","engine.state.output","``",".","Default","behavior",":","-","Show","y_pred","as","images","(","GIF","for","3D",")","on","TensorBoard","when","Event","triggered",",","-","Need","to","use","``","batch_transform","``","and","``","output_transform","``","to","specify","how","many","images","to","show","and","show","which","channel",".","-","Expects","``","batch_transform","(","engine.state.batch",")","``","to","return","data","format",":","(","image","[","N",",","channel",",","...","]",",","label","[","N",",","channel",",","...","]",")",".","-","Expects","``","output_transform","(","engine.state.output",")","``","to","return","a","torch","tensor","in","format","(","y_pred","[","N",",","channel",",","...","]",",","loss",")",".","Usage","example","is","available","in","the","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/3d_segmentation\/unet_segmentation_3d_ignite.ipynb","."]
docstr: Args:
      summary_writer: user can specify TensorBoard or TensorBoardX SummaryWriter,
          default to create a new TensorBoard writer.
      log_dir: if using default SummaryWriter, write logs to this directory, default is `./runs`.
      interval: plot content from engine.state every N epochs or every N iterations, default is 1.
      epoch_level: plot content from engine.state every N epochs or N iterations. `True` is epoch level,
          `False` is iteration level.
      batch_transform: a callable that is used to extract `image` and `label` from `ignite.engine.state.batch`,
          then construct `(image, label)` pair. for example: if `ignite.engine.state.batch` is `{"image": xxx,
          "label": xxx, "other": xxx}`, `batch_transform` can be `lambda x: (x["image"], x["label"])`.
          will use the result to plot image from `result[0][index]` and plot label from `result[1][index]`.
          `engine.state` and `batch_transform` inherit from the ignite concept:
          https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
          https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.
      output_transform: a callable that is used to extract the `predictions` data from
          `ignite.engine.state.output`, will use the result to plot output from `result[index]`.
          `engine.state` and `output_transform` inherit from the ignite concept:
          https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
          https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.
      global_iter_transform: a callable that is used to customize global step number for TensorBoard.
          For example, in evaluation, the evaluator engine needs to know current epoch from trainer.
      index: plot which element in a data batch, default is the first element.
      max_channels: number of channels to plot.
      frame_dim: if plotting 3D image as GIF, specify the dimension used as frames,
          expect input data shape as `NCHWD`, default to `-3` (the first spatial dim)
      max_frames: if plot 3D RGB image as video in TensorBoardX, set the FPS to `max_frames`.
docstr_tok: ["Args",":","summary_writer",":","user","can","specify","TensorBoard","or","TensorBoardX","SummaryWriter",",","default","to","create","a","new","TensorBoard","writer",".","log_dir",":","if","using","default","SummaryWriter",",","write","logs","to","this","directory",",","default","is","`",".\/runs","`",".","interval",":","plot","content","from","engine.state","every","N","epochs","or","every","N","iterations",",","default","is","1.","epoch_level",":","plot","content","from","engine.state","every","N","epochs","or","N","iterations",".","`","True","`","is","epoch","level",",","`","False","`","is","iteration","level",".","batch_transform",":","a","callable","that","is","used","to","extract","`","image","`","and","`","label","`","from","`","ignite.engine.state.batch","`",",","then","construct","`","(","image",",","label",")","`","pair",".","for","example",":","if","`","ignite.engine.state.batch","`","is","`","{","``","image","''",":","xxx",",","``","label","''",":","xxx",",","``","other","''",":","xxx","}","`",",","`","batch_transform","`","can","be","`","lambda","x",":","(","x","[","``","image","''","]",",","x","[","``","label","''","]",")","`",".","will","use","the","result","to","plot","image","from","`","result","[","0","]","[","index","]","`","and","plot","label","from","`","result","[","1","]","[","index","]","`",".","`","engine.state","`","and","`","batch_transform","`","inherit","from","the","ignite","concept",":","https",":","\/\/pytorch.org\/ignite\/concepts.html","#","state",",","explanation","and","usage","example","are","in","the","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/modules\/batch_output_transform.ipynb",".","output_transform",":","a","callable","that","is","used","to","extract","the","`","predictions","`","data","from","`","ignite.engine.state.output","`",",","will","use","the","result","to","plot","output","from","`","result","[","index","]","`",".","`","engine.state","`","and","`","output_transform","`","inherit","from","the","ignite","concept",":","https",":","\/\/pytorch.org\/ignite\/concepts.html","#","state",",","explanation","and","usage","example","are","in","the","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/modules\/batch_output_transform.ipynb",".","global_iter_transform",":","a","callable","that","is","used","to","customize","global","step","number","for","TensorBoard",".","For","example",",","in","evaluation",",","the","evaluator","engine","needs","to","know","current","epoch","from","trainer",".","index",":","plot","which","element","in","a","data","batch",",","default","is","the","first","element",".","max_channels",":","number","of","channels","to","plot",".","frame_dim",":","if","plotting","3D","image","as","GIF",",","specify","the","dimension","used","as","frames",",","expect","input","data","shape","as","`","NCHWD","`",",","default","to","`","-3","`","(","the","first","spatial","dim",")","max_frames",":","if","plot","3D","RGB","image","as","video","in","TensorBoardX",",","set","the","FPS","to","`","max_frames","`","."]
code: def __init__(
      self,
      summary_writer: SummaryWriter | SummaryWriterX | None = None,
      log_dir: str = "./runs",
      interval: int = 1,
      epoch_level: bool = True,
      batch_transform: Callable = lambda x: x,
      output_transform: Callable = lambda x: x,
      global_iter_transform: Callable = lambda x: x,
      index: int = 0,
      max_channels: int = 1,
      frame_dim: int = -3,
      max_frames: int = 64,
  ) -> None:
      """
      Args:
          summary_writer: user can specify TensorBoard or TensorBoardX SummaryWriter,
              default to create a new TensorBoard writer.
          log_dir: if using default SummaryWriter, write logs to this directory, default is `./runs`.
          interval: plot content from engine.state every N epochs or every N iterations, default is 1.
          epoch_level: plot content from engine.state every N epochs or N iterations. `True` is epoch level,
              `False` is iteration level.
          batch_transform: a callable that is used to extract `image` and `label` from `ignite.engine.state.batch`,
              then construct `(image, label)` pair. for example: if `ignite.engine.state.batch` is `{"image": xxx,
              "label": xxx, "other": xxx}`, `batch_transform` can be `lambda x: (x["image"], x["label"])`.
              will use the result to plot image from `result[0][index]` and plot label from `result[1][index]`.
              `engine.state` and `batch_transform` inherit from the ignite concept:
              https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
              https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.
          output_transform: a callable that is used to extract the `predictions` data from
              `ignite.engine.state.output`, will use the result to plot output from `result[index]`.
              `engine.state` and `output_transform` inherit from the ignite concept:
              https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
              https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.
          global_iter_transform: a callable that is used to customize global step number for TensorBoard.
              For example, in evaluation, the evaluator engine needs to know current epoch from trainer.
          index: plot which element in a data batch, default is the first element.
          max_channels: number of channels to plot.
          frame_dim: if plotting 3D image as GIF, specify the dimension used as frames,
              expect input data shape as `NCHWD`, default to `-3` (the first spatial dim)
          max_frames: if plot 3D RGB image as video in TensorBoardX, set the FPS to `max_frames`.
      """
      super().__init__(summary_writer=summary_writer, log_dir=log_dir)
      self.interval = interval
      self.epoch_level = epoch_level
      self.batch_transform = batch_transform
      self.output_transform = output_transform
      self.global_iter_transform = global_iter_transform
      self.index = index
      self.frame_dim = frame_dim
      self.max_frames = max_frames
      self.max_channels = max_channels
  
imports: from __future__ import annotations
  import warnings
  from collections.abc import Callable, Sequence
  from typing import TYPE_CHECKING, Any
  import numpy
  import torch
  from monai.config import IgniteInfo
  from monai.utils import is_scalar, min_version, optional_import
  from monai.visualize import plot_2d_or_3d_image
label_desc: Use image node_id 1 to create a new TensorBoardImageHandler object from inherited base classes: TensorBoardHandler with example: obj = TensorBoardImageHandler(summary_writer, log_dir, interval, epoch_level, batch_transform, output_transform, global_iter_transform, index, max_channels, frame_dim, max_frames)