composer.algorithms.progressive_resizing.progressive_resizing#
Core Progressive Resizing classes and functions.
Functions
Resize inputs and optionally outputs by cropping or interpolating. |
Classes
Apply Fastai's progressive resizing data augmentation to speed up training. |
- class composer.algorithms.progressive_resizing.progressive_resizing.ProgressiveResizing(mode='resize', initial_scale=0.5, finetune_fraction=0.2, resize_targets=False)[source]#
Bases:
composer.core.algorithm.Algorithm
Apply Fastaiโs progressive resizing data augmentation to speed up training.
Progressive resizing initially reduces input resolution to speed up early training. Throughout training, the downsampling factor is gradually increased, yielding larger inputs up to the original input size. A final finetuning period is then run to finetune the model using the full-sized inputs.
Example
from composer.algorithms import ProgressiveResizing from composer.trainer import Trainer progressive_resizing_algorithm = ProgressiveResizing( mode='resize', initial_scale=1.0, finetune_fraction=0.2, resize_targets=False ) trainer = Trainer( model=model, train_dataloader=train_dataloader, eval_dataloader=eval_dataloader, max_duration="1ep", algorithms=[progressive_resizing_algorithm], optimizers=[optimizer] )
- Parameters
mode (str, optional) โ Type of scaling to perform. Value must be one of
'crop'
or'resize'
.'crop'
performs a random crop, whereas'resize'
performs a bilinear interpolation. Default:"resize"
.initial_scale (float, optional) โ Initial scale factor used to shrink the inputs. Must be a value in between 0 and 1. Default:
0.5
.finetune_fraction (float, optional) โ Fraction of training to reserve for finetuning on the full-sized inputs. Must be a value in between 0 and 1. Default:
0.2
.resize_targets (bool, optional) โ If True, resize targets also. Default:
False
.
- composer.algorithms.progressive_resizing.progressive_resizing.resize_batch(input, target, scale_factor, mode='resize', resize_targets=False)[source]#
Resize inputs and optionally outputs by cropping or interpolating.
- Parameters
input (Tensor) โ input tensor of shape
(N, C, H, W)
. Resizing will be done along dimensions H and W using the constant factorscale_factor
.target (Tensor) โ output tensor of shape
(N, H, W)
or(N, C, H, W)
that will also be resized ifresize_targets
isTrue
,scale_factor (float) โ scaling coefficient for the height and width of the input/output tensor. 1.0 keeps the original size.
mode (str, optional) โ type of scaling to perform. Value must be one of
'crop'
or'resize'
.'crop'
performs a random crop, whereas'resize'
performs a nearest neighbor interpolation. Default:"resize"
.resize_targets (bool, optional) โ whether to resize the targets,
y
. Default:False
.
- Returns
X_sized โ resized input tensor of shape
(N, C, H * scale_factor, W * scale_factor)
.y_sized โ if
resized_targets
isTrue
, resized output tensor of shape(N, H * scale_factor, W * scale_factor)
or(N, C, H * scale_factor, W * scale_factor)
. Depending on the inputy
. Otherwise returns originaly
.
Example
from composer.algorithms.progressive_resizing import resize_batch X_resized, y_resized = resize_batch(X_example, y_example, scale_factor=0.5, mode='resize', resize_targets=False)