Convolutional Layers#
Classes#
- class Conv(net_out, shapes, *, filters=None, layer=None, factor=None, groups=1, kernel=3, stride=1, padding=0, dropout=0, activation='ELU', norm=None, padding_mode=None, **kwargs)[source]#
Bases:
BaseSingleLayerConvolutional layer constructor.
Supports 1D, 2D, and 3D convolution.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- layers
Sequential Layers to loop through in the forward pass
- group
- Parameters:
- net_out
list[int] Shape of the network’s output, required only if layer contains factor
- shapes
Shapes Shape of the outputs from each layer
- filters
int|NoneType,Optional Number of convolutional filters, will be used if provided, else factor will be used
- layer
int|NoneType,Optional If factor is not None, which layer for factor to be relative to, if None, network output will be used
- factor
float|NoneType,Optional Number of convolutional filters equal to the output channels, or if layer is provided, the layer’s channels, multiplied by factor, won’t be used if filters is provided
- groups
int,Optional Number of input channel groups, each with its own convolutional filter(s), input and output channels must both be divisible by the number of groups, default = 1
- kernel
int|list[int],Optional Size of the kernel, default = 3
- stride
int|list[int],Optional Stride of the kernel, default = 1
- padding
int| {‘same’} |list[int],Optional Input padding, can an int, list of ints or ‘same’ where ‘same’ preserves the input shape, default = 0
- dropout
float,Optional Probability of dropout, default = 0
- activation
str|NoneType,Optional Which activation function to use from PyTorch, default = ‘ELU’
- norm{
NoneType, ‘batch’, ‘layer’} If batch or layer normalisation should be used
- padding_mode{
NoneType, ‘zeros’, ‘reflect’, ‘replicate’, ‘circular’} Padding mode to use from PyTorch, if None zero padding is used if version is >3.9.4 else replication padding is used
- **kwargs
Leftover parameters to pass to base layer for checking
- net_out
- class ConvDepth(net_out, shapes, *, filters=None, layer=None, factor=None, kernel=3, stride=1, padding=0, dropout=0, activation='ELU', norm=None, padding_mode=None, **kwargs)[source]#
Bases:
ConvConstructs a depthwise convolutional layer.
Supports 1D, 2D, and 3D convolution.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- layers
Sequential Layers to loop through in the forward pass
- group
- Parameters:
- net_out
list[int] Shape of the network’s output, required only if layer contains factor
- shapes
Shapes Shape of the outputs from each layer
- filters
int|NoneType,Optional Number of convolutional filters, will be used if provided, else factor will be used
- layer
int|NoneType,Optional If factor is not None, which layer for factor to be relative to, if None, network output will be used
- factor
float|NoneType,Optional Number of convolutional filters equal to the output channels multiplied by factor, won’t be used if filters is provided
- kernel
int|list[int],Optional Size of the kernel, default = 3
- stride
int|list[int],Optional Stride of the kernel, default = 1
- padding
int| {‘same’} |list[int],Optional Input padding, can an int, list of ints or ‘same’ where ‘same’ preserves the input shape, default = 0
- dropout
float,Optional Probability of dropout, default = 0
- activation
str|NoneType,Optional Which activation function to use, default = ‘ELU’
- norm{
NoneType, ‘batch’, ‘layer’} If batch or layer normalisation should be used
- padding_mode{
NoneType, ‘zeros’, ‘reflect’, ‘replicate’, ‘circular’} Padding mode to use from PyTorch, if None zero padding is used if version is >3.9.4 else replication padding is used
- **kwargs
Leftover parameters to pass to base layer for checking
- net_out
- class ConvDepthDownscale(net_out, shapes, *, dropout=0, activation='ELU', norm=None, padding_mode=None, **kwargs)[source]#
Bases:
ConvConstructs depth downscaler using convolution with kernel size of 1.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- layers
Sequential Layers to loop through in the forward pass
- group
- Parameters:
- net_out
list[int] Shape of the network’s output, required only if layer contains factor
- shapes: Shapes
Shape of the outputs from each layer
- dropout
float,Optional Probability of dropout, default = 0
- activation
str|NoneType,Optional Which activation function to use, default = ‘ELU’
- norm{
NoneType, ‘batch’, ‘layer’} If batch or layer normalisation should be used
- padding_mode{
NoneType, ‘zeros’, ‘reflect’, ‘replicate’, ‘circular’} Padding mode to use from PyTorch, if None zero padding is used if version is >3.9.4 else replication padding is used
- **kwargs
Leftover parameters to pass to base layer for checking
- net_out
- class ConvDownscale(net_out, shapes, *, filters=None, layer=None, factor=None, scale=2, dropout=0, activation='ELU', norm=None, **kwargs)[source]#
Bases:
ConvConstructs a strided convolutional layer for downscaling.
The scale factor is equal to the stride and kernel size.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- layers
Sequential Layers to loop through in the forward pass
- group
- Parameters:
- net_out
list[int] Shape of the network’s output, required only if layer contains factor
- shapes: Shapes
Shape of the outputs from each layer
- filters
int|NoneType,Optional Number of convolutional filters, will be used if provided, else factor will be used
- layer
int|NoneType,Optional If factor is not None, which layer for factor to be relative to, if None, network output will be used
- factor
float|NoneType,Optional Number of convolutional filters equal to the output channels multiplied by factor, won’t be used if filters is provided
- scale
int,Optional Stride and size of the kernel, which acts as the downscaling factor, default = 2
- dropout
float,Optional Probability of dropout, default = 0
- activation
str|NoneType,Optional Which activation function to use, default = ‘ELU’
- norm{
NoneType, ‘batch’, ‘layer’} If batch or layer normalisation should be used
- **kwargs
Leftover parameters to pass to base layer for checking
- net_out
- class ConvTranspose(net_out, shapes, *, filters=None, layer=None, factor=None, kernel=3, stride=1, out_padding=0, dilation=1, padding=0, dropout=0, padding_mode='zeros', activation='ELU', norm=None, **kwargs)[source]#
Bases:
BaseSingleLayerConstructs a transpose convolutional layer with fractional stride for input upscaling.
Supports 1D, 2D, and 3D transposed convolution.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- layers
Sequential Layers to loop through in the forward pass
- group
- Parameters:
- net_out
list[int] Shape of the network’s output, required only if layer contains factor
- shapes: Shapes
Shape of the outputs from each layer
- filters
int|NoneType,Optional Number of convolutional filters, will be used if provided, else factor will be used
- layer
int|NoneType,Optional If factor is not None, which layer for factor to be relative to, if None, network output will be used
- factor
float|NoneType,Optional Number of convolutional filters equal to the output channels multiplied by factor, won’t be used if filters is provided
- kernel
int|list[int],Optional Size of the kernel, default = 3
- stride
int|list[int],Optional Stride of the kernel, default = 1
- out_padding
int|list[int],Optional Padding applied to the output, default = 0
- dilation
int|list[int],Optional Spacing between kernel points, default = 1
- padding
int| {‘same’} |list[int],Optional Inverse of convolutional padding which removes rows from each dimension in the output, default = 0
- dropout
float,Optional Probability of dropout, default = 0
- padding_mode{‘zeros’, ‘reflect’, ‘replicate’, ‘circular’}
Padding mode to use from PyTorch
- activation
str|NoneType,Optional Which activation function to use, default = ‘ELU’
- norm{
NoneType, ‘batch’, ‘layer’} If batch or layer normalisation should be used
- **kwargs
Leftover parameters to pass to base layer for checking
- net_out
- class ConvTransposeUpscale(net_out, shapes, *, filters=None, layer=None, factor=None, scale=2, out_padding=0, dropout=0, activation='ELU', norm=None, **kwargs)[source]#
Bases:
ConvTransposeConstructs an upscaler using a transposed convolutional layer.
Supports 1D, 2D, and 3D transposed convolutional upscaling.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- layers
Sequential Layers to loop through in the forward pass
- group
- Parameters:
- net_out
list[int] Shape of the network’s output, required only if layer contains factor
- shapes: Shapes
Shape of the outputs from each layer
- filters
int|NoneType,Optional Number of convolutional filters, will be used if provided, else factor will be used
- layer
int|NoneType,Optional If factor is not None, which layer for factor to be relative to, if None, network output will be used
- factor
float|NoneType,Optional Number of convolutional filters equal to the output channels multiplied by factor, won’t be used if filters is provided
- scale
int|list[int],Optional Stride and size of the kernel, which acts as the upscaling factor, default = 2
- out_padding
int|list[int],Optional Padding applied to the output, default = 0
- dropout
float,Optional Probability of dropout, default = 0
- activation
str|NoneType,Optional Which activation function to use, default = ‘ELU’
- norm{
NoneType, ‘batch’, ‘layer’} If batch or layer normalisation should be used
- **kwargs
Leftover parameters to pass to base layer for checking
- net_out
- class ConvUpscale(net_out, shapes, *, filters=None, layer=None, factor=None, scale=2, kernel=3, dropout=0, activation='ELU', norm=None, padding_mode=None, **kwargs)[source]#
Bases:
ConvConstructs an upscaler using a convolutional layer and pixel shuffling.
Supports 1D, 2D, and 3D convolutional upscaling.
See Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network by Shi et al. (2016) for details.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- layers
Sequential Layers to loop through in the forward pass
- group
- Parameters:
- net_out
list[int] Shape of the network’s output, required only if layer contains factor
- shapes: Shapes
Shape of the outputs from each layer
- filters
int|NoneType,Optional Number of convolutional filters, will be used if provided, else factor will be used
- layer
int|NoneType,Optional If factor is not None, which layer for factor to be relative to, if None, network output will be used
- factor
float|NoneType,Optional Number of convolutional filters equal to the output channels multiplied by factor, won’t be used if filters is provided
- scale
int,Optional Factor to upscale the input by, default = 2
- kernel
int|list[int],Optional Size of the kernel, default = 3
- dropout
float,Optional Probability of dropout, default = 0
- activation
str|NoneType,Optional Which activation function to use, default = ‘ELU’
- norm{
NoneType, ‘batch’, ‘layer’} If batch or layer normalisation should be used
- padding_mode{
NoneType, ‘zeros’, ‘reflect’, ‘replicate’, ‘circular’} Padding mode to use from PyTorch, if None zero padding is used if version is >3.9.4 else replicate padding is used
- **kwargs
Leftover parameters to pass to base layer for checking
- net_out
- class PixelShuffle(scale, *, shapes=None, **kwargs)[source]#
Bases:
BaseLayerUsed for upscaling by scale factor \(r\) for an input \((N,C\times r^n,D_1,...,D_n)\) to an output \((N,C,D_1\times r,...,D_n\times r)\).
Equivalent to
torch.nn.PixelShuffle, but for nD.- Attributes:
- Parameters:
- scale
int Upscaling factor
- shapes: Shapes | None, Optional
Shape of the outputs from each layer
- **kwargs
Leftover parameters to pass to base layer for checking
- scale
- extra_repr()[source]#
Displays layer parameters when printing the network
- Returns:
strLayer parameters
- forward(x, *_, **__)[source]#
Forward pass of pixel shuffle
- Parameters:
- x
Tensor Input tensor with shape \((N,C\times r^n,D_1,...,D_n)\) and type float, where N is the batch size, C is the number of channels, r is the upscaling factor and \(D_n\) is the length of dimension n
- x
- Returns:
TensorOutput tensor with shape \((N,C,D_1\times r,...,D_n\times r)\) and type float