Models · Image restoration

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

Checkpoint uvdoc

Paper 2023 Added in 0.4.0

Kernels, RTX 5060 Ti 16 GB 4.17 ms 512x512, fp16
vs the faster original 2.3× original fp32: 9.48 ms
Peak memory 33 MiB original: 67 MiB
Accuracy vs original fp32 – no test-set run

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)

BackenddtypeTime per call (ms)vs original fp32Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32torch 2.14.1+cu130; original code, authors' host-side pre/post-processingfp32 9.48–67 MiB/94 MiB0.50.31
Original fp16torch 2.14.1+cu130; original code, authors' host-side pre/post-processingfp16 10.70.88×62 MiB/94 MiB0.30.38
Portable fp32fp32not measured ––––
Portablefp16 4.991.9×35 MiB/60 MiB0.20.25
Kernelsfp16 4.172.3×33 MiB/42 MiB0.30.12
Portable + torch.compile 1.984.8×61 MiB/80 MiB9 (build)–
TensorRT fp16fp16 0.84611×46 MiBenginenot comparable19 (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

DeviceBackenddtypems / callPeak memoryLoad / first call (s)Output vs referenceInput
Apple silicon runs on macOS
Apple M1 Pro 16 GB (MLX, fp16) MLX, torch 2.14.1, 2026-11-30Portablefp1620.1 288 MiB process0.2 / 0.1skip512x512
Portablefp3221.0 334 MiB process0.3 / 0.5skip512x512

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 source
Training data

Our reading of the licences, not legal advice.

Weights

uvdoc.pkl 32.2 MB· hosted on raw.githubusercontent.com

fastforks 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).

CheckToleranceMeasured
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.scale x 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 gates
  • cutlass_convCUTLASS convolutions with the recurrent update (GRU) fused in
  • cudnn_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.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
uvdocsynthetic (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): uvdoc 3000x4000 (0.5 GiB peak allocated, 0.6 reserved)
  • uvdoc 512x512, first call: portable + torch.compile 9 s (cold Inductor cache), TensorRT fp16 19 s (ONNX + engine).
  • uvdoc original (fp32) 512x512, original 512x512: torch 2.14.1+cu130; original code, authors' host-side pre/post-processing
  • uvdoc load / 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).

variantkernels error vs original, mean / p99GPU, torchkernels used
uvdoc0.00176 / 0.01257RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, igev@f075827d68c6:sm_120

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

Example output

No example rendered for this checkpoint yet.