--- library_name: "fastforks" pipeline_tag: "image-to-image" license: "mit" tags: - "restoration" - "super-resolution" - "image-upscaling" - "image-restoration" - "cuda" - "pytorch" - "fastforks" - "fastforks-card" --- # NAFNet (fastforks) NAFNet (Chen et al., ECCV 2022): a nonlinear-activation-free U-Net for image restoration: blocks of channel LayerNorm, 1 x 1 and depthwise 3 x 3 convs, a gate that multiplies two channel halves (SimpleGate) and simplified channel attention, four 2 x down / up levels. `nafnet-gopro` removes motion blur (GoPro, width 64, run with the test-time local converter as upstream's `NAFNetLocal`), `nafnet-sidd` removes smartphone sensor noise (SIDD, width 64). 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: . Kernels for the `kernels` backend: . Original code: at `2b4af71ebe09`. Task: restoration. Tier: experimental. Outputs: `image`. Backends: `portable`, `kernels`. Input: one RGB image. Output: the restored (upscaled) image, `model.scale` x the input size, RGB in [0, 1]. `tile=` runs large images in overlapping tiles (as ComfyUI). ## Variants Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/restoration/models/nafnet/card.toml). | variant | weights (author link) | SHA-256 | weights licence | commercial use | |---|---|---|---|---| | `nafnet-gopro@1` | [NAFNet-GoPro-width64.pth](https://drive.usercontent.google.com/download?export=download&confirm=t&id=1S0PVRbyTakYY9a82kujgZLbMihfNBLfC) | `329d3ab4077b` | MIT | yes | | `nafnet-sidd@1` | [NAFNet-SIDD-width64.pth](https://drive.usercontent.google.com/download?export=download&confirm=t&id=14Fht1QQJ2gMlk4N1ERCRuElg8JfjrWWR) | `cd685efaae01` | MIT | yes | ## Licence Original-code strings, recorded as they are (research-use package; check them before any other use). Code: MIT. Licence files: `LICENSE`. Training data: GoPro deblurring (GOPRO_Large, Nah et al. 2017: 3214 blurred / sharp frame pairs) (options/train/GoPro/NAFNet-width64.yml: GoPro train (2103 blurred / sharp pairs), 256 x 256 crops.). Licence evidence: https://github.com/megvii-research/NAFNet/blob/2b4af71ebe098a92a75910c233a3965a3e93ede4/LICENSE ; https://github.com/megvii-research/NAFNet/blob/2b4af71ebe098a92a75910c233a3965a3e93ede4/docs/GoPro.md ; https://github.com/megvii-research/NAFNet/blob/2b4af71ebe098a92a75910c233a3965a3e93ede4/docs/SIDD.md ## Input size any H x W >= 1, resized or padded inside the model Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `nafnet-gopro` 1988x2880 (7.0 GiB peak allocated, 9.6 reserved); `nafnet-sidd` 1988x2880 (7.8 GiB peak allocated, 10.1 reserved) ## Speed and memory ### Restoration, synthetic, 512x512 | model | time (ms): original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `nafnet-gopro` | 63.7 | 60.4 | 55.3 | 1.2x | 1.1x | 484 / 612 | 451 / 532 | 451 / 550 | | `nafnet-sidd` | 71.6 | 60.6 | 56.9 | 1.3x | 1.1x | 608 / 730 | 575 / 670 | 575 / 650 | ### Startup and first call | model | load (s): original | portable | kernels | first call (s): original | portable | kernels | | --- | --- | --- | --- | --- | --- | --- | | `nafnet-gopro` | 1.50 | 0.35 | 0.64 | 0.39 | 0.28 | 0.23 | | `nafnet-sidd` | 1.16 | 0.79 | 0.70 | 0.29 | 0.37 | 0.24 | ### torch.compile and TensorRT | model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `nafnet-gopro` | 512x512 | 60.4 ms | 35.4 ms | 52.6 ms | 55.3 ms | 38.1 s | 66.5 s | 451 / 532 | 422 / 470 | 451 / 550 | 722 / 734 | | `nafnet-sidd` | 512x512 | 60.6 ms | 30.9 ms | 24.5 ms | 56.9 ms | 30.3 s | 33.8 s | 575 / 670 | 450 / 508 | 575 / 650 | 650 / 668 | Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB). Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (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 Each degraded image at its own size, one pass without tiles (the model pads internally); PSNR and SSIM of the output rounded to uint8 on RGB, no border crop, averaged over the images (the authors' test scripts). Original = the original code named under Details, same checkpoint and protocol. | variant | dataset | original fp32 | portable | kernels | note | |---|---|---|---|---|---| | `nafnet-gopro` | GoPro test (every 4th: 278 frames), deblurring, PSNR / SSIM (RGB) | 33.73 / 0.9468 | 33.73 / 0.9468 | 33.73 / 0.9468 | | | `nafnet-sidd` | SIDD validation (1280 crops), denoising, PSNR / SSIM (RGB) | 40.21 / 0.9243 | 40.21 / 0.9243 | 40.21 / 0.9243 | | Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks f104019b, 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.003 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0015 and p99 <= 0.005 (absolute error of the output `image`). ## Usage ```python from fastforks import restoration model = restoration.load("nafnet-gopro") # mode="auto": the preferred backend from recorded measurements result = model("photo.png") # tile=512 for large images result.image # [3, sH, sW] float32 RGB in [0, 1], s = model.scale result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16') ``` Install with `pip install fastforks` (see ). Other variants: `nafnet-gopro`, `nafnet-sidd`. ## Kernels backend `restoration.load("nafnet-gopro", mode="kernels")` runs our CUDA kernels (`cudnn_hacc`). It needs a prebuilt kernel for your GPU architecture (downloaded from 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.