pymic.layer package

Submodules

pymic.layer.activation module

pymic.layer.activation.get_acti_func(acti_func, params)

pymic.layer.convolution module

class pymic.layer.convolution.ConvolutionLayer(in_channels, out_channels, kernel_size, dim=3, stride=1, padding=0, dilation=1, conv_group=1, bias=True, norm_type='batch_norm', norm_group=1, acti_func=None)

Bases: Module

A compose layer with the following components: convolution -> (batch_norm / layer_norm / group_norm / instance_norm) -> (activation) -> (dropout) Batch norm and activation are optional.

Parameters:
  • in_channels – (int) The input channel number.

  • out_channels – (int) The output channel number.

  • kernel_size – The size of convolution kernel. It can be either a single int or a tupe of two or three ints.

  • dim – (int) The dimention of convolution (2 or 3).

  • stride – (int) The stride of convolution.

  • padding – (int) Padding size.

  • dilation – (int) Dilation rate.

  • conv_group – (int) The groupt number of convolution.

  • bias – (bool) Add bias or not for convolution.

  • norm_type – (str or None) Normalization type, can be batch_norm, ‘group_norm’.

  • norm_group – (int) The number of group for group normalization.

  • acti_func – (str or None) Activation funtion.

forward(x)

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 pymic.layer.convolution.DepthSeperableConvolutionLayer(in_channels, out_channels, kernel_size, dim=3, stride=1, padding=0, dilation=1, conv_group=1, bias=True, norm_type='batch_norm', norm_group=1, acti_func=None)

Bases: Module

Depth seperable convolution with the following components: 1x1 conv -> group conv -> (batch_norm / layer_norm / group_norm / instance_norm) -> (activation) -> (dropout) Batch norm and activation are optional.

Parameters:
  • in_channels – (int) The input channel number.

  • out_channels – (int) The output channel number.

  • kernel_size – The size of convolution kernel. It can be either a single int or a tupe of two or three ints.

  • dim – (int) The dimention of convolution (2 or 3).

  • stride – (int) The stride of convolution.

  • padding – (int) Padding size.

  • dilation – (int) Dilation rate.

  • conv_group – (int) The groupt number of convolution.

  • bias – (bool) Add bias or not for convolution.

  • norm_type – (str or None) Normalization type, can be batch_norm, ‘group_norm’.

  • norm_group – (int) The number of group for group normalization.

  • acti_func – (str or None) Activation funtion.

forward(x)

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

pymic.layer.deconvolution module

class pymic.layer.deconvolution.DeconvolutionLayer(in_channels, out_channels, kernel_size, dim=3, stride=1, padding=0, output_padding=0, dilation=1, groups=1, bias=True, batch_norm=True, acti_func=None)

Bases: Module

A compose layer with the following components: deconvolution -> (batch_norm / layer_norm / group_norm / instance_norm) -> (activation) -> (dropout) Batch norm and activation are optional.

Parameters:
  • in_channels – (int) The input channel number.

  • out_channels – (int) The output channel number.

  • kernel_size – The size of convolution kernel. It can be either a single int or a tupe of two or three ints.

  • dim – (int) The dimention of convolution (2 or 3).

  • stride – (int) The stride of convolution.

  • padding – (int) Padding size.

  • dilation – (int) Dilation rate.

  • groups – (int) The groupt number of convolution.

  • bias – (bool) Add bias or not for convolution.

  • batch_norm – (bool) Use batch norm or not.

  • acti_func – (str or None) Activation funtion.

forward(x)

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 pymic.layer.deconvolution.DepthSeperableDeconvolutionLayer(in_channels, out_channels, kernel_size, dim=3, stride=1, padding=0, output_padding=0, dilation=1, groups=1, bias=True, batch_norm=True, acti_func=None)

Bases: Module

Depth seperable deconvolution with the following components: 1x1 conv -> deconv -> (batch_norm / layer_norm / group_norm / instance_norm) -> (activation) -> (dropout) Batch norm and activation are optional.

Parameters:
  • in_channels – (int) The input channel number.

  • out_channels – (int) The output channel number.

  • kernel_size – The size of convolution kernel. It can be either a single int or a tupe of two or three ints.

  • dim – (int) The dimention of convolution (2 or 3).

  • stride – (int) The stride of convolution.

  • padding – (int) Padding size for input.

  • output_padding – (int) Padding size for ouput.

  • dilation – (int) Dilation rate.

  • groups – (int) The groupt number of convolution.

  • bias – (bool) Add bias or not for convolution.

  • batch_norm – (bool) Use batch norm or not.

  • acti_func – (str or None) Activation funtion.

forward(x)

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

pymic.layer.space2channel module

class pymic.layer.space2channel.ChannelToSpace3D

Bases: Module

Channel to space transform for 3D input.

forward(x)

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 pymic.layer.space2channel.SpaceToChannel3D

Bases: Module

Space to channel transform for 3D input.

forward(x)

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

Module contents