Skip to content

UNet

Source

UNet model.

A UNet encoder, decoder and complete model.

UNet

Bases: Module

UNet model.

Adapted for PyTorch from: https://github.com/juglab/n2v/blob/main/n2v/nets/unet_blocks.py.

Parameters:

Name Type Description Default
conv_dims int

Number of dimensions of the convolution layers (2 or 3).

required
num_classes int

Number of classes to predict, by default 1.

1
in_channels int

Number of input channels, by default 1.

1
depth int

Number of downsamplings, by default 3.

3
num_channels_init int

Number of filters in the first convolution layer, by default 64.

64
use_batch_norm bool

Whether to use batch normalization, by default True.

True
dropout float

Dropout probability, by default 0.0.

0.0
pool_kernel int

Kernel size of the pooling layers, by default 2.

2
residual bool

Whether to add a residual connection from the input to the output.

False
final_activation Optional[Callable]

Activation function to use for the last layer, by default None.

NONE
n2v2 bool

Whether to use N2V2 architecture, by default False.

False
independent_channels bool

Whether to train the channels independently, by default True.

True
**kwargs Any

Additional keyword arguments, unused.

{}

forward(x)

Forward pass.

Parameters:

Name Type Description Default
x torch.Tensor

Input tensor.

required

Returns:

Type Description
Tensor

Output of the model.

UnetDecoder

Bases: Module

Unet decoder pathway.

Parameters:

Name Type Description Default
conv_dim int

Number of dimension of the convolution layers, 2 for 2D or 3 for 3D.

required
depth int

Number of decoder blocks, by default 3.

3
num_channels_init int

Number of channels in the first encoder block, by default 64.

64
use_batch_norm bool

Whether to use batch normalization, by default True.

True
dropout float

Dropout probability, by default 0.0.

0.0
n2v2 bool

Whether to use N2V2 architecture, by default False.

False
groups int

Number of blocked connections from input channels to output channels, by default 1.

1

forward(*features)

Forward pass.

Parameters:

Name Type Description Default
*features list[torch.Tensor]

List containing the output of each encoder block(skip connections) and final output of the encoder.

()

Returns:

Type Description
Tensor

Output of the decoder.

UnetEncoder

Bases: Module

Unet encoder pathway.

Parameters:

Name Type Description Default
conv_dim int

Number of dimension of the convolution layers, 2 for 2D or 3 for 3D.

required
in_channels int

Number of input channels, by default 1.

1
depth int

Number of encoder blocks, by default 3.

3
num_channels_init int

Number of channels in the first encoder block, by default 64.

64
use_batch_norm bool

Whether to use batch normalization, by default True.

True
dropout float

Dropout probability, by default 0.0.

0.0
pool_kernel int

Kernel size for the max pooling layers, by default 2.

2
n2v2 bool

Whether to use N2V2 architecture, by default False.

False
groups int

Number of blocked connections from input channels to output channels, by default 1.

1

forward(x)

Forward pass.

Parameters:

Name Type Description Default
x Tensor

Input tensor.

required

Returns:

Type Description
list[Tensor]

Output of each encoder block (skip connections) and final output of the encoder.