mr2.nn.AbsolutePositionEncoding

class mr2.nn.AbsolutePositionEncoding[source]

Bases: Module

Absolute position encoding layer.

Encodes absolute positions in a grid. Has no learnable parameters.

__init__(n_dim: int, n_features: int, include_radii: bool = True, base_resolution: int = 128)[source]

Initialize absolute position encoding layer.

Parameters:
  • n_dim (int) – Dimensions of the input space (1, 2, or 3)

  • n_features (int) – Number of features to encode. The input to the forward pass needs to have at least this many features/channels.

  • include_radii (bool, default: True) – Whether to include radius features

  • base_resolution (int, default: 128) – Base resolution for position encoding. Encodings are generated at this resolution and interpolated to the input shape in the forward pass.

__call__(x: Tensor) → Tensor[source]

Apply absolute position encoding to a tensor.

Parameters:

x (Tensor) – Input tensor

Returns:

Encoded tensor with absolute position information

forward(x: Tensor) → Tensor[source]

Apply absolute position encoding to a tensor.