Models · Optical flow

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

Checkpoint

Paper 2024 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 865 ms 1080x1920, fp16
vs the faster original 3.6× original fp16: 3116 ms
Peak memory 968 MiB original: 14.7 GiB
Accuracy vs original fp32 +0.005 kernels EPE, KITTI 2015 train (4.108 original)

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.

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16torch.autocast(float16) around the call; upstream MemFlowNet configs/things_memflownet.py, InferenceCore.step(end=True) per pairfp16 3116–14.7 GiB/15.2 GiB0.23.82
Portable fp32fp32not measured ––––
Portablefp16 9643.2×8,265 MiB/8,382 MiB0.10.97
Kernelsfp16 8653.6×968 MiB/1,022 MiB1.20.88
Portable + torch.compile 16421.9×6,813 MiB/6,946 MiB79 (build)–
TensorRTTensorRT engine build failedfails––––

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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-13Originalfp32out of memory–1080x1920
Portablefp3210016 12.4 GiB processmatches1080x1920
Kernelsfp16not 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

Our reading of the licences, not legal advice.

Weights

MemFlowNet_things.pth 25.4 MB· hosted on GitHub

fastforks 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 %

RundtypeEPE ↓Fl-all % ↓Δ EPE vs fp32 originalpairsms / pair
Original fp32fp324.10814.43 reference 200 314
Original fp16fp164.10714.43 +0.001 200 256
Portable fp32fp324.09314.43 +0.015 200 259
Portablefp164.10914.44 −0.000 200 145
Kernelsfp164.10314.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).

CheckToleranceMeasured
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.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
memflowsynthetic (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-sintelsynthetic (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-kittisynthetic (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): memflow 1024x2048 (8.2 GiB peak allocated, 9.2 reserved); memflow-sintel 1024x2048 (8.2 GiB peak allocated, 9.2 reserved); memflow-kitti 1024x2048 (8.2 GiB peak allocated, 9.2 reserved)
  • memflow 1080x1920, first call: portable + torch.compile 79 s (cold Inductor cache).
  • memflow-sintel 1080x1920, first call: portable + torch.compile 76 s (cold Inductor cache).
  • memflow-kitti 1080x1920, first call: portable + torch.compile 73 s (cold Inductor cache).
  • memflow original 1080x1920: torch.autocast(float16) around the call; upstream MemFlowNet configs/things_memflownet.py, InferenceCore.step(end=True) per pair
  • memflow-sintel original 1080x1920: torch.autocast(float16) around the call; upstream MemFlowNet configs/sintel_memflownet.py, InferenceCore.step(end=True) per pair
  • memflow-kitti original 1080x1920: torch.autocast(float16) around the call; upstream MemFlowNet configs/kitti_memflownet.py, InferenceCore.step(end=True) per pair
  • memflow load / first call: original 0.16 s / 3.824 s, portable 0.06 s / 0.975 s, kernels 1.18 s / 0.878 s
  • memflow-sintel load / first call: original 0.14 s / 3.061 s, portable 0.1 s / 0.979 s, kernels 0.95 s / 0.876 s
  • memflow-kitti load / 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.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
memflowKITTI 2015 train, EPE / Fl-all %4.108 / 14.434.107 / 14.434.109 / 14.444.093 / 14.434.103 / 14.42
memflow-kittiKITTI 2015 train, EPE / Fl-all %0.600 / 1.210.600 / 1.210.600 / 1.210.600 / 1.210.600 / 1.21trained 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).

variantkernels error vs original, mean / p99GPU, torchkernels used
memflow0.00089 / 0.00347RTX 5060 Ti, torch 2.14.1+cu130raft_flow@a101a33607b6:sm_120
memflow-sintel0.00072 / 0.00354RTX 5060 Ti, torch 2.14.1+cu130raft_flow@a101a33607b6:sm_120
memflow-kitti0.00106 / 0.00435RTX 5060 Ti, torch 2.14.1+cu130raft_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.