class_docstr: TensorBoardStatsHandler defines a set of Ignite Event-handlers for all the TensorBoard logics.
  It can be used for any Ignite Engine(trainer, validator and evaluator).
  And it can support both epoch level and iteration level with pre-defined TensorBoard event writer.
  The expected data source is Ignite ``engine.state.output`` and ``engine.state.metrics``.
  
  Default behaviors:
      - When EPOCH_COMPLETED, write each dictionary item in
        ``engine.state.metrics`` to TensorBoard.
      - When ITERATION_COMPLETED, write each dictionary item in
        ``self.output_transform(engine.state.output)`` to TensorBoard.
  
  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: ["TensorBoardStatsHandler","defines","a","set","of","Ignite","Event-handlers","for","all","the","TensorBoard","logics",".","It","can","be","used","for","any","Ignite","Engine","(","trainer",",","validator","and","evaluator",")",".","And","it","can","support","both","epoch","level","and","iteration","level","with","pre-defined","TensorBoard","event","writer",".","The","expected","data","source","is","Ignite","``","engine.state.output","``","and","``","engine.state.metrics","``",".","Default","behaviors",":","-","When","EPOCH_COMPLETED",",","write","each","dictionary","item","in","``","engine.state.metrics","``","to","TensorBoard",".","-","When","ITERATION_COMPLETED",",","write","each","dictionary","item","in","``","self.output_transform","(","engine.state.output",")","``","to","TensorBoard",".","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`.
      iteration_log: whether to write data to TensorBoard when iteration completed, default to `True`.
          ``iteration_log`` can be also a function or int. If it is an int, it will be interpreted as the iteration interval
          at which the iteration_event_writer is called. If it is a function, it will be interpreted as an event filter
          (see https://pytorch.org/ignite/generated/ignite.engine.events.Events.html for details).
          Event filter function accepts as input engine and event value (iteration) and should return True/False.
      epoch_log: whether to write data to TensorBoard when epoch completed, default to `True`.
          ``epoch_log`` can be also a function or int. If it is an int, it will be interpreted as the epoch interval
          at which the epoch_event_writer is called. If it is a function, it will be interpreted as an event filter.
          See ``iteration_log`` argument for more details.
      epoch_event_writer: customized callable TensorBoard writer for epoch level.
          Must accept parameter "engine" and "summary_writer", use default event writer if None.
      iteration_event_writer: customized callable TensorBoard writer for iteration level.
          Must accept parameter "engine" and "summary_writer", use default event writer if None.
      output_transform: a callable that is used to transform the
          ``ignite.engine.state.output`` into a scalar to plot, or a dictionary of {key: scalar}.
          In the latter case, the output string will be formatted as key: value.
          By default this value plotting happens when every iteration completed.
          The default behavior is to print loss from output[0] as output is a decollated list
          and we replicated loss value for every item of the decollated list.
          `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_epoch_transform: a callable that is used to customize global epoch number.
          For example, in evaluation, the evaluator engine might want to use trainer engines epoch number
          when plotting epoch vs metric curves.
      state_attributes: expected attributes from `engine.state`, if provided, will extract them
          when epoch completed.
      tag_name: when iteration output is a scalar, tag_name is used to plot, defaults to ``'Loss'``.
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","`",".","iteration_log",":","whether","to","write","data","to","TensorBoard","when","iteration","completed",",","default","to","`","True","`",".","``","iteration_log","``","can","be","also","a","function","or","int",".","If","it","is","an","int",",","it","will","be","interpreted","as","the","iteration","interval","at","which","the","iteration_event_writer","is","called",".","If","it","is","a","function",",","it","will","be","interpreted","as","an","event","filter","(","see","https",":","\/\/pytorch.org\/ignite\/generated\/ignite.engine.events.Events.html","for","details",")",".","Event","filter","function","accepts","as","input","engine","and","event","value","(","iteration",")","and","should","return","True\/False",".","epoch_log",":","whether","to","write","data","to","TensorBoard","when","epoch","completed",",","default","to","`","True","`",".","``","epoch_log","``","can","be","also","a","function","or","int",".","If","it","is","an","int",",","it","will","be","interpreted","as","the","epoch","interval","at","which","the","epoch_event_writer","is","called",".","If","it","is","a","function",",","it","will","be","interpreted","as","an","event","filter",".","See","``","iteration_log","``","argument","for","more","details",".","epoch_event_writer",":","customized","callable","TensorBoard","writer","for","epoch","level",".","Must","accept","parameter","``","engine","''","and","``","summary_writer","''",",","use","default","event","writer","if","None",".","iteration_event_writer",":","customized","callable","TensorBoard","writer","for","iteration","level",".","Must","accept","parameter","``","engine","''","and","``","summary_writer","''",",","use","default","event","writer","if","None",".","output_transform",":","a","callable","that","is","used","to","transform","the","``","ignite.engine.state.output","``","into","a","scalar","to","plot",",","or","a","dictionary","of","{","key",":","scalar","}",".","In","the","latter","case",",","the","output","string","will","be","formatted","as","key",":","value",".","By","default","this","value","plotting","happens","when","every","iteration","completed",".","The","default","behavior","is","to","print","loss","from","output","[","0","]","as","output","is","a","decollated","list","and","we","replicated","loss","value","for","every","item","of","the","decollated","list",".","`","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_epoch_transform",":","a","callable","that","is","used","to","customize","global","epoch","number",".","For","example",",","in","evaluation",",","the","evaluator","engine","might","want","to","use","trainer","engines","epoch","number","when","plotting","epoch","vs","metric","curves",".","state_attributes",":","expected","attributes","from","`","engine.state","`",",","if","provided",",","will","extract","them","when","epoch","completed",".","tag_name",":","when","iteration","output","is","a","scalar",",","tag_name","is","used","to","plot",",","defaults","to","``","'Loss","'","``","."]
code: def __init__(
      self,
      summary_writer: SummaryWriter | SummaryWriterX | None = None,
      log_dir: str = "./runs",
      iteration_log: bool | Callable[[Engine, int], bool] | int = True,
      epoch_log: bool | Callable[[Engine, int], bool] | int = True,
      epoch_event_writer: Callable[[Engine, Any], Any] | None = None,
      iteration_event_writer: Callable[[Engine, Any], Any]
      | None = None,
      output_transform: Callable = lambda x: x[0],
      global_epoch_transform: Callable = lambda x: x,
      state_attributes: Sequence[str] | None = None,
      tag_name: str = DEFAULT_TAG,
  ) -> 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`.
          iteration_log: whether to write data to TensorBoard when iteration completed, default to `True`.
              ``iteration_log`` can be also a function or int. If it is an int, it will be interpreted as the iteration interval
              at which the iteration_event_writer is called. If it is a function, it will be interpreted as an event filter
              (see https://pytorch.org/ignite/generated/ignite.engine.events.Events.html for details).
              Event filter function accepts as input engine and event value (iteration) and should return True/False.
          epoch_log: whether to write data to TensorBoard when epoch completed, default to `True`.
              ``epoch_log`` can be also a function or int. If it is an int, it will be interpreted as the epoch interval
              at which the epoch_event_writer is called. If it is a function, it will be interpreted as an event filter.
              See ``iteration_log`` argument for more details.
          epoch_event_writer: customized callable TensorBoard writer for epoch level.
              Must accept parameter "engine" and "summary_writer", use default event writer if None.
          iteration_event_writer: customized callable TensorBoard writer for iteration level.
              Must accept parameter "engine" and "summary_writer", use default event writer if None.
          output_transform: a callable that is used to transform the
              ``ignite.engine.state.output`` into a scalar to plot, or a dictionary of {key: scalar}.
              In the latter case, the output string will be formatted as key: value.
              By default this value plotting happens when every iteration completed.
              The default behavior is to print loss from output[0] as output is a decollated list
              and we replicated loss value for every item of the decollated list.
              `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_epoch_transform: a callable that is used to customize global epoch number.
              For example, in evaluation, the evaluator engine might want to use trainer engines epoch number
              when plotting epoch vs metric curves.
          state_attributes: expected attributes from `engine.state`, if provided, will extract them
              when epoch completed.
          tag_name: when iteration output is a scalar, tag_name is used to plot, defaults to ``'Loss'``.
      """
  
      super().__init__(summary_writer=summary_writer, log_dir=log_dir)
      self.iteration_log = iteration_log
      self.epoch_log = epoch_log
      self.epoch_event_writer = epoch_event_writer
      self.iteration_event_writer = iteration_event_writer
      self.output_transform = output_transform
      self.global_epoch_transform = global_epoch_transform
      self.state_attributes = state_attributes
      self.tag_name = tag_name
  
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 TensorBoardStatsHandler object from inherited base classes: TensorBoardHandler with example: obj = TensorBoardStatsHandler(summary_writer, log_dir, iteration_log, epoch_log, epoch_event_writer, iteration_event_writer, output_transform, global_epoch_transform, state_attributes, tag_name)