composer.algorithms.cutout.cutout#

Core CutOut classes and functions.

Functions

Classes

CutOut

Cutout is a data augmentation technique that works by masking out one or more square regions of an input image.

class composer.algorithms.cutout.cutout.CutOut(n_holes=1, length=0.5)[source]#

Bases: composer.core.algorithm.Algorithm

Cutout is a data augmentation technique that works by masking out one or more square regions of an input image.

This implementation cuts out the same square from all images in a batch.

Example

from composer.algorithms import CutOut
from composer.trainer import Trainer
cutout_algorithm = CutOut(n_holes=1, length=0.25)
trainer = Trainer(
    model=model,
    train_dataloader=train_dataloader,
    eval_dataloader=eval_dataloader,
    max_duration="1ep",
    algorithms=[cutout_algorithm],
    optimizers=[optimizer]
)
Parameters
  • X (Tensor) โ€“ Batch Tensor image of size (B, C, H, W).

  • n_holes โ€“ Integer number of holes to cut out

  • length โ€“ Side length of the square holes to cut out. Must be greater than 0. If 0 < length < 1, length is interpreted as a fraction of min(H, W) and converted to int(length * min(H, W)). If length >= 1, length is used as an integer size directly.

apply(event, state, logger)[source]#

Apply cutout on input images.

match(event, state)[source]#

Runs on Event.AFTER_DATALOADER.

composer.algorithms.cutout.cutout.cutout_batch(X, n_holes=1, length=0.5)[source]#

See CutOut.

Example

from composer.algorithms.cutout import cutout_batch
new_input_batch = cutout_batch(
    X=X_example,
    n_holes=1,
    length=16
)
Parameters
  • X โ€“ 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.

  • n_holes โ€“ Integer number of holes to cut out

  • length โ€“ Side length of the square holes to cut out. Must be greater than 0. If 0 < length < 1, length is interpreted as a fraction of min(H, W) and converted to int(length * min(H, W)). If length >= 1, length is used as an integer size directly.

Returns

X_cutout โ€“ Batch of images with n_holes holes of dimension length x length replaced with zeros.