# composer.algorithms.colout.colout#

Core ColOut classes and functions.

Functions

 colout_batch Applies ColOut augmentation to a batch of images and (optionally) targets, dropping the same random rows and columns from all images and targets in a batch.

Classes

 ColOut Drops a fraction of the rows and columns of an input image and (optionally) a target image. ColOutTransform Torchvision-like transform for performing the ColOut augmentation, where random rows and columns are dropped from up to two Torch tensors or two PIL images.
class composer.algorithms.colout.colout.ColOut(p_row=0.15, p_col=0.15, batch=True, resize_target='auto', input_key=0, target_key=1)[source]#

Drops a fraction of the rows and columns of an input image and (optionally) a target image. If the fraction of rows/columns dropped isn’t too large, this does not significantly alter the content of the image, but reduces its size and provides extra variability.

If batch is True (the default), then this algorithm runs on AFTER_DATALOADER to modify the batch.

Otherwise, if batch=False (the default), this algorithm runs on INIT to insert a dataset transformation. It is a no-op if this algorithm already applied itself on the State.train_dataloader.dataset.

See the Method Card for more details.

Example

from composer.algorithms import ColOut
from composer.trainer import Trainer
colout_algorithm = ColOut(p_row=0.15, p_col=0.15, batch=True)
trainer = Trainer(
model=model,
max_duration="1ep",
algorithms=[colout_algorithm],
optimizers=[optimizer]
)

Parameters
• p_row (float, optional) – Fraction of rows to drop (drop along H). Default: 0.15.

• p_col (float, optional) – Fraction of columns to drop (drop along W). Default: 0.15.

• batch (bool, optional) – Run ColOut at the batch level. Default: True.

• resize_target (bool | str, optional) – Whether to resize the target in addition to the input. If set to 'auto', resizing the target will be based on if the target has the same spatial dimensions as the input. Default: auto.

• 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.

class composer.algorithms.colout.colout.ColOutTransform(p_row=0.15, p_col=0.15, resize_target='auto')[source]#

Torchvision-like transform for performing the ColOut augmentation, where random rows and columns are dropped from up to two Torch tensors or two PIL images.

See the Method Card for more details.

Example

from torchvision import datasets, transforms
from composer.algorithms.colout import ColOutTransform
colout_transform = ColOutTransform(p_row=0.15, p_col=0.15)
transforms = transforms.Compose([colout_transform, transforms.ToTensor()])

Parameters
• p_row (float, optional) – Fraction of rows to drop (drop along H). Default: 0.15.

• p_col (float, optional) – Fraction of columns to drop (drop along W). Default: 0.15.

• resize_target (bool | str, optional) – Whether to resize the target in addition to the input. If set to 'auto', resizing the target will be based on if the target has the same spatial dimensions as the input. Default: 'auto'.

composer.algorithms.colout.colout.colout_batch(sample, p_row=0.15, p_col=0.15, resize_target='auto')[source]#

Applies ColOut augmentation to a batch of images and (optionally) targets, dropping the same random rows and columns from all images and targets in a batch.

See the Method Card for more details.

Example

from composer.algorithms.colout import colout_batch
new_X = colout_batch(X_example, p_row=0.15, p_col=0.15)

Parameters
• sample (Tensor | PIL.Image | Tuple[Tensor, Tensor] | Tuple[PIL.Image, PIL.Image]) – Either a single tensor or image or a 2-tuple of tensors or images. When tensor(s), the tensor must be of shape CHW for a single image or NCHW for a batch of images of shape.

• p_row (float, optional) – Fraction of rows to drop (drop along H). Default: 0.15.

• p_col (float, optional) – Fraction of columns to drop (drop along W). Default: 0.15.

• resize_target (bool | str, optional) – If sample is a tuple, whether to resize both objects in the tuple. If set to 'auto', both objects will be resized if they have the same spatial dimensions. Otherwise, only the first object is resized. Default: 'auto'.

Returns

torch.Tensor | PIL.Image | Tuple[torch.Tensor, torch.Tensor] | Tuple[PIL.Image, PIL.Image] – A smaller image or 2-tuple of images with random rows and columns dropped.