Optical Flow API
The optical-flow module has two public levels. SILVADEQFlow is a compact
flow-only equilibrium for quick custom experiments. SILVARAFTDEQ is the
coupled hidden-state/flow case connecting SILVA fixed points with RAFT
correlation [22] and DEQ-Flow
equilibrium framing [23].
For the source-to-package derivation and scope notes, see Method Adaptation Atlas.
Equations
The coordinate grid stores pixel coordinates
Given a flow field
silva_flow_warp(tensor, flow) samples the input at
For feature maps
the all-pairs correlation volume is
The local lookup samples a radius-\(r\) neighborhood around the current correspondence estimate:
The optical-flow DEQ transition is
and the solver seeks
The coupled RAFT case instead solves
Its feature/context residual encoder stages, dropout and output stride, correlation pyramid and radius, motion-branch widths, separated GRU, optional global motion aggregation, flow head, scaled learned convex upsampling, initialization, solver, gradient mode, indexed correction states, and cached fixed-point reuse are constructor parameters. Custom feature/context encoders and a custom update block can be injected without changing the solver contract.
Endpoint error is
The first-order smoothness penalty is
Minimal Run
from silva_networks import SolverConfig, make_silva_translation_flow_batch, silva_deq_flow
batch = make_silva_translation_flow_batch(height=16, width=16, shift=(1.0, 0.0))
model = silva_deq_flow(
in_channels=1,
feature_dim=8,
hidden_dim=12,
config=SolverConfig(solver="anderson", max_iter=12, alpha=0.5),
)
result = model(batch.image1, batch.image2, return_result=True)
assert result.flow.shape == batch.flow.shape
print(result.solver_result.converged, result.solver_result.residual)
Images have shape (batch, channels, height, width) and flow has shape
(batch, 2, height, width). Report endpoint error only after checking the
fixed-point residual and valid-pixel mask.
Citation Map
| Object family | Cite |
|---|---|
| all-pairs correlation and recurrent refinement | RAFT |
| equilibrium optical-flow framing | Deep Equilibrium Optical Flow Estimation |
| package-native implementation | SILVA paper/package |
| endpoint error and benchmark use | cite the optical-flow dataset or benchmark used |
Public Objects
| Object | Role |
|---|---|
SILVAFlowBatch |
image pair, target flow, and validity mask bundle |
SILVAFlowResult |
flow estimate plus solver diagnostics and optional correlation |
silva_coords_grid |
pixel coordinate grid |
silva_flow_warp |
bilinear flow warping |
silva_all_pairs_correlation |
RAFT-style all-pairs feature correlation |
silva_local_correlation_lookup |
local correlation sampling around current flow |
SILVAFlowFeatureEncoder |
compact feature encoder |
SILVAFlowUpdateBlock |
recurrent flow update block |
SILVADEQFlow |
preferred SILVA-style fixed-point optical-flow estimator |
silva_deq_flow |
preferred SILVA-style model factory |
SILVARAFTDEQ |
coupled hidden/flow RAFT and DEQ-Flow architecture |
SILVACorrelationPyramid |
multilevel all-pairs correlation and local lookup |
SILVARAFTEncoder |
configurable feature/context encoder |
SILVARAFTResidualBlock |
RAFT-style two-convolution residual encoder block |
SILVAGlobalMotionAggregator |
optional GMA-style global motion branch |
SILVASeparatedConvGRU |
horizontal/vertical recurrent update |
SILVARAFTUpdateBlock |
motion encoder, GRU, flow head, and upsampling mask |
SILVARAFTState |
reusable low-resolution hidden and flow state |
silva_flow_fixed_point_correction_loss |
weighted indexed-correction objective |
silva_raft_deq |
coupled architecture factory |
SILVAOpticalFlowDEQ |
compatibility name for the same estimator family |
silva_optical_flow_deq |
compatibility factory |
make_silva_translation_flow_batch |
synthetic translation batch for validation |
silva_endpoint_error |
endpoint error metric |
silva_flow_smoothness_loss |
first-order smoothness penalty |
API Docs
SILVA optical-flow modules based on equilibrium flow refinement.
This module combines all-pairs correlation, recurrent flow refinement, and fixed-point solution of a flow field through the SILVA transition interface.
References
- Silva, "SILVA Networks as Structured Implicit Layers and Vector Attractors via Dynamic Interaction Fields", 2026.
- Teed and Deng, "RAFT: Recurrent All-Pairs Field Transforms for Optical Flow", ECCV 2020.
- Bai, Geng, Savani, and Kolter, "Deep Equilibrium Optical Flow Estimation", CVPR 2022.
SILVACorrelationPyramid
RAFT all-pairs correlation pyramid with differentiable local lookup.
Source code in src/silva_networks/flow.py
SILVADEQFlow
Bases: SILVAOpticalFlowDEQ
SILVA-style public name for the optical-flow equilibrium layer.
This class is equivalent to SILVAOpticalFlowDEQ. The name emphasizes the
package convention: the model is a SILVA fixed-point flow estimator whose
lineage includes RAFT all-pairs correlation and DEQ-Flow equilibrium
solving.
Source code in src/silva_networks/flow.py
SILVAFlowBatch
dataclass
Synthetic or loaded optical-flow batch.
Attributes:
| Name | Type | Description |
|---|---|---|
image1 |
Tensor
|
First image tensor with shape |
image2 |
Tensor
|
Second image tensor with the same shape. |
flow |
Tensor
|
Ground-truth forward flow with shape |
valid |
Tensor | None
|
Optional validity mask with shape |
Source code in src/silva_networks/flow.py
to
Move all tensors to a PyTorch device.
Source code in src/silva_networks/flow.py
SILVAFlowFeatureEncoder
Bases: Module
Small feature encoder for SILVA optical-flow validation experiments.
Source code in src/silva_networks/flow.py
SILVAFlowResult
dataclass
Output from SILVAOpticalFlowDEQ.
Attributes:
| Name | Type | Description |
|---|---|---|
flow |
Tensor
|
Estimated flow with shape |
solver_result |
SolverResult
|
Fixed-point solver diagnostics. |
correlation |
Tensor | None
|
Optional all-pairs correlation volume. |
Source code in src/silva_networks/flow.py
SILVAFlowUpdateBlock
Bases: Module
RAFT-style recurrent update block for a SILVA flow field.
The block consumes the current flow, encoded image features, warped second features, residual features, and local all-pairs correlation lookups. It predicts a bounded flow increment.
Source code in src/silva_networks/flow.py
SILVAGlobalMotionAggregator
Bases: Module
Optional GMA-style global attention over motion features.
Source code in src/silva_networks/flow.py
SILVAOpticalFlowDEQ
Bases: Module
DEQ-Flow/RAFT-style optical-flow estimator ported to SILVA.
The model estimates a flow field \(u^\star\) by solving
where \(F_1,F_2\) are image features, \(C\) is an all-pairs correlation
volume, and \(\Delta_\theta\) is a convolutional update block. In practice,
damping from SolverConfig and the bounded tanh increment control the
finite solve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
Number of image channels. |
1
|
feature_dim
|
int
|
Feature encoder width. |
8
|
hidden_dim
|
int
|
Update block width. |
32
|
corr_radius
|
int
|
Local correlation lookup radius. |
1
|
update_scale
|
float
|
Scale applied to bounded flow increments. |
0.25
|
config
|
SolverConfig | None
|
Fixed-point solver configuration. |
None
|
reengage
|
bool
|
Whether to apply one differentiable transition after the numerical solve. |
True
|
Inputs
image1: Tensor with shape (batch, channels, height, width).
image2: Tensor with the same shape.
flow0: Optional initial flow with shape (batch, 2, height, width).
Output
Flow tensor, or SILVAFlowResult when return_result=True.
Source code in src/silva_networks/flow.py
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | |
transition
Return one RAFT-style SILVA flow-refinement step.
Source code in src/silva_networks/flow.py
SILVARAFTDEQ
Bases: Module
Coupled hidden-state/flow equilibrium adapted from RAFT and DEQ-Flow.
The solved SILVA state is (h, u) with transition
h_next = ConvGRU(h, context, motion(u, Corr(u))) and
u_next = u + delta_u(h_next).
Feature/context encoder widths, output stride, correlation levels/radius, GRU, GMA-style global aggregation, initialization, solver, gradient mode, cached fixed-point reuse, sparse correction states, and upsampling are all public parameters.
Source code in src/silva_networks/flow.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | |
SILVARAFTEncoder
Bases: Module
Configurable convolutional encoder for RAFT/DEQ-Flow features.
Source code in src/silva_networks/flow.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
SILVARAFTResidualBlock
Bases: Module
Two-convolution residual block used by RAFT feature encoders.
Source code in src/silva_networks/flow.py
SILVARAFTState
dataclass
SILVARAFTUpdateBlock
Bases: Module
RAFT motion encoder, recurrent hidden update, flow head, and upsampler mask.
Source code in src/silva_networks/flow.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
upsampling_mask
Predict the convex upsampling mask from a recurrent state.
SILVASeparatedConvGRU
Bases: Module
Horizontal/vertical convolutional GRU used by RAFT update blocks.
Source code in src/silva_networks/flow.py
make_silva_translation_flow_batch
make_silva_translation_flow_batch(*, batch_size=2, channels=1, height=16, width=16, shift=(1.0, 0.0), noise=0.0, device=None, dtype=torch.float32)
Create a small synthetic optical-flow batch.
The second image is generated by translating the first image. The stored
flow is the forward displacement from image1 to image2, using (dx, dy)
channel order.
Source code in src/silva_networks/flow.py
silva_all_pairs_correlation
Compute a RAFT-style all-pairs correlation volume.
For feature maps \(F_1,F_2\in\mathbb R^{B\times C\times H\times W}\), the correlation is
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmap1
|
Tensor
|
First feature map with shape |
required |
fmap2
|
Tensor
|
Second feature map with the same shape. |
required |
normalize_features
|
bool
|
If true, L2-normalize channel vectors before the dot product. |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor with shape |
Source code in src/silva_networks/flow.py
silva_coords_grid
Create a pixel coordinate grid with channels (x, y).
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor with shape |
Source code in src/silva_networks/flow.py
silva_deq_flow
silva_deq_flow(*, in_channels=1, feature_dim=8, hidden_dim=32, corr_radius=1, update_scale=0.25, config=None, reengage=True, encoder_module=None, update_block=None, transition_module=None)
Create a SILVA DEQ-flow model.
This is the preferred SILVA-style factory. The older
silva_optical_flow_deq name remains available for compatibility.
Source code in src/silva_networks/flow.py
silva_endpoint_error
Compute optical-flow endpoint error.
Source code in src/silva_networks/flow.py
silva_flow_fixed_point_correction_loss
Exponentially weighted sparse fixed-point correction loss.
Source code in src/silva_networks/flow.py
silva_flow_smoothness_loss
First-order smoothness penalty for flow fields.
Source code in src/silva_networks/flow.py
silva_flow_warp
Warp tensor by a pixel-space flow field.
The output at pixel \(p=(x,y)\) samples the input at \(p+u(p)\), where
\(u=(u_x,u_y)\) is stored in flow[:, 0] and flow[:, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
Image or feature tensor with shape |
required |
flow
|
Tensor
|
Flow tensor with shape |
required |
padding_mode
|
Literal['zeros', 'border', 'reflection']
|
Passed to |
'border'
|
align_corners
|
bool
|
Passed to |
True
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Warped tensor with the same shape as |
Source code in src/silva_networks/flow.py
silva_local_correlation_lookup
Sample local correlation neighborhoods around current flow estimates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
correlation
|
Tensor
|
All-pairs correlation with shape |
required |
flow
|
Tensor
|
Flow tensor with shape |
required |
radius
|
int
|
Lookup radius in pixels. |
2
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor with shape |
Source code in src/silva_networks/flow.py
silva_optical_flow_deq
silva_optical_flow_deq(*, in_channels=1, feature_dim=8, hidden_dim=32, corr_radius=1, update_scale=0.25, config=None, reengage=True, encoder_module=None, update_block=None, transition_module=None)
Create a SILVA optical-flow DEQ model.
Source code in src/silva_networks/flow.py
Where to Go Next
| Question | Page |
|---|---|
| How is the flow equilibrium derived? | DEQ Engine and Optical Flow |
| Where is the compact flow model executed? | Optical Flow SILVA Example |
| Where is the coupled recurrent state executed? | RAFT and DEQ-Flow Example |