deepali.networks.unet#

U-net model architectures.

Module Contents#

Classes#

UNetLayerConfig

Base class of configuration data classes.

UNetDownsampleConfig

Base class of configuration data classes.

UNetUpsampleConfig

Base class of configuration data classes.

UNetOutputConfig

Base class of configuration data classes.

UNetEncoderConfig

Base class of configuration data classes.

UNetDecoderConfig

Base class of configuration data classes.

UNetConfig

Base class of configuration data classes.

UNetEncoder

Downsampling path of U-net model.

UNetDecoder

Upsampling path of U-net model.

SequentialUNet

Sequential U-net architecture.

UNet

U-net with optionally multiple output layers.

Functions#

unet_conv_block(→ torch.nn.Module)

Create U-net block of convolutional layers.

class UNetLayerConfig[source]#
Inheritance diagram of deepali.networks.unet.UNetLayerConfig

Base class of configuration data classes.

class UNetDownsampleConfig[source]#
Inheritance diagram of deepali.networks.unet.UNetDownsampleConfig

Base class of configuration data classes.

class UNetUpsampleConfig[source]#
Inheritance diagram of deepali.networks.unet.UNetUpsampleConfig

Base class of configuration data classes.

class UNetOutputConfig[source]#
Inheritance diagram of deepali.networks.unet.UNetOutputConfig

Base class of configuration data classes.

class UNetEncoderConfig[source]#
Inheritance diagram of deepali.networks.unet.UNetEncoderConfig

Base class of configuration data classes.

property num_levels: int#

Number of spatial encoder levels.

class UNetDecoderConfig[source]#
Inheritance diagram of deepali.networks.unet.UNetDecoderConfig

Base class of configuration data classes.

property num_levels: int#

Number of spatial decoder levels, including bottleneck input.

classmethod from_encoder(encoder: Union[UNetEncoder, UNetEncoderConfig], residual: Optional[bool] = None, **kwargs) UNetDecoderConfig[source]#

Derive decoder configuration from U-net encoder configuration.

class UNetConfig[source]#
Inheritance diagram of deepali.networks.unet.UNetConfig

Base class of configuration data classes.

unet_conv_block(spatial_dims: int, in_channels: int, out_channels: int, kernel_size: deepali.core.typing.ScalarOrTuple[int] = 3, stride: deepali.core.typing.ScalarOrTuple[int] = 1, padding: Optional[deepali.core.typing.ScalarOrTuple[int]] = None, padding_mode: Union[deepali.core.enum.PaddingMode, str] = 'zeros', dilation: deepali.core.typing.ScalarOrTuple[int] = 1, groups: int = 1, init: str = 'default', bias: Optional[Union[bool, str]] = None, norm: deepali.networks.layers.NormArg = None, acti: deepali.networks.layers.ActivationArg = None, order: str = 'CNA', num_layers: Optional[int] = None) torch.nn.Module[source]#

Create U-net block of convolutional layers.

class UNetEncoder(spatial_dims: int, in_channels: Optional[int] = None, config: Optional[UNetEncoderConfig] = None, conv_block: Optional[ModuleFactory] = None, input_layer: Optional[ModuleFactory] = None)[source]#
Inheritance diagram of deepali.networks.unet.UNetEncoder

Downsampling path of U-net model.

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

output_size(in_size: deepali.core.typing.ScalarOrTuple[int]) deepali.core.typing.ScalarOrTuple[int][source]#

Calculate output size of last feature map for a tensor of given spatial input size.

output_sizes(in_size: deepali.core.typing.ScalarOrTuple[int]) List[deepali.core.typing.ScalarOrTuple[int]][source]#

Calculate output sizes of feature maps for a tensor of given spatial input size.

class UNetDecoder(spatial_dims: int, in_channels: Optional[int] = None, config: Optional[UNetDecoderConfig] = None, conv_block: Optional[ModuleFactory] = None, input_layer: Optional[ModuleFactory] = None, output_all: bool = False)[source]#
Inheritance diagram of deepali.networks.unet.UNetDecoder

Upsampling path of U-net model.

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

classmethod from_encoder(encoder: Union[UNetEncoder, UNetEncoderConfig], residual: Optional[bool] = None, **kwargs) UNetDecoder[source]#

Create U-net decoder given U-net encoder configuration.

output_size(in_size: deepali.core.typing.ScalarOrTuple[int]) deepali.core.typing.ScalarOrTuple[int][source]#

Calculate output size for an initial feature map of given spatial input size.

output_sizes(in_size: deepali.core.typing.ScalarOrTuple[int]) List[deepali.core.typing.ScalarOrTuple[int]][source]#

Calculate output sizes for an initial feature map of given spatial input size.

class SequentialUNet(spatial_dims: int, in_channels: Optional[int] = None, out_channels: Optional[int] = None, config: Optional[UNetConfig] = None, conv_block: Optional[ModuleFactory] = None, output_layer: Optional[ModuleFactory] = None, bridge_layer: Optional[ModuleFactory] = None)[source]#
Inheritance diagram of deepali.networks.unet.SequentialUNet

Sequential U-net architecture.

The final module of this sequential module either outputs a tuple of feature maps at the different resolution levels (out_channels=None), the final decoded feature map at the highest resolution level (out_channels == config.decoder.out_channels and output_layers=None), or a tensor with specified number of out_channels as produced by a final output layer otherwise. Note that additional layers (e.g., a custom output layer or post-output layers) can be added to the initialized sequential U-net using add_module().

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

output_size(in_size: deepali.core.typing.ScalarOrTuple[int]) deepali.core.typing.ScalarOrTuple[int][source]#

Calculate spatial output size given an input tensor with specified spatial size.

class UNet(spatial_dims: int, in_channels: Optional[int] = None, out_channels: Optional[int] = None, output_modules: Optional[Mapping[str, torch.nn.Module]] = None, output_indices: Optional[Union[Mapping[str, int], int]] = None, config: Optional[UNetConfig] = None, conv_block: Optional[ModuleFactory] = None, bridge_layer: Optional[ModuleFactory] = None, output_layer: Optional[ModuleFactory] = None, output_name: str = 'output')[source]#
Inheritance diagram of deepali.networks.unet.UNet

U-net with optionally multiple output layers.

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

output_is_dict() bool[source]#

Whether model output is dictionary of output tensors.

output_is_tensor() bool[source]#

Whether model output is a single output tensor.

output_is_tuple() bool[source]#

Whether model output is tuple of decoded feature maps.