# 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(num_holes=1, length=0.5, uniform_sampling=False)[source]#

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(num_holes=1, length=0.25)
trainer = Trainer(
model=model,
max_duration="1ep",
algorithms=[cutout_algorithm],
optimizers=[optimizer]
)

Parameters
• num_holes (int, optional) – Integer number of holes to cut out. Default: 1.

• length (float, optional) – Relative side length of the masked region. If specified, length is interpreted as a fraction of H and W, and the resulting box is a square with side length length * min(H, W). Must be in the interval $$(0, 1)$$. Default: 0.5.

• uniform_sampling (bool, optional) – If True, sample the bounding box such that each pixel has an equal probability of being masked. If False, defaults to the sampling used in the original paper implementation. Default: False.

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

Apply cutout on input images.

match(event, state)[source]#

composer.algorithms.cutout.cutout.cutout_batch(input, num_holes=1, length=0.5, uniform_sampling=False)[source]#

See CutOut.

Parameters
• input (PIL.Image.Image | torch.Tensor) – Image or batch of images. If a torch.Tensor, must be a single image of shape (C, H, W) or a batch of images of shape (N, C, H, W).

• num_holes – Integer number of holes to cut out. Default: 1.

• length (float, optional) – Relative side length of the masked region. If specified, length is interpreted as a fraction of H and W, and the resulting box is a square with side length length * min(H, W). Must be in the interval $$(0, 1)$$. Default: 0.5.

• uniform_sampling (bool, optional) – If True, sample the bounding box such that each pixel has an equal probability of being masked. If False, defaults to the sampling used in the original paper implementation. Default: False.

Returns

X_cutout – Batch of images with num_holes square holes with dimension determined by length replaced with zeros.

Example

from composer.algorithms.cutout import cutout_batch
new_input_batch = cutout_batch(X_example, num_holes=1, length=0.25)