monailabel.deepedit.handlers module¶
- class monailabel.deepedit.handlers.TensorBoard2DImageHandler(summary_writer=None, log_dir='./runs', tag_prefix='', interval=1, batch_transform=<function TensorBoard2DImageHandler.<lambda>>, output_transform=<function TensorBoard2DImageHandler.<lambda>>, batch_limit=1, device=None)[source]¶
Bases:
object
- class monailabel.deepedit.handlers.TensorBoardImageHandler(summary_writer=None, log_dir='./runs', interval=1, batch_transform=<function TensorBoardImageHandler.<lambda>>, output_transform=<function TensorBoardImageHandler.<lambda>>, global_iter_transform=<function TensorBoardImageHandler.<lambda>>, index=0, max_channels=1, max_frames=64)[source]¶
Bases:
object
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).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’sengine.state.batch
andengine.state.output
.- Default behavior:
Show y_pred as images (GIF for 3D) on TensorBoard when Event triggered,
Need to use
batch_transform
andoutput_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).
- Parameters
summary_writer (
Optional
[SummaryWriter
,None
]) – user can specify TensorBoard SummaryWriter, default to create a new writer.log_dir (
str
) – if using default SummaryWriter, write logs to this directory, default is ./runs.interval (
int
) – plot content from engine.state every N epochs or every N iterations, default is 1.batch_transform (
Callable
) – 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].output_transform (
Callable
) – 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].global_iter_transform (
Callable
) – 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 (
int
) – plot which element in a data batch, default is the first element.max_channels (
int
) – number of channels to plot.max_frames (
int
) – number of frames for 2D-t plot.
- __init__(summary_writer=None, log_dir='./runs', interval=1, batch_transform=<function TensorBoardImageHandler.<lambda>>, output_transform=<function TensorBoardImageHandler.<lambda>>, global_iter_transform=<function TensorBoardImageHandler.<lambda>>, index=0, max_channels=1, max_frames=64)[source]¶
- Parameters
summary_writer (
Optional
[SummaryWriter
,None
]) – user can specify TensorBoard SummaryWriter, default to create a new writer.log_dir (
str
) – if using default SummaryWriter, write logs to this directory, default is ./runs.interval (
int
) – plot content from engine.state every N epochs or every N iterations, default is 1.batch_transform (
Callable
) – 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].output_transform (
Callable
) – 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].global_iter_transform (
Callable
) – 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 (
int
) – plot which element in a data batch, default is the first element.max_channels (
int
) – number of channels to plot.max_frames (
int
) – number of frames for 2D-t plot.