mr2.nn.nets.SwinIR

class mr2.nn.nets.SwinIR[source]

Bases: CondMixin, Module

SwinIR architecture.

Implements the SwinIR [LZL21] network, which is a Swin Transformer based image restoration network.

References

[LZL21]

Liang, Jie, et al. “SwinIR: Image restoration using swin transformer.” ICCVW 2021, https://arxiv.org/pdf/2108.10257.pdf

__init__(n_dim: int, n_channels_in: int, n_channels_out: int, n_channels_per_head: int = 16, n_heads: int = 6, window_size: int = 64, n_blocks: int = 6, n_attn_per_block: int = 6, emb_dim: int = 0, p_droppath: float = 0.0, mlp_ratio: int = 4)[source]

Initialize SwinIR.

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: 16) – The number of channels per attention head.

  • n_heads (int, default: 6) – The number of attention heads.

  • window_size (int, default: 64) – The size of the attention window. Partial windows are padded circularly.

  • n_blocks (int, default: 6) – The number of residual blocks.

  • n_attn_per_block (int, default: 6) – The number of attention layers per block.

  • emb_dim (int, default: 0) – The dimension of the conditioning input. If 0, no FiLM conditioning is used.

  • p_droppath (float, default: 0.0) – The droppath probability for MLP.

  • mlp_ratio (int, default: 4) – The ratio for hidden dimension expansion in MLP.

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

Apply the module to the input.

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

Apply SwinIR.

Parameters:
  • x (Tensor) – Input tensor

  • cond (Tensor | None, default: None) – Conditioning input. If None, no FiLM conditioning is used.

Returns:

torch.Tensor – Output tensor