fusionlab.layers.factories module#
- class fusionlab.layers.factories.AdaptiveAvgPool(spatial_dims: int, output_size: int | Sequence[int])[source]#
Bases:
objectFactory class for creating adaptive average pooling layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
output_size – the target output size of the image of the form H x W. Can be a tuple (H, W) or a single H for a square image H x H. H and W can be either a
int, orNonewhich means the size will be the same as that of the input.
- class fusionlab.layers.factories.AdaptiveMaxPool(spatial_dims: int, output_size: int | Sequence[int], return_indices: bool = False)[source]#
Bases:
objectFactory class for creating adaptive max pooling layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
output_size – the target output size \(L_{out}\).
return_indices – if
True, will return the indices along with the outputs. Useful to pass to nn.MaxUnpool1d. Default:False
- class fusionlab.layers.factories.AvgPool(spatial_dims: int, kernel_size: int | Sequence[int], stride: int | Sequence[int] | None = None, padding: int | Sequence[int] = 0, ceil_mode: bool = False, count_include_pad: bool = True)[source]#
Bases:
objectFactory class for creating average pooling layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
kernel_size – the size of the window
stride – the stride of the window. Default value is
kernel_sizepadding – implicit zero padding to be added on both sides
ceil_mode – when True, will use ceil instead of floor to compute the output shape
count_include_pad – when True, will include the zero-padding in the averaging calculation
(the original version for 2d and 3d has a ‘divisor_override’ parameter which is neglected here)
- class fusionlab.layers.factories.BatchNorm(spatial_dims: int, num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = True, track_running_stats: bool = True)[source]#
Bases:
objectFactory class for creating batch normalization layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
num_features – number of features or channels \(C\) of the input
eps – a value added to the denominator for numerical stability. Default: 1e-5
momentum – the value used for the running_mean and running_var computation. Can be set to
Nonefor cumulative moving average (i.e. simple average). Default: 0.1affine – a boolean value that when set to
True, this module has learnable affine parameters. Default:Truetrack_running_stats – a boolean value that when set to
True, this module tracks the running mean and variance, and when set toFalse, this module does not track such statistics, and initializes statistics buffersrunning_meanandrunning_varasNone. When these buffers areNone, this module always uses batch statistics. in both training and eval modes. Default:True
- class fusionlab.layers.factories.ConstantPad(spatial_dims: int, padding: int | Sequence[int], value: float)[source]#
Bases:
objectFactory class for creating adaptive average pooling layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
padding (int, tuple) – the size of the padding. If is int, uses the same padding in all boundaries. If a 4-tuple, uses (:math:` ext{padding_left}`, :math:` ext{padding_right}`, :math:` ext{padding_top}`, :math:` ext{padding_bottom}`)
value (float) – the value of padding
- class fusionlab.layers.factories.ConvND(spatial_dims: int, in_channels: int, out_channels: int, kernel_size: Sequence[int] | int, stride: Sequence[int] | int = 1, padding: int | Sequence[int] | None = None, dilation: Sequence[int] | int = 1, groups: int = 1, bias: bool = True, padding_mode: str = 'zeros')[source]#
Bases:
objectFactory class for creating convolutional layers. This class is used to create convolutional layers with the same configuration.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
in_channels (int) – number of channels in the input data.
out_channels (int) – number of channels produced by the convolution.
kernel_size (int or tuple) – size of the convolving kernel.
stride (int or tuple, optional) – stride of the convolution. Default: 1
padding (int or tuple, optional) – zero-padding added to both sides of the input,
Nonefor same padding. Default:Nonedilation (int or tuple, optional) – spacing between kernel elements. Default: 1
groups (int, optional) – number of blocked connections from input channels to output channels. Default: 1
bias (bool, optional) – whether to add a bias to the convolution. Default: True
padding_mode (str, optional) – type of padding. Default: ‘zeros’
- class fusionlab.layers.factories.ConvT(spatial_dims, in_channels: int, out_channels: int, kernel_size: Sequence[int] | int, stride: Sequence[int] | int = 1, padding: int | Sequence[int] | None = None, output_padding: Sequence[int] | str = 0, groups: int = 1, bias: bool = True, dilation: Sequence[int] | int = 1, padding_mode: str = 'zeros')[source]#
Bases:
objectFactory class for creating transposed convolutional layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
in_channels (int) – number of channels in the input data.
out_channels (int) – number of channels produced by the convolution.
kernel_size (int or tuple) – size of the convolving kernel.
stride (int or tuple, optional) – stride of the convolution. Default:
1padding (int or tuple, optional) – zero-padding added to both sides of the input,
Nonefor same padding. Default:Noneoutput_padding (int or tuple, optional) – additional size added to one side of each dimension in the output shape. Default:
0groups (int, optional) – number of blocked connections from input channels to output channels. Default:
1bias (bool, optional) – whether to add a bias to the convolution. Default:
Truedilation (int or tuple, optional) – spacing between kernel elements. Default:
1padding_mode (str, optional) – type of padding. Default:
zeros
- class fusionlab.layers.factories.MaxPool(spatial_dims: int, kernel_size: int | Sequence[int], stride: int | Sequence[int] | None = None, padding: Sequence[int] | int = 0, dilation: Sequence[int] | int = 1, return_indices: bool = False, ceil_mode: bool = False)[source]#
Bases:
objectFactory class for creating maximum pooling layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
kernel_size – The size of the sliding window, must be > 0.
stride – The stride of the sliding window, must be > 0. Default value is
kernel_size.padding – Implicit negative infinity padding to be added on both sides, must be >= 0 and <= kernel_size / 2.
dilation – The stride between elements within a sliding window, must be > 0.
return_indices – If
True, will return the argmax along with the max values. Useful fortorch.nn.MaxUnpool1dlaterceil_mode – If
True, will use ceil instead of floor to compute the output shape. This ensures that every element in the input tensor is covered by a sliding window.
- class fusionlab.layers.factories.ReplicationPad(spatial_dims: int, padding: int | Sequence[int])[source]#
Bases:
objectFactory class for creating replication padding layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
padding (int, tuple) – the size of the padding. If is int, uses the same padding in all boundaries. If a 4-tuple, uses (:math:` ext{padding_left}`, :math:` ext{padding_right}`, :math:` ext{padding_top}`, :math:` ext{padding_bottom}`)
- class fusionlab.layers.factories.Upsample(spatial_dims: int, size: int | Sequence[int] | None = None, scale_factor: int | Sequence[int] | None = None, mode: str = 'nearest', align_corners: bool | None = None, recompute_scale_factor: bool | None = None)[source]#
Bases:
objectFactory class for creating Upsample layers.
- Parameters:
spatial_dims (int) – number of spatial dimensions of the input data.
size (int or Tuple[int] or Tuple[int, int] or Tuple[int, int, int], optional) – output spatial sizes
scale_factor (float or Tuple[float] or Tuple[float, float] or Tuple[float, float, float], optional) – multiplier for spatial size. Has to match input size if it is a tuple.
mode (str, optional) – the upsampling algorithm: one of
'nearest','linear','bilinear','bicubic'and'trilinear'. Default:'nearest'align_corners (bool, optional) – if
True, the corner pixels of the input and output tensors are aligned, and thus preserving the values at those pixels. This only has effect whenmodeis'linear','bilinear','bicubic', or'trilinear'. Default:Falserecompute_scale_factor (bool, optional) – recompute the scale_factor for use in the interpolation calculation. If recompute_scale_factor is
True, then scale_factor must be passed in and scale_factor is used to compute the output size. The computed output size will be used to infer new scales for the interpolation. Note that when scale_factor is floating-point, it may differ from the recomputed scale_factor due to rounding and precision issues. If recompute_scale_factor isFalse, then size or scale_factor will be used directly for interpolation.