ImageVisualizer#

class composer.callbacks.ImageVisualizer(interval='100ba', mode='input', num_images=8, channels_last=False, input_key=0, target_key=1)[source]#

Logs image inputs and optionally outputs.

This callback triggers at a user defined interval, and logs a sample of input (optionally also segmentation masks) images under the Images/Train and Image/Eval keys.

Example

>>> from composer import Trainer
>>> from composer.callbacks import ImageVisualizer
>>> # constructing trainer object with this callback
>>> trainer = Trainer(
...     model=model,
...     train_dataloader=train_dataloader,
...     eval_dataloader=eval_dataloader,
...     optimizers=optimizer,
...     max_duration="1ep",
...     callbacks=[ImageVisualizer()],
... )

The images are logged by the Logger to the following key(s) as described below.

Key

Logged data

Images/Train

Sampled examples of train images

Images/Eval

Sampled examples of eval images

Note

This callback only works with wandb logging for now.

Parameters
  • interval (str | Time, optional) โ€“ Time string specifying how often to log train images. For example, interval='1ep' means images are logged once every epoch, while interval='100ba' means images are logged once every 100 batches. Eval images are logged once at the start of each eval. Default: "100ba".

  • mode (str, optional) โ€“ How to log the image labels. Valid values are "input" (input only) and โ€œsegmentationโ€ which also saves segmentation masks. Default: "input".

  • num_images (int, optional) โ€“ Number of images to log. Should be less than or equal to than the microbatch size. If there are not enough images in the microbatch, all the images in the microbatch will be logged. Default: 8.

  • channels_last (bool, optional) โ€“ Whether the image channel dimension is the last dimension. Default: False.

  • input_key (str | int | Tuple[Callable, Callable] | Any, optional) โ€“ A key that indexes to the input from the batch. Can also be a pair of get and set functions, where the getter is assumed to be first in the pair. The default is 0, which corresponds to any sequence, where the first element is the input. Default: 0.

  • target_key (str | int | Tuple[Callable, Callable] | Any, optional) โ€“ A key that indexes to the target from the batch. Can also be a pair of get and set functions, where the getter is assumed to be first in the pair. The default is 1, which corresponds to any sequence, where the second element is the target. Default: 1.