mr2.nn.SeparableResBlock

class mr2.nn.SeparableResBlock[source]

Bases: CondMixin, Module

Residual block with separable convolutions.

__init__(dim_groups: Sequence[Sequence[int]], n_channels_in: int, n_channels_out: int, cond_dim: int) → None[source]

Initialize the SeparableResBlock.

Applies convolutions as separable convolutions with SilU activation and group normalization. For example, if dim_groups = ((-1,-2), (-3)) then one 2D convolution is applied to the last two dimensions, and one 1D convolution is applied to the last dimension. The order within the block is Norm->Activation->Conv. The whole sequence for all dimension groups is performed twice, with optional FiLM conditioning in between. So for two dim_groups, a total of 4 convolutions are applied.

Parameters:
  • dim_groups (Sequence[Sequence[int]]) – Sequence of dimension groups to use in the convolutions.

  • n_channels_in (int) – Number of input channels.

  • n_channels_out (int) – Number of output channels.

  • cond_dim (int) – Number of channels in the conditioning tensor. If 0, no conditioning is applied.

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

Apply the SeparableResBlock.

Parameters:
  • x (Tensor) – Input tensor.

  • cond (Tensor | None, default: None) – Conditioning tensor.

Returns:

Output tensor with the same number and order of dimensions as the input.

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

Apply the SeparableResBlock.