Network architectures

Blocks

Convolution

class Convolution(dimensions, in_channels, out_channels, strides=1, kernel_size=3, instance_norm=True, dropout=0, dilation=1, bias=True, conv_only=False, is_transposed=False)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

ResidualUnit

class ResidualUnit(dimensions, in_channels, out_channels, strides=1, kernel_size=3, subunits=2, instance_norm=True, dropout=0, dilation=1, bias=True, last_conv_only=False)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

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.

Layers

get_conv_type

factories.get_conv_type(is_transpose)

get_dropout_type

factories.get_dropout_type()

get_normalize_type

factories.get_normalize_type(is_instance)

get_maxpooling_type

factories.get_maxpooling_type(is_adaptive)

get_avgpooling_type

factories.get_avgpooling_type(is_adaptive)

SkipConnection

class SkipConnection(submodule, cat_dim=1)[source]

Concats the forward pass input with the result from the given submodule.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

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.

Flatten

class Flatten[source]

Flattens the given input in the forward pass to be [B,-1] in shape.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

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.

GaussianFilter

class GaussianFilter(spatial_dims, sigma, truncated=4.0, device=None)[source]
Parameters
  • spatial_dims (int) – number of spatial dimensions of the input image. must have shape (Batch, channels, H[, W, …]).

  • sigma (float) – std.

  • truncated (float) – spreads how many stds.

  • device (torch.device) – device on which the tensor will be allocated.

__call__(x)[source]
Parameters

x (tensor) – in shape [Batch, chns, H, W, D].

Nets

Densenet3D

class DenseNet(spatial_dims, in_channels, out_channels, init_features=64, growth_rate=32, block_config=(6, 12, 24, 16), bn_size=4, dropout_prob=0)[source]

Densenet based on: “Densely Connected Convolutional Networks” https://arxiv.org/pdf/1608.06993.pdf Adapted from PyTorch Hub 2D version: https://github.com/pytorch/vision/blob/master/torchvision/models/densenet.py

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

  • in_channels (Int) – number of the input channel.

  • out_channels (Int) – number of the output classes.

  • init_features (Int) –

  • growth_rate (Int) – how many filters to add each layer (k in paper).

  • block_config (tuple) – how many layers in each pooling block.

  • bn_size (Int) – (i.e. bn_size * k features in the bottleneck layer)

  • dropout_prob (Float) – dropout rate after each dense layer.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

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.

densenet3d.densenet121()
densenet3d.densenet169()
densenet3d.densenet201()
densenet3d.densenet264()

Highresnet

class ConvNormActi(spatial_dims, in_channels, out_channels, kernel_size, norm_type=None, acti_type=None, dropout_prob=None)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

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.

class HighResBlock(spatial_dims, in_channels, out_channels, kernels=(3, 3), dilation=1, norm_type='instance', acti_type='relu', channel_matching='pad')[source]
Parameters
  • kernels (list of int) – each integer k in kernels corresponds to a convolution layer with kernel size k.

  • channel_matching ('pad'|'project') – handling residual branch and conv branch channel mismatches with either zero padding (‘pad’) or a trainable conv with kernel size 1 (‘project’).

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.

class HighResNet(spatial_dims=3, in_channels=1, out_channels=1, norm_type='batch', acti_type='relu', dropout_prob=None, layer_params=({'name': 'conv_0', 'n_features': 16, 'kernel_size': 3}, {'name': 'res_1', 'n_features': 16, 'kernels': (3, 3), 'repeat': 3}, {'name': 'res_2', 'n_features': 32, 'kernels': (3, 3), 'repeat': 3}, {'name': 'res_3', 'n_features': 64, 'kernels': (3, 3), 'repeat': 3}, {'name': 'conv_1', 'n_features': 80, 'kernel_size': 1}, {'name': 'conv_2', 'kernel_size': 1}))[source]

Reimplementation of highres3dnet based on Li et al., “On the compactness, efficiency, and representation of 3D convolutional networks: Brain parcellation as a pretext task”, IPMI ‘17

Adapted from: https://github.com/NifTK/NiftyNet/blob/v0.6.0/niftynet/network/highres3dnet.py https://github.com/fepegar/highresnet

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

  • in_channels (int) – number of input channels.

  • out_channels (int) – number of output channels.

  • norm_type ('batch'|'instance') – feature normalisation with batchnorm or instancenorm.

  • acti_type ('relu'|'prelu'|'relu6') – non-linear activation using ReLU or PReLU.

  • dropout_prob (float) – probability of the feature map to be zeroed (only applies to the penultimate conv layer).

  • layer_params (a list of dictionaries) – specifying key paraemters of each layer/block.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

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.

Unet

class UNet(dimensions, in_channels, out_channels, channels, strides, kernel_size=3, up_kernel_size=3, num_res_units=0, instance_norm=True, dropout=0)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

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.