mr2.nn.attention.ConvolutionalAttention

class mr2.nn.attention.ConvolutionalAttention[source]

Bases: Module

Temporal or patch attention with spatial convolutional projections.

Implements the attention used by the released SNRAware imaging transformers [XUE25]. Spatial relative-position bias is added after softmax, following the official implementation [SNRAWARE] rather than the usual logit bias.

References

[XUE25]

Xue et al. SNRAware: Improved Deep Learning MRI Denoising with SNR Unit Training and G-factor Map Augmentation. https://arxiv.org/abs/2503.18162

__init__(n_channels: int, n_heads: int, image_size: int, mode: Literal['temporal', 'local', 'global']) → None[source]

Initialize convolutional attention.

Parameters:
  • n_channels (int) – Number of input and output channels.

  • n_heads (int) – Number of heads. Must divide the channel count.

  • image_size (int) – Height and width of the input. Must be divisible by eight.

  • mode (Literal['temporal', 'local', 'global']) – Attend across frames, four patches within each local window, or all spatial patches within each frame.

__call__(x: Tensor) → Tensor[source]

Apply convolutional attention.

Parameters:

x (Tensor) – Real input of shape (batch, channels, frames, image_size, image_size).

Returns:

Features with the same shape as the input.

forward(x: Tensor) → Tensor[source]

Apply attention to a real tensor of shape (batch, channels, frames, height, width).