composer.algorithms.colout.colout#

Core ColOut classes and functions.

Functions

colout_batch

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

Classes

ColOut

Drops a fraction of the rows and columns of an input image.

ColOutTransform

Torchvision-like transform for performing the ColOut augmentation, where random rows and columns are dropped from a single image.

class composer.algorithms.colout.colout.ColOut(p_row=0.15, p_col=0.15, batch=True)[source]#

Bases: composer.core.algorithm.Algorithm

Drops a fraction of the rows and columns of an input 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), this algorithm runs on Event.INIT to insert a dataset transformation. It is a no-op if this algorithm already applied itself on the State.train_dataloader.dataset.

Otherwise, if batch is False, then this algorithm runs on Event.AFTER_DATALOADER to modify the batch.

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,
    train_dataloader=train_dataloader,
    eval_dataloader=eval_dataloader,
    max_duration="1ep",
    algorithms=[colout_algorithm],
    optimizers=[optimizer]
)
Parameters
  • p_row (float) โ€“ Fraction of rows to drop (drop along H). Default: 0.15.

  • p_col (float) โ€“ Fraction of columns to drop (drop along W). Default: 0.15.

  • batch (bool) โ€“ Run ColOut at the batch level. Default: True.

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

Torchvision-like transform for performing the ColOut augmentation, where random rows and columns are dropped from a single image.

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) โ€“ Fraction of rows to drop (drop along H). Default: 0.15.

  • p_col (float) โ€“ Fraction of columns to drop (drop along W). Default: 0.15.

composer.algorithms.colout.colout.colout_batch(input, p_row=0.15, p_col=0.15)[source]#

Applies ColOut augmentation to a batch of images, dropping the same random rows and columns from all images 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
  • input โ€“ PIL.Image.Image or torch.Tensor of image data. In the latter case, must be a single image of shape CHW or a batch of images of shape NCHW.

  • p_row โ€“ Fraction of rows to drop (drop along H). Default: 0.15.

  • p_col โ€“ Fraction of columns to drop (drop along W). Default: 0.15.

Returns

torch.Tensor โ€“ Input batch tensor with randomly dropped columns and rows.