fusionlab.layers.base module#

class fusionlab.layers.base.ConvNormAct(spatial_dims, in_channels, out_channels, kernel_size, stride=1, padding=None, dilation=1, groups=1, bias=None, norm_layer=<class 'fusionlab.layers.factories.BatchNorm'>, act_layer=<class 'torch.nn.modules.activation.ReLU'>, padding_mode='zeros', inplace=<class 'bool'>)[source]#

Bases: Module

ref: https://pytorch.org/vision/main/generated/torchvision.ops.Conv2dNormActivation.html pytorch/vision

Convolution + Normalization + Activation

Parameters:
  • spatial_dims (int) – number of spatial dimensions of the input image.

  • in_channels (int) – number of channels of the input image.

  • out_channels (int) – number of channels of the output image.

  • kernel_size (Union[Sequence[int], int]) – size of the convolving kernel.

  • stride (Union[Sequence[int], int], optional) – stride of the convolution. Default: 1

  • padding (Union[Sequence[int], str], optional) – Padding added to all four sides of the input. Default: None, in which case it will be calculated as padding = (kernel_size - 1) // 2 * dilation

  • dilation (Union[Sequence[int], int], 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 use bias in the convolution layer. By default, biases are included if norm_layer is None.

  • norm_layer (Optional[Callable[..., nn.Module]], optional) – normalization layer. Default: BatchNorm

  • act_layer (Optional[Callable[..., nn.Module]], optional) – activation layer. Default: nn.ReLU

  • padding_mode (str, optional) – mode of padding. Default: ‘zeros’

  • inplace (Optional[bool], optional) – Parameter for the activation layer, which can optionally do the operation in-place. Default True

forward(x)[source]#

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool#
class fusionlab.layers.base.Rearrange(pattern, **kwargs)[source]#

Bases: Module

nn.Module wrapper for eion’s rearrange function

forward(x)[source]#

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool#