← All models

image-to-image (deblur / restoration) Β· vision Β· WASM Β· ~92 MB

NAFNet β€” sharpen a blurred photo

Give this model a blurred photo β€” camera shake, motion, a soft focus β€” and it reconstructs the sharp one: crisp edges, readable text, recovered texture. NAFNet is a restoration network (ECCV 2022) from the OpenCV Model Zoo, trained on real motion blur. It's not a sharpen filter β€” it learned what un-blurred scenes look like and rebuilds the detail. Runs entirely on your device via ONNX Runtime Web; the photo never leaves the tab.

At a glance

Modelopencv/deblurring_nafnet β€” NAFNet (Nonlinear-Activation-Free Network), OpenCV Model Zoo
Taskimage-to-image (deblurring / restoration) β€” run via raw ONNX Runtime Web (see note below)
Runtimeonnxruntime-web 1.21 (transformers.js has no NAFNet class / no deblurring task)
Input[1, 3, 512, 512] float32 β€” the blurred image resized to 512Γ—512, values 0–1 (no normalisation)
Output[1, 3, 512, 512] float32 β€” the restored image; resized back to your photo's aspect
Quantizationfp32 ONNX β€” runs on the plain WASM execution provider, no WebGPU needed
BackendWebAssembly (single-threaded on GitHub Pages) β€” a 512Γ—512 pass is a few seconds
Download~92 MB, cached after first load (auto-inits on return)
LicenseMIT (ONNX export) Β· NAFNet (MIT)
Web APIsWebAssembly, Web Workers, OffscreenCanvas, ImageBitmap β€” all Baseline widely available

Run it

Pick a sharp photo and add a known blur so you can watch NAFNet undo it β€” or drop your own genuinely blurry photo. Drag the divider to compare blurred vs restored.

β—€ blurred inputrestored β–Ά
Drop / choose your own blurry photo (a real motion-blurred shot works best)

Everything runs on your device β€” the photo and every restored pixel never leave the tab. Gallery images are rights-cleared samples (see each caption for the source).

See inside

Where did the model actually do something? This is the restoration delta: the per-pixel difference between the blurred input and the restored output, amplified. It lights up along edges, text, and fine texture β€” exactly the high-frequency detail a blur destroys and NAFNet puts back. Flat areas (sky, walls) stay dark: nothing to restore there.

Restore a photo to see where the model changed it.

Why it matters

A blurred shot is usually a lost shot β€” you can't re-take the moment. On-device restoration means you can rescue it privately, with no upload, no per-image cloud cost:

NAFNet reconstructs plausible detail; it can't invent information the blur erased entirely. Extreme blur restores partially β€” it's a rescue, not a time machine.

Use cases

Basics

Blur a photo, then watch NAFNet rebuild it β€” wipe between blurred and restored and see the sharpness jump.

Practical

Rescue a shaky document photo so the text is legible again, then download the restored image.

Wild

Push it: crank the blur up and find the breaking point where restoration starts to give up.

Multi-model

Restore β†’ detect text: deblur a photo, then run the text detector on the result to find text the blur hid.

How the API works

transformers.js has no NAFNet class and no deblurring task, so we run the ONNX graph directly with ONNX Runtime Web. In goes the blurred image, out comes the restored one:

import * as ort from "onnxruntime-web";

const session = await ort.InferenceSession.create(nafnetBytes, { executionProviders: ["wasm"] });

// blurred image β†’ [1,3,512,512] float32 in [0,1] (fixed network size, no normalisation)
const input = new ort.Tensor("float32", toNCHW(blurred, 512, 512), [1, 3, 512, 512]);
const { [session.outputNames[0]]: restored } = await session.run({ [session.inputNames[0]]: input });

// restored is [1,3,512,512] in [0,1] β†’ clamp to RGBA and resize back to the original aspect
const sharp = tensorToImage(restored.data, 512, 512);

Inference and the whole output composite run in a Web Worker so the UI never blocks, and the 92 MB model is fetched through Cache Storage, so a returning visit auto-initialises with no re-download.

References