NMRF
A stereo network from the CUHK T-Stone Robotics Institute that treats matching as Markov random field inference.
stable Fork of aeolusguan/NMRF@a50bd8f · backends: portable, kernels
- Paper Neural Markov Random Field for Stereo Matching CVPR 2024 · first released 17 Mar 2024
Checkpoint nmrf-sceneflow
Paper 2024 Added in 0.1.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 stereo
model = stereo.load("nmrf-sceneflow") # kernels on a supported GPU, else portable PyTorch
result = model(left, right)
result.disparity
result.backend # what ran: mode, device, dtype, kernels fastforks bench nmrf-sceneflow 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 | 445 | 0.70× | 2,300 MiB/2,426 MiB | – | – |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 313 | – | 1,656 MiB/2,054 MiB | – | – |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 216 | 1.4× | 1,510 MiB/1,552 MiB | 0.1 | 0.22 |
| Kernels | fp16 | 196 | 1.6× | 1,022 MiB/1,112 MiB | 0.1 | 0.20 |
| Portable + torch.compile | 161 | 1.9× | 854 MiB/1,104 MiB | 85 (build) | – | |
| TensorRT fp16 | fp16 | 184 | 1.7× | 826 MiBenginenot comparable | 143 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-01 to 2026-11-03. Median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls. 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-14 | Original | fp32 | 1736 | 7,232 MiB process | matches | 994x1482 |
| Portable | fp16 | 1469 | 4,747 MiB process | matches | 994x1482 | |
| Portable | fp32 | 1560 | 5,749 MiB process | matches | 994x1482 | |
| Kernels | fp16 | 1204 | 3,806 MiB process | matches | 994x1482 | |
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 282 | 1,457 MiB/1,630 MiB | – | 994x1482 |
| Kernels | fp16 | 239 | 969 MiB/1,090 MiB | – | 994x1482 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 79.4 | 1,457 MiB/1,630 MiB | – | 994x1482 |
| Kernels | fp16 | 64.6 | 969 MiB/1,090 MiB | – | 994x1482 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 196 | 1,457 MiB/1,630 MiB | – | 994x1482 |
| Kernels | fp16 | 173 | 969 MiB/1,090 MiB | – | 994x1482 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 93.6 | 1,457 MiB/1,630 MiB | – | 994x1482 |
| Kernels | fp16 | 84.4 | 969 MiB/1,090 MiB | – | 994x1482 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 43.1 | 1,481 MiB/1,630 MiB | – | 994x1482 |
| Kernels | fp16 | 37.7 | 993 MiB/1,110 MiB | – | 994x1482 |
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
- MIT LICENSE
- Weights
- MIT (assumed from code)(not stated by the authors; assumed to follow the code) source
- Training data
-
- Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa) research-only, non-commercial
- weights licence not stated by the original authors; assumed to be the code licence
Our reading of the licences, not legal advice.
Weights
sceneflow.pth 24.6 MB· hosted on Google Drivefastforks downloads and checks these files on first use (fastforks download nmrf-sceneflow).
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.
ETH3D two-view train
bad > 1 px % / EPE
| Run | dtype | bad px % ↓ | EPE ↓ | Δ bad px % vs fp32 original | pairs | ms / pair |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 3.78 | 0.311 | reference | 27 | 95.9 |
| Original fp16 | fp16 | 3.81 | 0.313 | −0.03 | 27 | 61.9 |
| Portable fp32 | fp32 | 3.78 | 0.311 | ±0.00 | 27 | 90.0 |
| Portable | fp16 | 3.81 | 0.311 | −0.03 | 27 | 50.1 |
| Kernels | fp16 | 3.81 | 0.311 | −0.03 | 27 | 41.2 |
| Original .half() | fp16 | fails: RuntimeError: expected scalar type Float but found Half | ||||
Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16, original .half(): RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-05; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 468fba10, 2026-11-05.
Middlebury 2014 trainingH
bad > 2 px % / EPE
| Run | dtype | bad px % ↓ | EPE ↓ | Δ bad px % vs fp32 original | pairs | ms / pair |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 13.36 | 2.920 | reference | 15 | 380 |
| Original fp16 | fp16 | 13.35 | 2.914 | +0.01 | 15 | 264 |
| Portable fp32 | fp32 | 13.36 | 2.921 | ±0.00 | 15 | 345 |
| Portable | fp16 | 13.35 | 2.915 | +0.01 | 15 | 189 |
| Kernels | fp16 | 13.35 | 2.915 | +0.01 | 15 | 168 |
| Original .half() | fp16 | fails: RuntimeError: expected scalar type Float but found Half | ||||
Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16, original .half(): RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-05; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 468fba10, 2026-11-05.
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| <= 0.05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.05 px and p99 <= 0.5 px.
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.05 px | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.05 px | 0.00236 px |
| GPU default dtypes, p99 |diff| | ≤ 0.5 px | 0.03745 px |
| real_gpu_mean | ≤ 0.1 px | not recorded |
| real_gpu_p99 | ≤ 1.5 px | not recorded |
Recorded for nmrf-sceneflow on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-01, with these kernels: fastbb
Details
NMRF (Guan et al. 2024): neural Markov random field with disparity proposals from a group-wise cost volume, CSWin label-seed propagation and window-attention inference at 1/8 resolution plus a 1/4 refinement.
- Input / output
- Input: a rectified left / right image pair. Output: a disparity map (pixels, left view).
- Input size
- any H x W >= 9, padded to a multiple of 8; tested up to 3000x4000 (11.0 GiB allocated)
- Outputs
disparity- CUDA kernels
fastbbfast backbone kernels: flash attention, window attention, instance norm and rotary embeddings for ViT and similar backbones
- Apple (MPS)
stereo_metalMetal: stereo kernels. fp32, fp16
Limitations
- ONNX Runtime resolves top-k ties differently from PyTorch on noise pairs: nmrf-sceneflow differs by up to 0.56 px (mean 0.006) on a synthetic textured pair.
Full reference, generated from the repository
A stereo network from the CUHK T-Stone Robotics Institute that treats matching as Markov random field inference.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
nmrf-sceneflow | Middlebury 2014 half (994x1482) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 445 313 216 196 161 184 | 2300 / 2426 1656 / 2054 1510 / 1552 1022 / 1112 854 / 1104 1027 / 1134 |
Details
- Original code: https://github.com/aeolusguan/NMRF at
a50bd8f407ae - Code licence: MIT (permissive); files:
LICENSE - Weights licence: MIT (assumed from code)
- Licence evidence: https://github.com/aeolusguan/NMRF/blob/a50bd8f407ae481c38f95cf141e1b5256e962cb7/README.md#L103
- Training data: Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa)
- Kernel libraries:
fastbb - Variants:
nmrf-sceneflow - Outputs: disparity
- Input size: any H x W >= 9, padded to a multiple of 8
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
nmrf-sceneflow3000x4000 (11.0 GiB peak allocated, 13.3 reserved) nmrf-sceneflow994x1482, first call: portable + torch.compile 85 s (cold Inductor cache), TensorRT fp16 142 s (ONNX + engine).nmrf-scenefloworiginal 994x1482: torch.autocast(fp16) around the forwardnmrf-sceneflowload / first call: original 0.21 s / 0.766 s (375x1242), portable 0.1 s / 0.218† s, kernels 0.07† s / 0.197† s- † measured in the speed sweep after the portable load (or an earlier size) in the same process: file cache and kernels are warm, so the time is lower than a fresh start.
- Protocol, median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls
Measured
Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | original half | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|---|
nmrf-sceneflow | ETH3D two-view train, bad > 1 px % / EPE | 3.78 / 0.311 | 3.81 / 0.312 | fails (RuntimeError: expected scalar type Float but found Half) | 3.81 / 0.311 | 3.78 / 0.311 | 3.81 / 0.311 | |
nmrf-sceneflow | Middlebury 2014 trainingH, bad > 2 px % / EPE | 13.36 / 2.920 | 13.35 / 2.914 | fails (RuntimeError: expected scalar type Float but found Half) | 13.35 / 2.915 | 13.36 / 2.921 | 13.35 / 2.915 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 468fba10, 2026-11-05.
Parity
CPU, float32: max |diff| <= 0.05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.05 px and p99 <= 0.5 px. On real pairs up to 720x1280 the limits are mean 0.1 / p99 1.5 (precision-sensitive there, see Limitations).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
nmrf-sceneflow | 0.00236 / 0.03745 | RTX 5060 Ti, torch 2.14.1+cu130 | fastbb@7d058322634d:sm_120 |
Limitations
- ONNX Runtime resolves top-k ties differently from PyTorch on noise pairs: nmrf-sceneflow differs by up to 0.56 px (mean 0.006) on a synthetic textured pair.
Example output
One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).
Input: Motorcycle, Middlebury 2014 stereo (left and right view, downscaled 4x), Scharstein et al., Middlebury College (research dataset, no licence stated).