MegaFlow (fastforks)
MegaFlow (Zhang, Wang, Pollefeys, Xu, ECCV 2026): zero-shot large-displacement optical flow from a video transformer. The frames are resized to width 952 for a DINOv2 ViT-L/14 + 24 alternating frame / global attention blocks (VGGT's aggregator); a DPT head fuses four of its layers with a ResNet34 CNN into 128-channel features, a global softmax correlation gives the initial flow, and RAFT-style updates on 9 x 9 local correlations of the CNN's 1/4 features refine it (convex 4x upsampling). The authors' released megaflow-flow weights; the network is ported from cvg/megaflow. A pair runs as upstream's two-frame clip. Paper: state-of-the-art zero-shot results on Sintel, KITTI and Spring.
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/cvg/megaflow at 2328f8bb2690.
Author weight repos: https://huggingface.co/Kristen-Z/MegaFlow.
Task: flow. Tier: experimental. Outputs: flow. Backends: portable, kernels.
Input: two RGB images (consecutive frames). Output: per-pixel motion from the first to the second (dx, dy in pixels).
Variants
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
megaflow@1 |
megaflow-flow.safetensors | 6b8524bdce14 |
Apache-2.0 | yes |
Licence
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Licence files: LICENSE.
Training data: FlyingChairs (Freiburg), TartanAir, Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa), MPI Sintel optical flow, KITTI stereo / optical flow 2012 / 2015, HCI HD1K optical flow benchmark (FlyingChairs, FlyingThings3D (part of SceneFlow), TartanAir, then a mix with Sintel, KITTI 2015 and HD1K, as upstream's README lists the training datasets).
Licence evidence: https://huggingface.co/Kristen-Z/MegaFlow/blob/b4c5c33800b8fa88e047d2eb70ae74b0feca606d/README.md
Input size
any H x W >= 64, padded to a multiple of 8
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): megaflow 1080x1920 (3.0 GiB peak allocated, 3.2 reserved)
Speed and memory
Flow, synthetic
| model | input | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|---|---|---|---|---|---|---|---|---|---|---|
megaflow |
1080x1920 | β | 1588 | 1109 | 734 | 2.2x | 1.5x | 8230 / 8786 | 3035 / 3246 | 2866 / 3066 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
megaflow |
9.56 | 1.96 (375x1242) | 7.10 (375x1242) | 6.77 | 0.76 (375x1242) | 0.67 (375x1242) |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
Accuracy
On public datasets
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 | kernels | note |
|---|---|---|---|---|---|---|
megaflow |
KITTI 2015 train, EPE / Fl-all % | 1.714 / 6.68 | 1.727 / 6.75 | 1.715 / 6.69 | 1.714 / 6.69 | trained on this dataset's public images; not a zero-shot result |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 790d5f2f, 2026-11-14.
Parity with the original code
Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.003 and p99 <= 0.008 (absolute error of the output flow).
Limitations
- Pairs only: upstream's multi-frame clips (temporal attention across more than two frames) and its point-tracking and chairs-things checkpoints are not exposed.
Usage
from fastforks import flow
model = flow.load("megaflow") # mode="auto": the preferred backend from recorded measurements
result = model("frame1.png", "frame2.png")
result.flow # [2, H, W] float32 tensor: dx, dy in input pixels
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: megaflow.
Kernels backend
flow.load("megaflow", mode="kernels") runs our CUDA kernels (fastbb, cudnn_hacc, raft_flow). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.