vision.pytorch.layers package#
Submodules#
vision.pytorch.layers.AdaLayerNorm module#
vision.pytorch.layers.BatchChannelNorm module#
- class vision.pytorch.layers.BatchChannelNorm.BatchChannelNorm2D[source]#
Bases:
torch.nn.Module
Implements Batch Channel Normalization proposed in Micro-Batch Training with Batch-Channel Normalization and Weight Standardization <https://arxiv.org/abs/1903.10520>
- Parameters
num_groups (int) – number of groups to separate the channels into.
num_channels (int) – number of channels. C from an expected input of size (N, C, H, W).
eps (float) – a value added to the denominator for numerical stability. Default: 1e-5.
momentum (float) – The Update rate value used for the running_mean and running_var computation. Default: 0.1.
device (torch.device) – Device to place the learnable parameters.
dtype (torch.dtype) – Data type of learnable parameters.
- Shape:
input: (N, C, H, W) output: (N, C, H, W) (same shape as input)
vision.pytorch.layers.ConvNormActBlock module#
- class vision.pytorch.layers.ConvNormActBlock.ConvNormActBlock[source]#
Bases:
torch.nn.Sequential
Customizable Convolution -> Normalization -> Activation Block.
:param (int) in_channels : Number of channels in the input image :param (int) out_channels: Number of channels produced by convolution :param (int or tuple) kernel_size : Size of the convolving kernel :param (int or tuple, optional) stride : Stride of the convolution.
Default: 1
- :param (str) paddingcontrols the amount of padding applied
to the input. Can be either valid or same.
- Parameters
dilation ((int or tuple, optional)) – Spacing between kernel elements. Default: 1
- :param (int, optional) groupsNumber of blocked connections from
input channels to output channels. Default: 1
- Parameters
bias ((bool, optional)) – If True, adds a learnable bias to the output. Default: False
padding_mode ((str, optional)) – ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’
norm_layer ((str, optional)) – Type of normalization to be used. Supported norm layers can be found in ./layers/normalizations.py. Default: batchnorm2d
norm_kwargs ((dict, optional)) –
args to be passed to norm layers during initialization. For norm_type = group,
norm_kwargs must include num_groups key value pair.
- norm_type = layer,
norm_kwargs must include normalized_shape key value pair.
weight_standardization ((bool, optional)) – If True standardize weights according to <https://arxiv.org/abs/1903.10520v2>.
act ((str, optional)) – Activation to be used. Supported activation layers can be found in ../../../common/pytorch/model_utils/activations.py. Default: relu
device ((str, optional)) – Device to place conv layer.
dtype ((torch.dtype, optional)) – Datatype to be used for weight and bias of convolution layer.
- __init__(in_channels, out_channels, kernel_size, stride=1, padding='valid', dilation=1, groups=1, bias=False, padding_mode='zeros', norm_layer='batchnorm2d', norm_kwargs=None, weight_standardization=False, act='relu', device=None, dtype=None, use_conv3d=False, affine=True)[source]#
:param (int) in_channels : Number of channels in the input image :param (int) out_channels: Number of channels produced by convolution :param (int or tuple) kernel_size : Size of the convolving kernel :param (int or tuple, optional) stride : Stride of the convolution.
Default: 1
- :param (str) paddingcontrols the amount of padding applied
to the input. Can be either valid or same.
- Parameters
dilation ((int or tuple, optional)) – Spacing between kernel elements. Default: 1
- :param (int, optional) groupsNumber of blocked connections from
input channels to output channels. Default: 1
- Parameters
bias ((bool, optional)) – If True, adds a learnable bias to the output. Default: False
padding_mode ((str, optional)) – ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’
norm_layer ((str, optional)) – Type of normalization to be used. Supported norm layers can be found in ./layers/normalizations.py. Default: batchnorm2d
norm_kwargs ((dict, optional)) –
args to be passed to norm layers during initialization. For norm_type = group,
norm_kwargs must include num_groups key value pair.
- norm_type = layer,
norm_kwargs must include normalized_shape key value pair.
weight_standardization ((bool, optional)) – If True standardize weights according to <https://arxiv.org/abs/1903.10520v2>.
act ((str, optional)) – Activation to be used. Supported activation layers can be found in ../../../common/pytorch/model_utils/activations.py. Default: relu
device ((str, optional)) – Device to place conv layer.
dtype ((torch.dtype, optional)) – Datatype to be used for weight and bias of convolution layer.
- class vision.pytorch.layers.ConvNormActBlock.ConvNormActBlockModule[source]#
Bases:
torch.nn.Module
Customizable Convolution -> Normalization -> Activation Block. with custom namespace flexibility with nn.Module
:param (int) in_channels : Number of channels in the input image :param (int) out_channels: Number of channels produced by convolution :param (int or tuple) kernel_size : Size of the convolving kernel :param (int or tuple, optional) stride : Stride of the convolution.
Default: 1
- :param (str) paddingcontrols the amount of padding applied
to the input. Can be either valid or same.
- Parameters
dilation ((int or tuple, optional)) – Spacing between kernel elements. Default: 1
- :param (int, optional) groupsNumber of blocked connections from
input channels to output channels. Default: 1
- Parameters
bias ((bool, optional)) – If True, adds a learnable bias to the output. Default: False
padding_mode ((str, optional)) – ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’
norm_layer ((str, optional)) – Type of normalization to be used. Supported norm layers can be found in ./layers/normalizations.py. Default: batchnorm2d
norm_kwargs ((dict, optional)) –
args to be passed to norm layers during initialization. For norm_type = group,
norm_kwargs must include num_groups key value pair.
- norm_type = layer,
norm_kwargs must include normalized_shape key value pair.
weight_standardization ((bool, optional)) – If True standardize weights according to <https://arxiv.org/abs/1903.10520v2>.
act ((str, optional)) – Activation to be used. Supported activation layers can be found in ../../../common/pytorch/model_utils/activations.py. Default: relu
device ((str, optional)) – Device to place conv layer.
dtype ((torch.dtype, optional)) – Datatype to be used for weight and bias of convolution layer.
custom_namespace ((List[str], optional)) – List of strings to control the namespace of the module
- __init__(in_channels, out_channels, kernel_size, stride=1, padding='valid', dilation=1, groups=1, bias=False, padding_mode='zeros', norm_layer='batchnorm2d', norm_kwargs=None, weight_standardization=False, act='relu', device=None, dtype=None, use_conv3d=False, affine=True, custom_namespace=None)[source]#
:param (int) in_channels : Number of channels in the input image :param (int) out_channels: Number of channels produced by convolution :param (int or tuple) kernel_size : Size of the convolving kernel :param (int or tuple, optional) stride : Stride of the convolution.
Default: 1
- :param (str) paddingcontrols the amount of padding applied
to the input. Can be either valid or same.
- Parameters
dilation ((int or tuple, optional)) – Spacing between kernel elements. Default: 1
- :param (int, optional) groupsNumber of blocked connections from
input channels to output channels. Default: 1
- Parameters
bias ((bool, optional)) – If True, adds a learnable bias to the output. Default: False
padding_mode ((str, optional)) – ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’
norm_layer ((str, optional)) – Type of normalization to be used. Supported norm layers can be found in ./layers/normalizations.py. Default: batchnorm2d
norm_kwargs ((dict, optional)) –
args to be passed to norm layers during initialization. For norm_type = group,
norm_kwargs must include num_groups key value pair.
- norm_type = layer,
norm_kwargs must include normalized_shape key value pair.
weight_standardization ((bool, optional)) – If True standardize weights according to <https://arxiv.org/abs/1903.10520v2>.
act ((str, optional)) – Activation to be used. Supported activation layers can be found in ../../../common/pytorch/model_utils/activations.py. Default: relu
device ((str, optional)) – Device to place conv layer.
dtype ((torch.dtype, optional)) – Datatype to be used for weight and bias of convolution layer.
custom_namespace ((List[str], optional)) – List of strings to control the namespace of the module
- class vision.pytorch.layers.ConvNormActBlock.ConvNormActLayers[source]#
Bases:
object
Customizable Convolution -> Normalization -> Activation Block. Returns list of layers in the above order when get_layers method is called.
:param (int) in_channels : Number of channels in the input image :param (int) out_channels: Number of channels produced by convolution :param (int or tuple) kernel_size : Size of the convolving kernel :param (int or tuple, optional) stride : Stride of the convolution.
Default: 1
- :param (str) paddingcontrols the amount of padding applied
to the input. Can be either valid or same.
- Parameters
dilation ((int or tuple, optional)) – Spacing between kernel elements. Default: 1
- :param (int, optional) groupsNumber of blocked connections from
input channels to output channels. Default: 1
- Parameters
bias ((bool, optional)) – If True, adds a learnable bias to the output. Default: False
padding_mode ((str, optional)) – ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’
norm_layer ((str, optional)) – Type of normalization to be used. Supported norm layers can be found in ./layers/normalizations.py. Default: batchnorm2d
norm_kwargs ((dict, optional)) –
args to be passed to norm layers during initialization. For norm_type = group,
norm_kwargs must include num_groups key value pair.
- norm_type = layer,
norm_kwargs must include normalized_shape key value pair.
weight_standardization ((bool, optional)) – If True standardize weights according to <https://arxiv.org/abs/1903.10520v2>.
act ((str, optional)) – Activation to be used. Supported activation layers can be found in ../../../common/pytorch/model_utils/activations.py. Default: relu
device ((str, optional)) – Device to place conv layer.
dtype ((torch.dtype, optional)) – Datatype to be used for weight and bias of convolution layer.
- __init__(in_channels, out_channels, kernel_size, stride=1, padding='valid', dilation=1, groups=1, bias=False, padding_mode='zeros', norm_layer='batchnorm2d', norm_kwargs=None, weight_standardization=False, act='relu', device=None, dtype=None, use_conv3d=False, affine=True)[source]#
:param (int) in_channels : Number of channels in the input image :param (int) out_channels: Number of channels produced by convolution :param (int or tuple) kernel_size : Size of the convolving kernel :param (int or tuple, optional) stride : Stride of the convolution.
Default: 1
- :param (str) paddingcontrols the amount of padding applied
to the input. Can be either valid or same.
- Parameters
dilation ((int or tuple, optional)) – Spacing between kernel elements. Default: 1
- :param (int, optional) groupsNumber of blocked connections from
input channels to output channels. Default: 1
- Parameters
bias ((bool, optional)) – If True, adds a learnable bias to the output. Default: False
padding_mode ((str, optional)) – ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’
norm_layer ((str, optional)) – Type of normalization to be used. Supported norm layers can be found in ./layers/normalizations.py. Default: batchnorm2d
norm_kwargs ((dict, optional)) –
args to be passed to norm layers during initialization. For norm_type = group,
norm_kwargs must include num_groups key value pair.
- norm_type = layer,
norm_kwargs must include normalized_shape key value pair.
weight_standardization ((bool, optional)) – If True standardize weights according to <https://arxiv.org/abs/1903.10520v2>.
act ((str, optional)) – Activation to be used. Supported activation layers can be found in ../../../common/pytorch/model_utils/activations.py. Default: relu
device ((str, optional)) – Device to place conv layer.
dtype ((torch.dtype, optional)) – Datatype to be used for weight and bias of convolution layer.
vision.pytorch.layers.GroupInstanceNorm module#
- class vision.pytorch.layers.GroupInstanceNorm.GroupInstanceNorm[source]#
Bases:
torch.nn.Module
Uses torch.nn.GroupNorm to emulate InstanceNorm by setting number of groups equal to the number of channels.
- Parameters
num_channels (int) – number of channels. C from an expected input of size (N, C, H, W).