Skip to content

Optical Flow SILVA

Run:

python examples/optical_flow_silva.py

This example builds a synthetic translated image pair, estimates a flow field with SILVADEQFlow, computes endpoint error, adds a smoothness penalty, and checks that gradients reach the update block.

Synthetic Batch

The helper creates:

\[ I_1,I_2\in\mathbb R^{B\times C\times H\times W}, \qquad u_{\rm target}\in\mathbb R^{B\times 2\times H\times W}. \]

The second image is generated by translating the first image by

\[ u=(0.75,0.25). \]
batch = make_silva_translation_flow_batch(
    batch_size=1,
    channels=1,
    height=12,
    width=12,
    shift=(0.75, 0.25),
)

Flow Fixed Point

The model computes features

\[ F_1=E_\psi(I_1), \qquad F_2=E_\psi(I_2), \]

then builds all-pairs correlation

\[ C_{b,i,j,k,\ell} = \frac{ \langle F_{1,b,:,i,j},F_{2,b,:,k,\ell}\rangle }{\sqrt C}. \]

The flow transition is

\[ T_\theta(u) = u+\gamma\tanh\Delta_\theta(u,F_1,F_2,C). \]

The solver seeks

\[ u^\star=T_\theta(u^\star). \]

In code:

model = silva_deq_flow(
    feature_dim=4,
    hidden_dim=12,
    corr_radius=1,
    config=SolverConfig(solver="picard", max_iter=4, alpha=0.4),
)

result = model(batch.image1, batch.image2, return_result=True)

Loss

Endpoint error is

\[ \operatorname{EPE} = \|u^\star-u_{\rm target}\|_2. \]

The smoothness penalty is

\[ \mathcal L_{\rm smooth} = \sum_p \left( |u(p+\hat x)-u(p)|+ |u(p+\hat y)-u(p)| \right). \]

The example uses

\[ \mathcal L = \operatorname{EPE} +0.01\mathcal L_{\rm smooth}. \]

What to Inspect

Field Meaning
flow_shape predicted flow tensor shape
iterations fixed-point solver iterations
residual final flow fixed-point residual
endpoint_error flow error on the valid translated region
has_grad whether gradients reached the update block

Use Optical Flow API for the complete object and equation map.

Citations

Cite SILVA [1] for this package-native implementation, RAFT [22] for all-pairs correlation and recurrent refinement lineage, and DEQ-Flow [23] when discussing the equilibrium optical-flow framing.

Direct source links are collected in DEQ Engines and Optical Flow.

Complete Worked Study

The short construction above identifies the main API. A complete study must also distinguish the state equation, task objective, numerical residual, gradient path, and scale transfer. In this example, the equilibrium state is the flow field, optionally coupled to a recurrent hidden state, the condition is image features, correlation volumes, context, and initial flow, and the repeated map is the tied correlation-conditioned refinement update.

Derivation From Transition to Reported Result

The forward solve is defined by

\[ z^\star = T_\theta(z^\star,x). \]

The task output and task objective are separate from convergence:

\[ \widehat y = R_\phi(z^\star), \qquad \mathcal L_{\mathrm{task}}=\ell(\widehat y,y). \]

For a computed state \(z_K\), the normalized fixed-point residual is

\[ r_K = \frac{\lVert T_\theta(z_K,x)-z_K\rVert_2} {\lVert z_K\rVert_2+\varepsilon}. \]

A small task loss does not imply a small \(r_K\), and a small \(r_K\) does not establish task quality. Both belong in the result. For implicit training, the parameter sensitivity follows

\[ \frac{\mathrm d z^\star}{\mathrm d\theta} = \left(I-\partial_z T_\theta(z^\star,x)\right)^{-1} \partial_\theta T_\theta(z^\star,x). \]

This is why the example checks gradients in addition to forward convergence. The reader-facing evidence for this route is flow shape, endpoint error, iterations, residual, and gradients. The invariants that must remain true are flow shape, coordinate convention, image resolution, and warping domain.

Run the Complete Example

python examples/optical_flow_silva.py

Measured Compact Output

The following output was produced by the executable program in the current repository. Floating-point values may vary slightly across devices and library builds, while shapes, finite values, invariants, and declared tolerances must remain stable.

{'device': 'cpu', 'flow_shape': (1, 2, 12, 12), 'iterations': 4, 'residual': 0.32843607664108276, 'endpoint_error': 0.7464414238929749, 'has_grad': True}

Interpret the Output

Evidence What it answers What would require investigation
Tensor shapes Did every source, state, branch, and readout preserve its declared contract? A changed entity, channel, token, or spatial dimension
Task metric Did the compact task execute and produce finite evidence? Non-finite loss, a missing mask, or a metric computed on the wrong split
Fixed-point residual Did the returned state satisfy the repeated transition to the requested tolerance? A residual plateau, rising trajectory, or convergence flag inconsistent with the value
Iteration or trajectory data How much numerical work was required? Solver effort that grows sharply under a small input or resolution change
Gradient evidence Can the loss reach every trainable component through the selected backward mode? Missing, non-finite, or implausibly large gradients
Domain invariant Did the method retain positivity, feasibility, boundary values, permutation behavior, or another structural requirement? A task metric that looks acceptable while the structural contract fails

The compact output is a mechanism check, not a paper-scale benchmark claim. It shows that data enter the intended construction, the transition executes, the solver returns diagnostics, and differentiation reaches trainable parameters.

Add a Solver and Scale Sweep

The next run should hold model parameters and data fixed while changing one numerical control at a time. A complete experiment record can use this schema:

experiment:
  example: optical-flow-silva
  state: the flow field, optionally coupled to a recurrent hidden state
  condition: image features, correlation volumes, context, and initial flow
  repeated_transition: the tied correlation-conditioned refinement update
  invariant_checks: flow shape, coordinate convention, image resolution, and warping domain
  compact_evidence: flow shape, endpoint error, iterations, residual, and gradients
  scale_axes: image resolution, correlation radius/levels, hidden width, and solver budget
solver_sweep:
  methods: [picard, anderson, broyden]
  tolerances: [1.0e-4, 1.0e-6, 1.0e-8]
  maximum_iterations: [25, 50, 100]
report:
  - task_metric
  - fixed_point_residual
  - backward_linear_residual
  - iterations
  - wall_time
  - peak_memory
  - gradient_norm

At full scale, move toward Sintel, KITTI Flow, or FlyingChairs with the source preprocessing protocol. Increase only one of image resolution, correlation radius/levels, hidden width, and solver budget at a time. Retain this compact run as a regression test, preserve the source split and preprocessing receipt, archive the resolved configuration and checkpoint, and report convergence failures rather than discarding them.

Where to Go Next

Question Page
How is equilibrium optical flow connected to the SILVA transition? DEQ Engine and Optical Flow
Which compact flow objects are public? Optical Flow API
Where is the coupled recurrent flow state implemented? RAFT and DEQ-Flow Example