MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / TensorBoardStatsHandler

Class TensorBoardStatsHandler

monai/handlers/tensorboard_handlers.py:71–285  ·  view source on GitHub ↗

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 from the content-addressed store, hash-verified

69
70
71class TensorBoardStatsHandler(TensorBoardHandler):
72 """
73 TensorBoardStatsHandler defines a set of Ignite Event-handlers for all the TensorBoard logics.
74 It can be used for any Ignite Engine(trainer, validator and evaluator).
75 And it can support both epoch level and iteration level with pre-defined TensorBoard event writer.
76 The expected data source is Ignite ``engine.state.output`` and ``engine.state.metrics``.
77
78 Default behaviors:
79 - When EPOCH_COMPLETED, write each dictionary item in
80 ``engine.state.metrics`` to TensorBoard.
81 - When ITERATION_COMPLETED, write each dictionary item in
82 ``self.output_transform(engine.state.output)`` to TensorBoard.
83
84 Usage example is available in the tutorial:
85 https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/unet_segmentation_3d_ignite.ipynb.
86
87 """
88
89 def __init__(
90 self,
91 summary_writer: SummaryWriter | SummaryWriterX | None = None,
92 log_dir: str = "./runs",
93 iteration_log: bool | Callable[[Engine, int], bool] | int = True,
94 epoch_log: bool | Callable[[Engine, int], bool] | int = True,
95 epoch_event_writer: Callable[[Engine, Any], Any] | None = None,
96 iteration_event_writer: Callable[[Engine, Any], Any] | None = None,
97 output_transform: Callable = lambda x: x[0],
98 global_epoch_transform: Callable = lambda x: x,
99 state_attributes: Sequence[str] | None = None,
100 tag_name: str = DEFAULT_TAG,
101 ) -> None:
102 """
103 Args:
104 summary_writer: user can specify TensorBoard or TensorBoardX SummaryWriter,
105 default to create a new TensorBoard writer.
106 log_dir: if using default SummaryWriter, write logs to this directory, default is `./runs`.
107 iteration_log: whether to write data to TensorBoard when iteration completed, default to `True`.
108 ``iteration_log`` can be also a function or int. If it is an int, it will be interpreted as the iteration interval
109 at which the iteration_event_writer is called. If it is a function, it will be interpreted as an event filter
110 (see https://pytorch.org/ignite/generated/ignite.engine.events.Events.html for details).
111 Event filter function accepts as input engine and event value (iteration) and should return True/False.
112 epoch_log: whether to write data to TensorBoard when epoch completed, default to `True`.
113 ``epoch_log`` can be also a function or int. If it is an int, it will be interpreted as the epoch interval
114 at which the epoch_event_writer is called. If it is a function, it will be interpreted as an event filter.
115 See ``iteration_log`` argument for more details.
116 epoch_event_writer: customized callable TensorBoard writer for epoch level.
117 Must accept parameter "engine" and "summary_writer", use default event writer if None.
118 iteration_event_writer: customized callable TensorBoard writer for iteration level.
119 Must accept parameter "engine" and "summary_writer", use default event writer if None.
120 output_transform: a callable that is used to transform the
121 ``ignite.engine.state.output`` into a scalar to plot, or a dictionary of {key: scalar}.
122 In the latter case, the output string will be formatted as key: value.
123 By default this value plotting happens when every iteration completed.
124 The default behavior is to print loss from output[0] as output is a decollated list
125 and we replicated loss value for every item of the decollated list.
126 `engine.state` and `output_transform` inherit from the ignite concept:
127 https://pytorch.org/ignite/concepts.html#state, explanation and usage example are in the tutorial:
128 https://github.com/Project-MONAI/tutorials/blob/master/modules/batch_output_transform.ipynb.

Callers 7

run_training_testFunction · 0.90
run_training_testFunction · 0.90
run_training_testFunction · 0.90
test_metrics_printMethod · 0.90
test_metrics_writerMethod · 0.90

Calls

no outgoing calls

Tested by 7

run_training_testFunction · 0.72
run_training_testFunction · 0.72
run_training_testFunction · 0.72
test_metrics_printMethod · 0.72
test_metrics_writerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…