composer.algorithms.cutout.cutout#
Core CutOut classes and functions.
Functions
See |
Classes
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 ofmin(H, W)
and converted toint(length * min(H, W))
. Iflength >= 1
,length
is used as an integer size directly.
- 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
ortorch.Tensor
of image data. In the latter case, must be a single image of shapeCHW
or a batch of images of shapeNCHW
.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 ofmin(H, W)
and converted toint(length * min(H, W))
. Iflength >= 1
,length
is used as an integer size directly.
- Returns
X_cutout โ Batch of images with
n_holes
holes of dimensionlength x length
replaced with zeros.