mr2.nn.attention.TransposedAttention

class mr2.nn.attention.TransposedAttention[source]

Bases: Module

Transposed Self Attention from Restormer.

Implements the transposed self-attention, i.e. channel-wise multihead self-attention, layer from Restormer [ZAM22].

References

[ZAM22]

Zamir, Syed Waqas, et al. “Restormer: Efficient transformer for high-resolution image restoration.” CVPR 2022, https://arxiv.org/pdf/2111.09881.pdf

__init__(n_dim: int, n_channels_in: int, n_channels_out: int, n_heads: int)[source]

Initialize a TransposedAttention layer.

Parameters:
  • n_dim (int) – input dimension

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

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

  • n_heads (int) – Number of attention heads.

__call__(x: Tensor) → Tensor[source]

Apply transposed attention.

Parameters:

x (Tensor) – The input tensor.

Returns:

The output tensor.

forward(x: Tensor) → Tensor[source]

Apply transposed attention.