MemFlow
MemFlow (Dong and Fu, CVPR 2024): optical flow with a motion memory, a RAFT-style network whose update step also reads attention over the frame's motion features. Apache-2.0 code and weights; some training sets are research-only.
experimental Fork of DQiaole/MemFlow@5486fb8 · backends: portable, kernels
- Paper MemFlow: Optical Flow Estimation and Prediction with Memory CVPR 2024 · first released 7 Apr 2024
Paper 2024 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import flow
model = flow.load("memflow") # kernels on a supported GPU, else portable PyTorch
result = model(frame1, frame2)
result.flow
result.backend # what ran: mode, device, dtype, kernels fastforks bench memflow Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16torch.autocast(float16) around the call; upstream MemFlowNet configs/things_memflownet.py, InferenceCore.step(end=True) per pair | fp16 | 3116 | – | 14.7 GiB/15.2 GiB | 0.2 | 3.82 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 964 | 3.2× | 8,265 MiB/8,382 MiB | 0.1 | 0.97 |
| Kernels | fp16 | 865 | 3.6× | 968 MiB/1,022 MiB | 1.2 | 0.88 |
| Portable + torch.compile | 1642 | 1.9× | 6,813 MiB/6,946 MiB | 79 (build) | – | |
| TensorRTTensorRT engine build failed | fails | – | – | – | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-13 | Original | fp32 | out of memory | – | 1080x1920 | |
| Portable | fp32 | 10016 | 12.4 GiB process | matches | 1080x1920 | |
| Kernels | fp16 | not implemented | – | 1080x1920 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- Apache-2.0 LICENSE
- Weights
- Apache-2.0 source
- Training data
-
- FlyingChairs (Freiburg) research-only, non-commercial
- Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa) research-only, non-commercial
Our reading of the licences, not legal advice.
Weights
MemFlowNet_things.pth 25.4 MB· hosted on GitHubfastforks downloads and checks these files on first use (fastforks download memflow).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
KITTI 2015 train
EPE / Fl-all %
| Run | dtype | EPE ↓ | Fl-all % ↓ | Δ EPE vs fp32 original | pairs | ms / pair |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 4.108 | 14.43 | reference | 200 | 314 |
| Original fp16 | fp16 | 4.107 | 14.43 | +0.001 | 200 | 256 |
| Portable fp32 | fp32 | 4.093 | 14.43 | +0.015 | 200 | 259 |
| Portable | fp16 | 4.109 | 14.44 | −0.000 | 200 | 145 |
| Kernels | fp16 | 4.103 | 14.42 | +0.005 | 200 | 141 |
Frames _10 -> _11 at full size against the flow_occ ground truth; EPE = mean of the per-pair mean end-point error, Fl-all = share of all valid pixels with an error > 3 px and > 5 % of the GT magnitude. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 6f0a70e1, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks db9e79d5+unc, 2026-11-13.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 4.2e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0018 and p99 <= 0.0065 (absolute error of the output flow).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.000042 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.0018 | 0.00089 |
| GPU default dtypes, p99 |diff| | ≤ 0.0065 | 0.00347 |
Recorded for memflow on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: raft_flow
Details
MemFlow (Dong & Fu, CVPR 2024): optical flow with a memory of past motion. A RAFT-style network at 1/8 resolution: BasicEncoder feature and context networks, an all-pairs correlation pyramid, a motion encoder and update block of depthwise-separable large-kernel blocks (SKFlow) instead of a GRU, and an attention readout of the motion features of memory frames; convex 8x upsampling. The authors' released weights; the network is ported from DQiaole/MemFlow. A pair (image1, image2) runs as upstream's first frame of a video (empty memory: the readout attends over the pair's own motion features). Paper (video with memory, val_decoder_depth 15): Sintel test EPE 1.05 (clean) / 1.91 (final), KITTI 2015 test Fl-all 4.10 %.
- Input / output
- Input: two RGB images (consecutive frames). Output: per-pixel motion from the first to the second (dx, dy in pixels).
- Input size
- any H x W >= 128, padded to a multiple of 8; tested up to 1024x2048 (8,440 MiB allocated)
- Options
iters=15>= 1· changes the output
- Outputs
flow- CUDA kernels
raft_flowRAFT optical flow kernels
- Apple (MPS)
- fp32
Limitations
- Pairs only: the video memory (the keys and values of earlier frames that upstream's inference keeps) is not exposed; each pair runs as the first frame of a video.
- The MemFlow-T checkpoints (Twins-SVT encoders) and MemFlow-P (flow prediction) are not ported.
Full reference, generated from the repository
MemFlow (Dong and Fu, CVPR 2024): optical flow with a motion memory, a RAFT-style network whose update step also reads attention over the frame's motion features. Apache-2.0 code and weights; some training sets are research-only.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
memflow | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 3116 964 865 1642 fails: TensorRT engine build failed | 15061 / 15594 8265 / 8382 968 / 1022 6813 / 6946 – |
memflow-sintel | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 3214 964 865 1640 fails: TensorRT engine build failed | 15061 / 15634 8265 / 8382 968 / 1022 6813 / 6946 – |
memflow-kitti | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 3247 965 865 1644 fails: TensorRT engine build failed | 15061 / 15594 8265 / 8382 968 / 1022 6813 / 6946 – |
Details
- Original code: https://github.com/DQiaole/MemFlow at
5486fb88a55b - Code licence: Apache-2.0 (permissive); files:
LICENSE - Weights licence: Apache-2.0
- Licence evidence: https://github.com/DQiaole/MemFlow/blob/5486fb88a55b04c2e2b292b3abaa7641d9988831/LICENSE
- Training data: FlyingChairs (Freiburg), Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa) (FlyingThings3D (part of SceneFlow), starting from SKFlow's FlyingChairs + FlyingThings3D checkpoint, as upstream's train.sh)
memflow-sintel: FlyingChairs (Freiburg), Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa), MPI Sintel optical flow, KITTI stereo / optical flow 2012 / 2015, HCI HD1K optical flow benchmark (as memflow, then fine-tuned on a mix of FlyingThings3D, Sintel, KITTI 2015 and HD1K (upstream stage 'sintel'))memflow-kitti: FlyingChairs (Freiburg), Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa), MPI Sintel optical flow, KITTI stereo / optical flow 2012 / 2015, HCI HD1K optical flow benchmark (as memflow-sintel, then fine-tuned on KITTI 2015)
- Options:
iters= 15 (>= 1) - Kernel libraries:
raft_flow - Variants:
memflow,memflow-sintel,memflow-kitti - Outputs: flow
- Input size: any H x W >= 128, padded to a multiple of 8
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
memflow1024x2048 (8.2 GiB peak allocated, 9.2 reserved);memflow-sintel1024x2048 (8.2 GiB peak allocated, 9.2 reserved);memflow-kitti1024x2048 (8.2 GiB peak allocated, 9.2 reserved) memflow1080x1920, first call: portable + torch.compile 79 s (cold Inductor cache).memflow-sintel1080x1920, first call: portable + torch.compile 76 s (cold Inductor cache).memflow-kitti1080x1920, first call: portable + torch.compile 73 s (cold Inductor cache).memfloworiginal 1080x1920: torch.autocast(float16) around the call; upstream MemFlowNet configs/things_memflownet.py, InferenceCore.step(end=True) per pairmemflow-sinteloriginal 1080x1920: torch.autocast(float16) around the call; upstream MemFlowNet configs/sintel_memflownet.py, InferenceCore.step(end=True) per pairmemflow-kittioriginal 1080x1920: torch.autocast(float16) around the call; upstream MemFlowNet configs/kitti_memflownet.py, InferenceCore.step(end=True) per pairmemflowload / first call: original 0.16 s / 3.824 s, portable 0.06 s / 0.975 s, kernels 1.18 s / 0.878 smemflow-sintelload / first call: original 0.14 s / 3.061 s, portable 0.1 s / 0.979 s, kernels 0.95 s / 0.876 smemflow-kittiload / first call: original 0.14 s / 3.061 s, portable 0.14 s / 0.976 s, kernels 0.97 s / 0.876 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
Frames _10 -> _11 at full size against the flow_occ ground truth; EPE = mean of the per-pair mean end-point error, Fl-all = share of all valid pixels with an error > 3 px and > 5 % of the GT magnitude. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
memflow | KITTI 2015 train, EPE / Fl-all % | 4.108 / 14.43 | 4.107 / 14.43 | 4.109 / 14.44 | 4.093 / 14.43 | 4.103 / 14.42 | |
memflow-kitti | KITTI 2015 train, EPE / Fl-all % | 0.600 / 1.21 | 0.600 / 1.21 | 0.600 / 1.21 | 0.600 / 1.21 | 0.600 / 1.21 | trained on this dataset's public images; not a zero-shot result |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks db9e79d5+uncommitted, 2026-11-13; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 6f0a70e1, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks db9e79d5+uncommitted, 2026-11-13.
Parity
CPU, float32: max |diff| <= 4.2e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0018 and p99 <= 0.0065 (absolute error of the output flow).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
memflow | 0.00089 / 0.00347 | RTX 5060 Ti, torch 2.14.1+cu130 | raft_flow@a101a33607b6:sm_120 |
memflow-sintel | 0.00072 / 0.00354 | RTX 5060 Ti, torch 2.14.1+cu130 | raft_flow@a101a33607b6:sm_120 |
memflow-kitti | 0.00106 / 0.00435 | RTX 5060 Ti, torch 2.14.1+cu130 | raft_flow@a101a33607b6:sm_120 |
Limitations
- Pairs only: the video memory (the keys and values of earlier frames that upstream's inference keeps) is not exposed; each pair runs as the first frame of a video.
- The MemFlow-T checkpoints (Twins-SVT encoders) and MemFlow-P (flow prediction) are not ported.
Example output
No example rendered for this checkpoint yet.