mr2.nn.nets.HourglassTransformer

class mr2.nn.nets.HourglassTransformer[source]

Bases: UNetBase

Hourglass Transformer.

A U-shaped transformer [CK] with neighborhood self-attention [NAT].

References

[CK]

Crowson, Katherine, et al. “Scalable high-resolution pixel-space image synthesis with hourglass diffusion transformers.” ICML 2024, https://arxiv.org/abs/2401.11605

[NAT]

Hassani, A. et al. “Neighborhood Attention Transformer” CVPR, 2023, https://arxiv.org/abs/2204.07143

__init__(n_dim: int, n_channels_in: int, n_channels_out: int, n_features: Sequence[int] | int, depths: Sequence[int] | int = 3, attention_neighborhood: Sequence[int | None] | int | None = 11, n_heads: int | Sequence[int] = 4, cond_dim: int = 0)[source]

Initialize the Hourglass Transformer.

Parameters:
  • n_dim (int) – Number of (spatial)dimensions of the input data.

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

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

  • n_features (Sequence[int] | int) – Number of features in each stage.

  • depths (Sequence[int] | int, default: 3) – Number of layers in each stage.

  • attention_neighborhood (Sequence[int | None] | int | None, default: 11) – Neighborhood size for the neighborhood self-attention. If None, use global attention for that stage.

  • n_heads (int | Sequence[int], default: 4) – Number of heads in each stage.

  • cond_dim (int, default: 0) – Number of dimensions of the conditioning tensor.

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.