image-to-image (face restoration) Β· vision Β· WASM Β· ~340 MB
Give this model an old, low-resolution or degraded portrait and it reconstructs a clean, sharp face: defined eyes, smooth skin, recovered hair and expression. GFPGAN (CVPR 2021) is a blind face-restoration network built on a StyleGAN2 face prior β it learned what real faces look like and rebuilds the detail degradation destroyed. It works on a single, roughly front-facing, aligned face. Runs entirely on your device via ONNX Runtime Web; the photo never leaves the tab.
| Model | Neus/GFPGANv1.4 β an ONNX export of GFPGAN v1.4 (StyleGAN2-prior face restorer) |
|---|---|
| Task | image-to-image (blind face restoration) β run via raw ONNX Runtime Web (see note below) |
| Runtime | onnxruntime-web 1.21 (transformers.js has no GFPGAN class / no face-restoration task) |
| Input | [1, 3, 512, 512] float32 β an aligned face resized to 512Γ512, normalised to [-1, 1] (not [0,1]) |
| Output | [1, 3, 512, 512] float32 in [-1, 1] β the restored face; mapped back to RGB |
| Quantization | fp32 ONNX β runs on the plain WASM execution provider, no WebGPU needed |
| Backend | WebAssembly (single-threaded on GitHub Pages) β a 512Γ512 pass is ~10β20 s |
| Download | ~340 MB, cached after first load (auto-inits on return). A large download β expect a wait on first use. |
| License | Apache-2.0 (GFPGAN weights, TencentARC upstream). The ONNX re-export repo declares no explicit licence; the underlying weights are Apache-2.0. |
| Web APIs | WebAssembly, Web Workers, OffscreenCanvas, ImageBitmap β all Baseline widely available |
Pick a genuinely old, degraded portrait and restore it as-is β or add extra degradation to a cleaner face to watch GFPGAN undo a known amount. Drag the divider to compare the degraded input vs the restored face.
The wipe above is the real evidence β slide it to see the face come back. βSharpnessβ is the Laplacian variance (the standard detail measure) of the input β the restored face; it rises as GFPGAN rebuilds eyes, skin, and hair. GFPGAN reconstructs a plausible face from a learned prior β it does not recover the person's true identity from information that's gone.
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).
Where did the model actually do something? This is the restoration delta: the per-pixel difference between the degraded input and the restored face, amplified. It lights up on the eyes, mouth, skin, and hairline β the facial structure a StyleGAN2 prior knows how to rebuild β and stays dark on flat background: nothing to restore there.
Bright indigo = big change (eyes, teeth, skin texture the model reconstructed); dark = untouched. The delta concentrates on facial features because the GAN prior only knows faces β feed it something that isn't a single aligned face and it will try (wrongly) to make one, which is why the input matters.
Old and low-quality portraits are everywhere β family archives, scanned documents, low-res avatars, video-call stills. On-device face restoration means you can rescue them privately, with no upload and no per-image cloud cost:
GFPGAN synthesises a plausible face from a learned prior; it can invent detail that wasn't there and can subtly change identity, so it's an enhancement, not forensic evidence. It expects a single, roughly aligned, front-facing face β group shots or profiles need a face detector/aligner first.
Restore a genuinely old portrait as-is β wipe between the degraded original and the reconstructed face.
Rescue a small, compressed avatar or scan so the face is clean again, then download the result.
Push it: crank the degradation up and find where honest restoration turns into invented identity.
Restore β upscale: reconstruct the face with GFPGAN, then enlarge the whole photo 4Γ with Real-ESRGAN.
transformers.js has no GFPGAN class and no face-restoration task, so we run the ONNX graph directly with ONNX Runtime Web. In goes an aligned face, out comes the restored one:
import * as ort from "onnxruntime-web";
const session = await ort.InferenceSession.create(gfpganBytes, { executionProviders: ["wasm"] });
// aligned face β [1,3,512,512] float32 normalised to [-1,1]: (x/255 - 0.5) / 0.5
const input = new ort.Tensor("float32", toNCHW(face, 512, 512), [1, 3, 512, 512]);
const { [session.outputNames[0]]: out } = await session.run({ [session.inputNames[0]]: input });
// out is [1,3,512,512] in [-1,1] β map back to RGB: (v + 1) / 2
const restored = tensorToImage(out.data, 512, 512);
Inference and the whole output composite run in a Web Worker so the UI never blocks, and the 340 MB model is fetched through Cache Storage, so a returning visit auto-initialises with no re-download.