# 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,
...     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.