mr2.nn.attention.AttentionGate

class mr2.nn.attention.AttentionGate[source]

Bases: Module

Attention gate from Attention UNet.

The attention mechanism from the attention UNet [OKT18].

References

..[OKT18] Oktay, Ozan, et al. “Attention U-net: Learning where to look for the pancreas.” MIDL (2018).

https://arxiv.org/abs/1804.03999

__init__(n_dim: int, channels_gate: int, channels_in: int, channels_hidden: int, concatenate: bool = False)[source]

Initialize the attention gate.

Parameters:
  • n_dim (int) – The dimension, i.e. 1, 2 or 3.

  • channels_gate (int) – The number of channels in the gate tensor.

  • channels_in (int) – The number of channels in the input tensor.

  • channels_hidden (int) – The number of internal, hidden channels.

  • concatenate (bool, default: False) – Whether to concatenate the gated signal with the gate signal in the channel dimension (1)

__call__(x: Tensor, gate: Tensor) → Tensor[source]

Apply the attention gate.

Parameters:
  • x (Tensor) – The input tensor.

  • gate (Tensor) – The gate tensor.

Returns:

The output tensor.

forward(x: Tensor, gate: Tensor) → Tensor[source]

Apply the attention gate.