composer.algorithms.blurpool.blurpool#
composer.algorithms.blurpool.blurpool
Functions
Add anti-aliasing filters to the strided |
Classes
Base class for algorithms. |
|
This module is a drop-in replacement for PyTorch's |
|
This module is a (nearly) drop-in replacement for PyTorch's |
|
BlurPool adds anti-aliasing filters to convolutional layers to increase accuracy and invariance to small shifts in the input. |
|
Enum to represent events in the training loop. |
|
An interface to record training data. |
|
|
Base class for all optimizers. |
The state of the trainer. |
Exceptions
Warns when an algorithm did not have an effect. |
Attributes
Optional
Sequence
Union
annotations
log
- class composer.algorithms.blurpool.blurpool.BlurPool(replace_convs=True, replace_maxpools=True, blur_first=True)[source]#
Bases:
composer.core.algorithm.Algorithm
BlurPool adds anti-aliasing filters to convolutional layers to increase accuracy and invariance to small shifts in the input.
Runs on
INIT
.- Parameters
replace_convs (bool) โ replace strided
torch.nn.Conv2d
modules withBlurConv2d
modules. Default:True
.replace_maxpools (bool) โ replace eligible
torch.nn.MaxPool2d
modules withBlurMaxPool2d
modules. Default:True
.blur_first (bool) โ when
replace_convs
isTrue
, blur input before the associated convolution. When set toFalse
, the convolution is applied with a stride of 1 before the blurring, resulting in significant overhead (though more closely matching the paper). SeeBlurConv2d
for further discussion. Default:True
.
- composer.algorithms.blurpool.blurpool.apply_blurpool(model, replace_convs=True, replace_maxpools=True, blur_first=True, optimizers=None)[source]#
Add anti-aliasing filters to the strided
torch.nn.Conv2d
and/ortorch.nn.MaxPool2d
modules within model.These filters increase invariance to small spatial shifts in the input (Zhang 2019).
- Parameters
model (Module) โ the model to modify in-place
replace_convs (bool, optional) โ replace strided
torch.nn.Conv2d
modules withBlurConv2d
modules. Default:True
.replace_maxpools (bool, optional) โ replace eligible
torch.nn.MaxPool2d
modules withBlurMaxPool2d
modules. Default:True
.blur_first (bool, optional) โ for
replace_convs
, blur input before the associated convolution. When set toFalse
, the convolution is applied with a stride of 1 before the blurring, resulting in significant overhead (though more closely matching the paper). SeeBlurConv2d
for further discussion. Default:True
.optimizers (Optimizer | Sequence[Optimizer], optional) โ
Existing optimizers bound to
model.parameters()
. All optimizers that have already been constructed withmodel.parameters()
must be specified here so they will optimize the correct parameters.If the optimizer(s) are constructed after calling this function, then it is safe to omit this parameter. These optimizers will see the correct model parameters.
- Returns
The modified model
Example
import composer.functional as cf from torchvision import models model = models.resnet50() cf.apply_blurpool(model)