mr2.nn.FiLM

class mr2.nn.FiLM[source]

Bases: CondMixin, Module

Feature-wise Linear Modulation.

Feature-wise Linear Modulation from [FiLM] to condition a network on a conditioning tensor.

References

..[FiLM] Perez, L., Strub, F., de Vries, H., Dumoulin, V., & Courville, A. “FiLMVisual reasoning with a general

conditioning layer.” AAAI (2018). https://arxiv.org/abs/1709.07871

__init__(channels: int, cond_dim: int, features_last: bool = False) → None[source]

Initialize FiLM.

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

  • cond_dim (int) – The dimension of the conditioning tensor.

  • features_last (bool, default: False) – Whether the features are in the last dimension of the input tensor (e.g. transformer tokens) or in the second dimension (e.g. image tensors).

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

Apply FiLM.

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

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

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

Apply FiLM.