mr2.nn.nets.UNet

class mr2.nn.nets.UNet[source]

Bases: UNetBase

UNet.

U-shaped convolutional network with optional patch attention. Inspired by [NOSENSE] and the OpenAi DDPM UNet/Latent Diffusion UNet [LDM]. Significant differences to the vanilla UNet [UNET] include:

  • Spatial transformer blocks

  • Convolutional downsampling, nearest neighbor upsampling

  • Residual convolution blocks with pre-act group normalization and SiLU activation

References

[UNET]

Ronneberger, Olaf, Philipp Fischer, and Thomas Brox. “U-net: Convolutional networks for biomedical image segmentation MICCAI 2015. https://arxiv.org/abs/1505.04597

[NOSENSE]

Zimmermann, FF, and Kofler, Andreas. “NoSENSE: Learned unrolled cardiac MRI reconstruction without explicit sensitivity maps.” STACOM 2023. https://github.com/fzimmermann89/CMRxRecon/blob/master/src/cmrxrecon/nets/unet.py

__init__(n_dim: int, n_channels_in: int, n_channels_out: int, attention_depths: Sequence[int] = (-1,), n_features: Sequence[int] = (64, 128, 192, 256), n_heads: int = 8, cond_dim: int = 0, encoder_blocks_per_scale: int = 2) → None[source]

Initialize the UNet.

Parameters:
  • n_dim (int) – The number of spatial dimensions of the input tensor.

  • n_channels_in (int) – The number of channels in the input tensor.

  • n_channels_out (int) – The number of channels in the output tensor.

  • attention_depths (Sequence[int], default: (-1,)) – The depths at which to apply attention.

  • n_features (Sequence[int], default: (64, 128, 192, 256)) – Number of features at each resolution level. The length determines the number of resolution levels.

  • n_heads (int, default: 8) – Number of attention heads.

  • cond_dim (int, default: 0) – Number of channels in the conditioning tensor. If 0, no conditioning is applied.

  • encoder_blocks_per_scale (int, default: 2) – Number of encoder blocks per resolution level. The number of decoder blocks is one more.

encoder

The encoder.

decoder

The decoder.

skip_blocks

Modifications of the skip connections.

__call__(x: Tensor, *, cond: Tensor | None = None) → Tensor[source]

Apply to Network.

Parameters:
  • x (Tensor) – The input tensor.

  • cond (Tensor | None, default: None) – The conditioning tensor.

Returns:

The output tensor.

forward(x: Tensor, *, cond: Tensor | None = None) → Tensor[source]

Apply to Network.