GFPGAN (fastforks)

GFPGAN v1.4 (Wang et al., CVPR 2021): blind face restoration with a generative facial prior: a U-Net encoder whose features modulate (spatial feature transform) a pretrained StyleGAN2 face generator. Input: an aligned 512 x 512 face crop (FFHQ alignment); detecting, aligning and pasting the face back are not part of the model.

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: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/TencentARC/GFPGAN at 7552a7791caa.

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.

variant weights (author link) SHA-256 weights licence commercial use
gfpgan-v1.4@1 GFPGANv1.4.pth e2cd4703ab14 Apache-2.0 yes

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Licence files: LICENSE.

Training data: Flickr-Faces-HQ (FFHQ, 70k face images) (Paper Sec. 4.1: FFHQ (70 000 faces, resized to 512 x 512) with synthetic degradations (blur, downsampling, noise, JPEG); the StyleGAN2 prior is also trained on FFHQ.).

Licence evidence: https://github.com/TencentARC/GFPGAN/blob/7552a7791caad982045a7bbe5634bbf1cd5c8679/LICENSE ; https://github.com/TencentARC/GFPGAN/blob/7552a7791caad982045a7bbe5634bbf1cd5c8679/README.md (weights: https://github.com/TencentARC/GFPGAN/releases/tag/v1.3.0)

Input size

any H x W >= 512, padded to a multiple of 32 Tested up to (portable, fp16, RTX 5060 Ti 16 GB): gfpgan-v1.4 512x512 (0.5 GiB peak allocated, 0.6 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
gfpgan-v1.4 21.9 21.2 18.0 1.2x 1.2x 563 / 670 505 / 528 473 / 530

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
gfpgan-v1.4 0.86 1.04 0.78 0.33 0.25 0.07

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)
gfpgan-v1.4 512x512 21.2 ms 12.5 ms 15.8 ms 18.0 ms 27.3 s 115 s 505 / 528 360 / 428 473 / 530 609 / 644

Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).

Hardware, protocol and caveats: benchmarks (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

Parity with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 6.3e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.00051 and p99 <= 0.0022 (absolute error of the output image).

Usage

from fastforks import restoration

model = restoration.load("gfpgan-v1.4")  # 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 https://github.com/kleinicke/fastforks). Other variants: gfpgan-v1.4.

Kernels backend

restoration.load("gfpgan-v1.4", mode="kernels") runs our CUDA kernels (cudnn_hacc). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels 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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Collection including fastforks/gfpgan