ProgressiveResizing#

class composer.algorithms.ProgressiveResizing(mode='resize', initial_scale=0.5, finetune_fraction=0.2, delay_fraction=0.5, size_increment=4, resize_targets=False, input_key=0, target_key=1)[source]#

Resize inputs and optionally outputs by cropping or interpolating.

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,
                                    delay_fraction=0.2,
                                    size_increment=32,
                                    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.

  • delay_fraction (float, optional) โ€“ Fraction of training before resizing ramp begins. Must be a value in between 0 and 1. Default: 0.5.

  • size_increment (int, optional) โ€“ Align sizes to a multiple of this number. Default: 4.

  • resize_targets (bool, optional) โ€“ If True, resize targets also. Default: False.

  • input_key (str | int | Tuple[Callable, Callable] | Any, optional) โ€“ A key that indexes to the input from the batch. Can also be a pair of get and set functions, where the getter is assumed to be first in the pair. The default is 0, which corresponds to any sequence, where the first element is the input. Default: 0.

  • target_key (str | int | Tuple[Callable, Callable] | Any, optional) โ€“ A key that indexes to the target from the batch. Can also be a pair of get and set functions, where the getter is assumed to be first in the pair. The default is 1, which corresponds to any sequence, where the second element is the target. Default: 1.