UVDoc
UVDoc (Verhoeven et al., SIGGRAPH Asia 2023): flattens a photo of a curled, bent or folded page by predicting a coarse grid of where each part of the flat page lies in the photo and resampling it. MIT code and weights.
experimental Fork of tanguymagne/UVDoc@4c9b82b · backends: portable, kernels
- Paper UVDoc: Neural Grid-based Document Unwarping SIGGRAPH Asia 2023 · first released 6 Feb 2023
Checkpoint uvdoc
Paper 2023 Added in 0.4.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import restoration
model = restoration.load("uvdoc") # fastest backend that runs here
result = model("photo.jpg")
# result fields: image
image = result.image # a torch tensor
arrays = result.numpy() # the tensor fields as NumPy arrays: arrays["image"]
result.backend # what ran: mode, device, dtype
Other ways to run it
- Backend:
restoration.load("uvdoc", mode="kernels") # or "portable", "auto" (default) - Precision:
restoration.load("uvdoc", dtype="float32") # full precision: slower, portable only
fastforks bench uvdoc 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, 512x512 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp32 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32torch 2.14.1+cu130; original code, authors' host-side pre/post-processing | fp32 | 9.48 | – | 67 MiB/94 MiB | 0.5 | 0.31 |
| Original fp16torch 2.14.1+cu130; original code, authors' host-side pre/post-processing | fp16 | 10.7 | 0.88× | 62 MiB/94 MiB | 0.3 | 0.38 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 4.99 | 1.9× | 35 MiB/60 MiB | 0.2 | 0.25 |
| Kernels | fp16 | 4.17 | 2.3× | 33 MiB/42 MiB | 0.3 | 0.12 |
| Portable + torch.compile | 1.98 | 4.8× | 61 MiB/80 MiB | 9 (build) | – | |
| TensorRT fp16 | fp16 | 0.846 | 11× | 46 MiBenginenot comparable | 19 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-29 to 2026-11-30. 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 | Load / first call (s) | Output vs reference | Input |
|---|---|---|---|---|---|---|---|
| Apple silicon runs on macOS | |||||||
| Apple M1 Pro 16 GB (MLX, fp16) MLX, torch 2.14.1, 2026-11-30 | Portable | fp16 | 20.1 | 288 MiB process | 0.2 / 0.1 | skip | 512x512 |
| Portable | fp32 | 21.0 | 334 MiB process | 0.3 / 0.5 | skip | 512x512 | |
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
Our reading of the licences, not legal advice.
Weights
uvdoc.pkl 32.2 MB· hosted on raw.githubusercontent.comfastforks downloads and checks these files on first use (fastforks download uvdoc).
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.
Accuracy not measured for uvdoc.
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.009 and p99 <= 0.06 (absolute error of the output image).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.009 | 0.00176 |
| GPU default dtypes, p99 |diff| | ≤ 0.06 | 0.01257 |
Recorded for uvdoc on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-27, with these kernels: cudnn_hacccutlass_convigev
Details
UVDoc (Verhoeven et al., SIGGRAPH Asia 2023): document unwarping. A dilated ResNet with six parallel dilated bridges sees the photo at 488 x 712 and predicts a coarse 31 x 45 grid of source positions; the grid is upsampled to the photo's size and the photo is resampled through it at full resolution. For a page photo already cropped to the page (curled, bent or folded paper): the output is the flattened page at the input size.
- Input / output
- Input: one RGB image. Output: the restored (upscaled) image,
model.scalex the input size, RGB in [0, 1].What the numbers mean, and which models need the camera focal length
tile=runs large images in overlapping tiles (as ComfyUI). - Input size
- any H x W >= 8, resized or padded inside the model; tested up to 3000x4000 (478 MiB allocated)
- Outputs
image- CUDA kernels
igevIGEV stereo: convolution epilogues, correlation lookups, GRU gatescutlass_convCUTLASS convolutions with the recurrent update (GRU) fused incudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
- fp32, fp16
Limitations
- Expects a photo cropped to one page (`ocr.scan` crops it first); the output keeps the input size, not the page's aspect ratio.
- The network sees the whole photo resized to 488 x 712: run it without `tile=` (tiles would be unwarped one by one).
Full reference, generated from the repository
UVDoc (Verhoeven et al., SIGGRAPH Asia 2023): flattens a photo of a curled, bent or folded page by predicting a coarse grid of where each part of the flat page lies in the photo and resampling it. MIT code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
uvdoc | synthetic (512x512) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 9.48 10.7 4.99 4.17 1.98 0.846 | 67 / 94 62 / 94 35 / 60 33 / 42 61 / 80 70 / 82 |
Details
- Original code: https://github.com/tanguymagne/UVDoc at
4c9b82b53705 - Code licence: MIT (permissive); files:
LICENSE - Weights licence: MIT
- Licence evidence: https://github.com/tanguymagne/UVDoc/blob/4c9b82b537057aff2526e6dd118a847cdd072e82/LICENSE ; https://github.com/tanguymagne/UVDoc/blob/4c9b82b537057aff2526e6dd118a847cdd072e82/README.md
- Training data: Doc3D (synthetic rendered documents with 3-D shape, Stony Brook), UVDoc dataset (pseudo-photorealistic deformed documents, ETH Zurich IGL) (README / train.py: a mix of Doc3D (with the authors' added 2-D / 3-D grids) and the UVDoc dataset.)
- Kernel libraries:
igev,cutlass_conv,cudnn_hacc - Variants:
uvdoc - Outputs: image
- Input size: any H x W >= 8, resized or padded inside the model
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
uvdoc3000x4000 (0.5 GiB peak allocated, 0.6 reserved) uvdoc512x512, first call: portable + torch.compile 9 s (cold Inductor cache), TensorRT fp16 19 s (ONNX + engine).uvdocoriginal (fp32) 512x512, original 512x512: torch 2.14.1+cu130; original code, authors' host-side pre/post-processinguvdocload / first call: original 0.28 s / 0.38 s, portable 0.16 s / 0.251 s, kernels 0.29 s / 0.118 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.009 and p99 <= 0.06 (absolute error of the output image).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
uvdoc | 0.00176 / 0.01257 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, igev@f075827d68c6:sm_120 |
Limitations
- Expects a photo cropped to one page (
ocr.scancrops it first); the output keeps the input size, not the page's aspect ratio. - The network sees the whole photo resized to 488 x 712: run it without
tile=(tiles would be unwarped one by one).
Example output
No example rendered for this checkpoint yet.