mr2.nn.nets.Uformer
- class mr2.nn.nets.Uformer[source]
Bases:
UNetBaseUformer: U-Net with window attention.
Implements the Uformer network proposed in [WANG21] It is SWin-Transformer/U-Net hybrid consisting of (shifted) windows attention transformer layers at different resolution levels, extended by FiLM layers for conditioning.
References
[WANG21]Wang, Z., Cun, X., Bao, J., Zhou, W., Liu, J., & Li, H. Uformer: A general u-shaped transformer for image restoration. CVPR 2022. https://doi.org/10.48550/arXiv.2106.03106
- __init__(n_dim: int, n_channels_in: int, n_channels_out: int, n_channels_per_head: int = 32, n_heads: Sequence[int] = (1, 2, 4, 8), n_blocks: int = 2, cond_dim: int = 0, window_size: int = 8, mlp_ratio: float = 4.0, max_droppath_rate: float = 0.1)[source]
Initialize the Uformer module.
- Parameters:
n_dim (
int) – The number of spatial dimensions of the input tensor.n_channels_in (
int) – The number of input channels.n_channels_out (
int) – The number of output channels.n_channels_per_head (
int, default:32) – The number of features per head. The number of features at a resolution level is given byn_channels_per_head * n_heads.n_heads (
Sequence[int], default:(1, 2, 4, 8)) – Number of attention heads at each resolution level.n_blocks (
int, default:2) – The number of transformer blocks at each resolution level in the input and output pathcond_dim (
int, default:0) – Dimension of a conditioning tensor. If0, no FiLM layers are added.window_size (
int, default:8) – The size of the attention windows in the (shifted) window attention layers.mlp_ratio (
float, default:4.0) – Ratio of the hidden dimension to the input dimension in the feed-forward blocksmax_droppath_rate (
float, default:0.1) – Maximum drop path rate. As in the original implementation, the drop path rate in the input path is linearly increased from0tomax_droppath_ratewith decreasing resolution. The rate in output blocks is fixed tomax_droppath_rate.
- encoder
The encoder.
- decoder
The decoder.
- skip_blocks
Modifications of the skip connections.