FlowLoss<T>
Models & Types · AiDotNet.LossFunctions
Optical-flow consistency loss: penalizes a reconstruction whose MOTION differs from the ground truth’s motion, even where individual frames already match.
Inheritance: LossFunctionBase<T> → FlowLoss<T>
For Beginners
comparing video frames one at a time cannot detect flicker — every frame can be individually close to the target while the sequence still jitters. This loss measures the apparent motion between consecutive frames (the “optical flow”) for both the reconstruction and the ground truth, and penalizes the difference. It therefore constrains how things MOVE, not just how they look.
How It Works
Definition. For each adjacent frame pair,
|| OF(x_t^rec, x_{t-1}^rec) - OF(x_t^GT, x_{t-1}^GT) ||_2^2, as specified by Stream-DiffVSR
(Shiu et al., 2025) for its temporal-decoder objective, where the paper states the flow is computed
“using RAFT”. The ground-truth flow is a constant target, so it is detached from the tape; gradients
reach the reconstruction through the flow estimator’s inputs.
The estimator is frozen. The flow network is a measuring instrument, not something being
trained: its parameters are never registered with the model being optimized, so an optimizer walking
the model’s parameters cannot touch them. Any of the library’s optical-flow models can be
substituted; RAFT is the default because it is what the paper specifies.
Usage:
Example
using AiDotNet.LossFunctions;
using AiDotNet.Tensors.LinearAlgebra;
var loss = new FlowLoss<float>();
var predicted = new Vector<float>(new[] { 0.9f, 0.2f, 0.7f });
var actual = new Vector<float>(new[] { 1.0f, 0.0f, 1.0f });
float value = loss.CalculateLoss(predicted, actual);
Console.WriteLine($"FlowLoss = {value:F4}");
Constructors
| Constructor | Summary |
|---|---|
FlowLoss(OpticalFlowBase<T> flowEstimator) |
Creates the flow-consistency loss. |
Properties
| Property | Summary |
|---|---|
OpticalFlowBase<T> FlowEstimator { get; } |
Gets the optical-flow model used to measure motion. |
Methods
| Method | Summary |
|---|---|
T CalculateLoss(Vector<T> predicted, Vector<T> actual) |
|
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target) |