PatchmatchNet
PatchmatchNet by Fangjinhua Wang et al.: learned PatchMatch multi-view stereo, depth from posed images.
stable Fork of FangjinhuaWang/PatchmatchNet@8dc6cb4 · backends: portable, kernels
- Paper PatchmatchNet: Learned Multi-View Patchmatch Stereo CVPR 2021 · first released 2 Dec 2020
Checkpoint patchmatchnet
Paper 2020 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 multiview
model = multiview.load("patchmatchnet") # kernels on a supported GPU, else portable PyTorch
result = model(images)
result.depth # also: confidence
result.backend # what ran: mode, device, dtype, kernels fastforks bench patchmatchnet 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.
Input: synthetic, 1536x1024
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 248 | 0.89× | 1,330 MiB/1,412 MiB | 0.0 | 0.39 |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 220 | – | 1,228 MiB/1,272 MiB | 0.0 | 0.92 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 201 | 1.1× | 1,039 MiB/1,212 MiB | 0.2 | 0.86 |
| Kernels | fp16 | 29.5 | 7.4× | 648 MiB/772 MiB | 0.2 | 0.56 |
| Portable + torch.compile | 175 | 1.3× | 1,798 MiB/1,888 MiB | 29 (build) | – | |
| TensorRT fp16 | fp16 | 51.0 | 4.3× | 844 MiBenginenot comparable | 82 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 to 2026-11-15. 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-14 | Original | fp32 | 875 | 3,724 MiB process | matches | 1536x1024 |
| Portable | fp16 | 1574 | 6,591 MiB process | matches | 1536x1024 | |
| Portable | fp32 | 1010 | 7,593 MiB process | matches | 1536x1024 | |
| Kernels | fp16 | not implemented | – | 1536x1024 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 273 | 1,690 MiB/1,892 MiB | – | 1536x1024 |
| Kernels | fp16 | 34.2 | 624 MiB/752 MiB | – | 1536x1024 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 82.5 | 1,690 MiB/1,892 MiB | – | 1536x1024 |
| Kernels | fp16 | 11.5 | 624 MiB/752 MiB | – | 1536x1024 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 260 | 1,690 MiB/1,892 MiB | – | 1536x1024 |
| Kernels | fp16 | 30.1 | 624 MiB/752 MiB | – | 1536x1024 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 87.9 | 1,690 MiB/1,892 MiB | – | 1536x1024 |
| Kernels | fp16 | 21.9 | 624 MiB/752 MiB | – | 1536x1024 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 39.6 | 1,714 MiB/1,892 MiB | – | 1536x1024 |
| Kernels | fp16 | 7.95 | 648 MiB/772 MiB | – | 1536x1024 | |
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
-
- DTU Robot Image Data Sets (MVS 2014) not stated
- weights licence not stated by the original authors; assumed to be the code licence
- The code is MIT; the checkpoint ships in the repository without a licence of its own (MIT assumed) and is trained on DTU, whose terms of use are not stated.
Our reading of the licences, not legal advice.
Weights
params_000007.ckpt 2.8 MB· hosted on GitHubfastforks downloads and checks these files on first use (fastforks download patchmatchnet).
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.
DTU scans 1
9, 24, 33, 75, view 24 + 7 sources, AbsRel / delta1 %
| Run | dtype | AbsRel ↓ | δ1.25 % ↑ | MAE mm ↓ | Δ AbsRel vs fp32 original | scans | ms / scan |
|---|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 0.0087 | 99.52 | 7.03 | reference | 5 | 72.4 |
| Original fp16 | fp16 | fails: _LinAlgError: linalg.inv | |||||
| Portable fp32 | fp32 | 0.0087 | 99.52 | 7.08 | ±0.0000 | 5 | 54.6 |
| Portable | fp16 | 0.0087 | 99.52 | 7.08 | ±0.0000 | 5 | 48.0 |
| Kernels | fp16 | 0.0087 | 99.52 | 7.08 | ±0.0000 | 5 | 10.3 |
640x512 crops, the 7 most co-visible views as sources; GT = depth rendered from the structured-light points. AbsRel / delta1 over GT pixels, after per-image median scaling unless the model takes the cameras (calibrated MVS: cameras, error in mm; PatchMatchNet also the depth range 425-935 mm, MVSAnywhere its own range from the camera baselines). Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 30c7a8e9, 2026-11-17.
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.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.5 % and p99 <= 3 % of the reference's median |value| (absolute error of the output depth).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 (relative) | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.005 (relative) | 0.00006 (relative) |
| GPU default dtypes, p99 |diff| | ≤ 0.03 (relative) | 0.00021 (relative) |
Recorded for patchmatchnet on RTX 5060 Ti, torch 2.14.1+cu130, 2026-10-31, with these kernels: patchmatchnet
Details
PatchmatchNet (Wang et al. 2021): learned PatchMatch multi-view stereo, the depth of a reference view from posed, calibrated source views and a depth search range. Three coarse-to-fine PatchMatch stages (random initialisation, adaptive propagation, group-wise correlation with pixel-wise view weights, adaptive spatial cost aggregation) on FPN features, then a depth refinement net at full resolution.
- Input / output
- Input: several images of one scene (posed and calibrated for multi-view stereo, unposed otherwise). Output: depth maps and, where the model predicts them, cameras and 3-D points.
- Input size
- any H x W >= 5, resized or padded inside the model; tested up to 1988x2880 (8,046 MiB allocated)
- Outputs
depth,confidence- CUDA kernels
patchmatchnetPatchmatchNet: fused cost, weights and aggregation
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
PatchmatchNet by Fangjinhua Wang et al.: learned PatchMatch multi-view stereo, depth from posed images.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
patchmatchnet | synthetic (1536x1024) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 248 220 201 29.5 175 51.0 | 1330 / 1412 1228 / 1272 1039 / 1212 648 / 772 1798 / 1888 1073 / 1106 |
Details
- Original code: https://github.com/FangjinhuaWang/PatchmatchNet at
8dc6cb4 - Code licence: MIT (permissive); files:
LICENSE - Weights licence: MIT (assumed from code)
- Licence evidence: https://github.com/FangjinhuaWang/PatchmatchNet/blob/8dc6cb4/LICENSE and README.md (the checkpoint ships in the repository)
- Training data: DTU Robot Image Data Sets (MVS 2014) (The released checkpoint (checkpoints/params_000007.ckpt) is trained on DTU (README); the paper evaluates it zero-shot on Tanks and Temples and ETH3D)
- Licence note: The code is MIT; the checkpoint ships in the repository without a licence of its own (MIT assumed) and is trained on DTU, whose terms of use are not stated.
- Kernel libraries:
patchmatchnet - Variants:
patchmatchnet - Outputs: depth, confidence; kind:
metric - Input size: any H x W >= 5, resized or padded inside the model
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
patchmatchnet1988x2880 (7.9 GiB peak allocated, 9.4 reserved) patchmatchnet1536x1024, first call: portable + torch.compile 29 s (cold Inductor cache), TensorRT fp16 82 s (ONNX + engine).patchmatchnetoriginal 1536x1024: torch.autocast(fp16) around the forwardpatchmatchnetload / first call: original 0.04 s / 0.917 s (1536x1024), portable 0.16 s / 0.861 s (1536x1024), kernels 0.17 s / 0.562 s (1536x1024)- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
640x512 crops, the 7 most co-visible views as sources; GT = depth rendered from the structured-light points. AbsRel / delta1 over GT pixels, after per-image median scaling unless the model takes the cameras (calibrated MVS: cameras, error in mm; PatchMatchNet also the depth range 425-935 mm, MVSAnywhere its own range from the camera baselines). Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
patchmatchnet | DTU scans 1, 9, 24, 33, 75, view 24 + 7 sources, AbsRel / delta1 % / MAE mm | 0.0087 / 99.52 / 7.03 | fails (LinAlgError: linalg.inv) | 0.0087 / 99.52 / 7.08 | 0.0087 / 99.52 / 7.08 | 0.0087 / 99.52 / 7.08 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 30c7a8e9, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.5 % and p99 <= 3 % of the reference's median |value| (absolute error of the output depth).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
patchmatchnet | 6e-05 / 0.00021 | RTX 5060 Ti, torch 2.14.1+cu130 | patchmatchnet@e73cbaa02d34:sm_120 |
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).