Models · Image restoration

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

Checkpoint

Paper 2022 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 55.3 ms 512x512, fp16
vs the faster original 1.2× original fp16: 63.7 ms
Peak memory 451 MiB original: 484 MiB
Accuracy vs original fp32 ±0.00 kernels psnr, GoPro test (every 4th: 278 frames) (33.73 original)

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)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16.half() on 1 modules, fp16 inputs; upstream ImageRestorationModel.test, float32, NAFNetLocal (TLC)fp16 63.7–484 MiB/612 MiB1.10.07
Portable fp32fp32not measured ––––
Portablefp16 60.41.1×451 MiB/532 MiB0.30.28
Kernelsfp16 55.31.2×451 MiB/550 MiB0.60.23
Portable + torch.compile 35.41.8×422 MiB/470 MiB38 (build)–
TensorRT fp16fp16 52.61.2×584 MiBenginenot comparable67 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-15Originalfp32645 3,634 MiB process–512x512
Portablefp16368 1,715 MiB processmatches512x512
Portablefp32409 2,894 MiB processmatches512x512
Kernelsfp16not 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

Code
MIT LICENSE
Weights
MIT source
Training data

Our reading of the licences, not legal advice.

Weights

NAFNet-GoPro-width64.pth 272 MB· hosted on Google Drive

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

Rundtypepsnr ↑ssim ↑Δ psnr vs fp32 originalimagesms / image
Original fp32fp3233.730.9468 reference 278 –
Original fp16not measured
Portable fp32fp3233.730.9468 ±0.00 278 –
Portablefp1633.730.9468 ±0.00 278 –
Kernelsfp1633.730.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).

CheckToleranceMeasured
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.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 >= 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.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
nafnet-goprosynthetic (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-siddsynthetic (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-gopro 1988x2880 (7.0 GiB peak allocated, 9.6 reserved); nafnet-sidd 1988x2880 (7.8 GiB peak allocated, 10.1 reserved)
  • nafnet-gopro 512x512, first call: portable + torch.compile 38 s (cold Inductor cache), TensorRT fp16 66 s (ONNX + engine).
  • nafnet-sidd 512x512, first call: portable + torch.compile 30 s (cold Inductor cache), TensorRT fp16 34 s (ONNX + engine).
  • nafnet-gopro original 512x512: .half() on 1 modules, fp16 inputs; upstream ImageRestorationModel.test, float32, NAFNetLocal (TLC)
  • nafnet-sidd original 512x512: .half() on 1 modules, fp16 inputs; upstream ImageRestorationModel.test, float32
  • nafnet-gopro load / first call: original 1.5 s / 0.386 s, portable 0.35 s / 0.278 s, kernels 0.64 s / 0.232 s
  • nafnet-sidd load / 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.

variantdatasetoriginal fp32portableportable fp32kernelsnote
nafnet-goproGoPro test (every 4th: 278 frames), deblurring, PSNR / SSIM (RGB)33.73 / 0.946833.73 / 0.946833.73 / 0.946833.73 / 0.9468
nafnet-siddSIDD validation (1280 crops), denoising, PSNR / SSIM (RGB)40.21 / 0.924340.21 / 0.924340.21 / 0.924340.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).

variantkernels error vs original, mean / p99GPU, torchkernels used
nafnet-gopro0.01098 / 0.54652RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400
nafnet-sidd0.00027 / 0.00099RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400

Example output

No example rendered for this checkpoint yet.