composer.functional.apply_blurpool(model, replace_convs=True, replace_maxpools=True, blur_first=True, min_channels=16, optimizers=None)[source]#

Add anti-aliasing filters to strided torch.nn.Conv2d and/or torch.nn.MaxPool2d modules.

These filters increase invariance to small spatial shifts in the input (Zhang 2019).

  • model (torch.nn.Module) โ€“ the model to modify in-place

  • replace_convs (bool, optional) โ€“ replace strided torch.nn.Conv2d modules with BlurConv2d modules. Default: True.

  • replace_maxpools (bool, optional) โ€“ replace eligible torch.nn.MaxPool2d modules with BlurMaxPool2d modules. Default: True.

  • blur_first (bool, optional) โ€“ for replace_convs, blur input before the associated convolution. When set to False, the convolution is applied with a stride of 1 before the blurring, resulting in significant overhead (though more closely matching the paper). See BlurConv2d for further discussion. Default: True.

  • min_channels (int, optional) โ€“ Skip replacing layers with in_channels < min_channels. Commonly used to prevent the blurring of the first layer. Default: 16.

  • optimizers (Optimizer | Sequence[Optimizer], optional) โ€“

    Existing optimizers bound to model.parameters(). All optimizers that have already been constructed with model.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.


The modified model


import composer.functional as cf
from torchvision import models
model = models.resnet50()