NAFNet
NAFNet (Chen et al., ECCV 2022): a nonlinear-activation-free U-Net that removes motion blur (GoPro) or real camera noise (SIDD) at the input size. MIT code and weights.
experimental Fork of megvii-research/NAFNet@2b4af71 · backends: portable, kernels
- Paper Simple Baselines for Image Restoration ECCV 2022 · first released 10 Apr 2022
Paper 2022 Added in 0.2.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 restoration
model = restoration.load("nafnet-gopro") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.image
result.backend # what ran: mode, device, dtype, kernels fastforks bench nafnet-gopro 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 fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16.half() on 1 modules, fp16 inputs; upstream ImageRestorationModel.test, float32, NAFNetLocal (TLC) | fp16 | 63.7 | – | 484 MiB/612 MiB | 1.1 | 0.07 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 60.4 | 1.1× | 451 MiB/532 MiB | 0.3 | 0.28 |
| Kernels | fp16 | 55.3 | 1.2× | 451 MiB/550 MiB | 0.6 | 0.23 |
| Portable + torch.compile | 35.4 | 1.8× | 422 MiB/470 MiB | 38 (build) | – | |
| TensorRT fp16 | fp16 | 52.6 | 1.2× | 584 MiBenginenot comparable | 67 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-14. 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-15 | Original | fp32 | 645 | 3,634 MiB process | – | 512x512 |
| Portable | fp16 | 368 | 1,715 MiB process | matches | 512x512 | |
| Portable | fp32 | 409 | 2,894 MiB process | matches | 512x512 | |
| Kernels | fp16 | not implemented | – | 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
NAFNet-GoPro-width64.pth 272 MB· hosted on Google Drivefastforks downloads and checks these files on first use (fastforks download nafnet-gopro).
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.
GoPro test (every 4th: 278 frames)
deblurring, PSNR / SSIM (RGB)
| Run | dtype | psnr ↑ | ssim ↑ | Δ psnr vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 33.73 | 0.9468 | reference | 278 | – |
| Original fp16 | not measured | |||||
| Portable fp32 | fp32 | 33.73 | 0.9468 | ±0.00 | 278 | – |
| Portable | fp16 | 33.73 | 0.9468 | ±0.00 | 278 | – |
| Kernels | fp16 | 33.73 | 0.9468 | ±0.00 | 278 | – |
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 authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-14; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks f104019b, 2026-11-14.
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.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).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.003 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.0015 | 0.01098 |
| GPU default dtypes, p99 |diff| | ≤ 0.005 | 0.54652 |
Recorded for nafnet-gopro on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-14, with these kernels: cudnn_hacc
Details
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).
- 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 >= 1, resized or padded inside the model; tested up to 1988x2880 (7,207 MiB allocated)
- Outputs
image- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
NAFNet (Chen et al., ECCV 2022): a nonlinear-activation-free U-Net that removes motion blur (GoPro) or real camera noise (SIDD) at the input size. MIT code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
nafnet-gopro | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 63.7 60.4 55.3 35.4 52.6 | 484 / 612 451 / 532 451 / 550 422 / 470 722 / 734 |
nafnet-sidd | synthetic (512x512) | original portable kernels portable + torch.compile TensorRT fp16 | 71.6 60.6 56.9 30.9 24.5 | 608 / 730 575 / 670 575 / 650 450 / 508 650 / 668 |
Details
- Original code: https://github.com/megvii-research/NAFNet at
2b4af71ebe09 - Code licence: MIT (permissive); files:
LICENSE - Weights licence: MIT
- 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
- 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.)
nafnet-sidd: Smartphone Image Denoising Dataset (SIDD, noisy / ground-truth smartphone photos) (options/train/SIDD/NAFNet-width64.yml: SIDD-Medium sRGB (320 noisy / clean pairs), 256 x 256 crops.)
- Kernel libraries:
cudnn_hacc - Variants:
nafnet-gopro,nafnet-sidd - Outputs: image
- Input size: any H x W >= 1, resized or padded inside the model
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
nafnet-gopro1988x2880 (7.0 GiB peak allocated, 9.6 reserved);nafnet-sidd1988x2880 (7.8 GiB peak allocated, 10.1 reserved) nafnet-gopro512x512, first call: portable + torch.compile 38 s (cold Inductor cache), TensorRT fp16 66 s (ONNX + engine).nafnet-sidd512x512, first call: portable + torch.compile 30 s (cold Inductor cache), TensorRT fp16 34 s (ONNX + engine).nafnet-goprooriginal 512x512: .half() on 1 modules, fp16 inputs; upstream ImageRestorationModel.test, float32, NAFNetLocal (TLC)nafnet-siddoriginal 512x512: .half() on 1 modules, fp16 inputs; upstream ImageRestorationModel.test, float32nafnet-goproload / first call: original 1.5 s / 0.386 s, portable 0.35 s / 0.278 s, kernels 0.64 s / 0.232 snafnet-siddload / first call: original 1.16 s / 0.291 s, portable 0.79 s / 0.369 s, kernels 0.7 s / 0.243 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
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 | portable fp32 | 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 | 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 | 40.21 / 0.9243 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks f104019b, 2026-11-14.
Parity
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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
nafnet-gopro | 0.01098 / 0.54652 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
nafnet-sidd | 0.00027 / 0.00099 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400 |
Example output
No example rendered for this checkpoint yet.