layers module

class edafm.layers.Conv2dBlock(in_channels, out_channels, kernel_size=3, depth=2, padding_mode='zeros', res_connection=True, activation=None, last_activation=True)[source]

Bases: edafm.layers._ConvNdBlock

Pytorch 2D convolution block module.

Parameters
  • in_channels – int. Number of channels entering the first convolution layer.

  • out_channels – int. Number of output channels in each layer of the block.

  • kernel_size – int or tuple. Size of convolution kernel.

  • depth – int >= 1. Number of convolution layers in the block.

  • padding_mode – str. Type of padding in each convolution layer. ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’.

  • res_connection – Boolean. Whether to use residual connection over the block (f(x) = h(x) + x). If in_channels != out_channels, a 1x1 convolution is applied to the res connection to make the channel numbers match.

  • activation – torch.nn.Module. Activation function to use after every layer in block. If None, defaults to ReLU.

  • last_activation – Bool. Whether to apply the activation after the last conv layer (before res connection).

training: bool
class edafm.layers.Conv3dBlock(in_channels, out_channels, kernel_size=3, depth=2, padding_mode='zeros', res_connection=True, activation=None, last_activation=True)[source]

Bases: edafm.layers._ConvNdBlock

Pytorch 3D convolution block module.

Parameters
  • in_channels – int. Number of channels entering the first convolution layer.

  • out_channels – int. Number of output channels in each layer of the block.

  • kernel_size – int or tuple. Size of convolution kernel.

  • depth – int >= 1. Number of convolution layers in the block.

  • padding_mode – str. Type of padding in each convolution layer. ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’.

  • res_connection – Boolean. Whether to use residual connection over the block (f(x) = h(x) + x). If in_channels != out_channels, a 1x1x1 convolution is applied to the res connection to make the channel numbers match.

  • activation – torch.nn.Module. Activation function to use after every layer in block. If None, defaults to ReLU.

  • last_activation – Bool. Whether to apply the activation after the last conv layer (before res connection).

training: bool
class edafm.layers.UNetAttentionConv(in_channels, query_channels, attention_channels, kernel_size, padding_mode='zeros', conv_activation=ReLU(), attention_activation='softmax', upsample_mode='bilinear')[source]

Bases: torch.nn.modules.module.Module

Pytorch attention layer for Attention U-net model upsampling stage.

Parameters
  • in_channels – int. Number of channels in the attended feature map.

  • query_channels – int. Number of channels in query feature map.

  • query_channels – int. Number of channels in hidden convolution layer before computing attention.

  • kernel_size – int. Size of convolution kernel.

  • padding_mode – str. Type of padding in each convolution layer. ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’.

  • conv_activation – nn.Module. Activation function to use after convolution layers

  • attention_activation – str. Type of activation to use for attention map. ‘sigmoid’ or ‘softmax’.

  • upsample_mode – str. Algorithm for upsampling query feature map to the attended feature map size. For options see torch.nn.functional.interpolate.

References

https://arxiv.org/abs/1804.03999

forward(x, q)[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