FiLM API
-
class FiLM
Feature-wise Linear Modulation (FiLM)
Given an input (input_dim x num_frames) and a condition (condition_dim x num_frames), compute: scale, shift = Conv1x1(condition) split across channels (top/bottom half, respectively) output = input * scale + shift (elementwise)
FiLM applies per-channel scaling and optional shifting based on conditioning input, allowing the model to adapt its behavior based on external signals.
Public Functions
-
inline FiLM(const int condition_dim, const int input_dim, const bool shift, const int groups = 1)
Constructor.
- Parameters:
condition_dim – Size of the conditioning input
input_dim – Size of the input to be modulated
shift – Whether to apply both scale and shift (true) or only scale (false)
groups – Number of groups for grouped convolution in the condition-to-scale-shift submodule (default: 1)
-
inline Eigen::MatrixXf &GetOutput()
Get the entire internal output buffer.
This is intended for internal wiring between layers; callers should treat the buffer as pre-allocated storage and only consider the first num_frames columns valid for a given processing call. Slice with .leftCols(num_frames) as needed.
- Returns:
Reference to the output buffer
-
inline const Eigen::MatrixXf &GetOutput() const
Get the entire internal output buffer (const version)
- Returns:
Const reference to the output buffer
-
inline void SetMaxBufferSize(const int maxBufferSize)
Resize buffers to handle maxBufferSize frames.
- Parameters:
maxBufferSize – Maximum number of frames to process in a single call
-
inline void set_weights_(std::vector<float>::iterator &weights)
Set the parameters (weights) of this module.
- Parameters:
weights – Iterator to the weights vector. Will be advanced as weights are consumed.
-
inline long get_condition_dim() const
Get the condition dimension.
- Returns:
Size of the conditioning input
-
inline long get_input_dim() const
Get the input dimension.
- Returns:
Size of the input to be modulated
-
inline void Process(const Eigen::Ref<const Eigen::MatrixXf> &input, const Eigen::Ref<const Eigen::MatrixXf> &condition, const int num_frames)
Process input with conditioning.
Writes (input_dim x num_frames) into internal output buffer; access via GetOutput(). Uses Eigen::Ref to accept matrices and block expressions without creating temporaries (real-time safe).
- Parameters:
input – Input matrix (input_dim x num_frames)
condition – Conditioning matrix (condition_dim x num_frames)
num_frames – Number of frames to process
-
inline void Process_(Eigen::Ref<Eigen::MatrixXf> input, const Eigen::Ref<const Eigen::MatrixXf> &condition, const int num_frames)
Process input with conditioning (in-place)
Uses Eigen::Ref to accept matrices and block expressions without creating temporaries (real-time safe). Modifies the input matrix directly.
- Parameters:
input – Input matrix (input_dim x num_frames), will be modified in-place
condition – Conditioning matrix (condition_dim x num_frames)
num_frames – Number of frames to process
-
inline FiLM(const int condition_dim, const int input_dim, const bool shift, const int groups = 1)