GFPGAN v1.4 — LiteRT (CompiledModel GPU)

GFPGAN restoration: degraded input to restored face, on the Pixel 8a GPU

On-device GFPGAN v1.4 blind face restoration: it reconstructs degraded / low-quality faces using a StyleGAN2 generative facial prior. Converted for LiteRT CompiledModel with the GPU (ML Drift) accelerator and verified running fully on the GPU of a Pixel 8a (551/551 nodes delegated to LITERT_CL, ~1.2 s per face).

Files

File What I/O
gfpgan_fp16.tflite GFPGAN v1.4 restoration (431 MB, fp16) [1,3,512,512] NCHW [-1,1][1,3,512,512] NCHW [-1,1]
yunet_fp16.tflite YuNet face detector (0.3 MB) for alignment [1,3,640,640] BGR 0-255 → 5 landmarks

Pipeline

  1. Detect the face + 5 landmarks with YuNet.
  2. Align: similarity-warp the face to the standard FFHQ 512 template (GFPGAN's StyleGAN prior mangles the mouth on off-template crops).
  3. Restore: normalize the aligned face to [-1,1], run gfpgan_fp16.tflite, denormalize (x+1)*127.5.

Minimal usage

Android (Kotlin, CompiledModel GPU)

// 431 MB — stage into filesDir and load by path
val model = CompiledModel.create("${context.filesDir}/gfpgan_fp16.tflite",
    CompiledModel.Options(Accelerator.GPU), null)
val inputs = model.createInputBuffers()
val outputs = model.createOutputBuffers()
inputs[0].writeFloat(chw)              // [1,3,512,512] RGB in [-1,1], FFHQ-aligned face
model.run(inputs, outputs)
val restored = outputs[0].readFloat()  // [1,3,512,512] in [-1,1] -> (x+1)*127.5

Python (desktop verification)

import numpy as np
from PIL import Image
from ai_edge_litert.interpreter import Interpreter

# input must be an FFHQ-aligned 512x512 face crop (YuNet 5-landmark warp; see Pipeline)
img = Image.open("aligned_face.png").convert("RGB").resize((512, 512))
x = (np.asarray(img, np.float32) / 127.5 - 1.0).transpose(2, 0, 1)[None]  # [1,3,512,512]

it = Interpreter(model_path="gfpgan_fp16.tflite"); it.allocate_tensors()
it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
y = it.get_tensor(it.get_output_details()[0]["index"])[0]                 # [3,512,512], [-1,1]
Image.fromarray(((y.transpose(1, 2, 0) + 1) * 127.5).clip(0, 255).astype(np.uint8)).save("restored.png")

Conversion notes (GPU compatibility)

Converted with litert-torch (NCHW preserved). The only substantial re-authoring is the StyleGAN2 ModulatedConv2d, whose original form builds a 5D weight (b,c_out,c_in,k,k) at runtime from the style vector and convolves with that runtime filter — both GPU-incompatible (>4D tensor; a GPU CONV_2D needs a constant filter). It is rewritten to an exact 4D form:

  • modulationconv(x, W·style) == conv(x · style_per_in_channel, W_const) (conv is linear), so the style becomes an input channel-scale and the filter stays constant.
  • demodulationrsqrt(Σ (W·style)² + eps) == rsqrt((style²) @ Wsqᵀ + eps) where Wsq[o,i] = Σ_k W[o,i,k]² is a constant matrix — a small matmul + RSQRT.

fp16 note (Mali): the demod sum Σ style²·Wsq overflows fp16 — the style vectors reach |s|~1000, so the sum reaches ~2.3e6 ≫ 65504, giving rsqrt(inf)=0 and collapsing the decoder to a flat color (it still compiles and runs). Normalizing the style by its per-image max before squaring keeps every intermediate in fp16 range; the scale cancels exactly against the demod, so the on-device output is identical to the desktop fp32 result.

Performance

Measured on a Pixel 8a (Tensor G3, Android 16) with the standard TFLite benchmark_model tool — 10 warm-up runs then 50 timed runs, reported as the tool's mean.

Runtime Backend Graph on GPU Latency
TFLite benchmark_model (TfLiteGpuDelegateV2) — yunet_fp16.tflite GPU (OpenCL) 146 / 146 22.1 ms
TFLite benchmark_model (TfLiteGpuDelegateV2) — gfpgan_fp16.tflite GPU (OpenCL) 641 / 641 265.2 ms
TFLite benchmark_modelyunet_fp16.tflite CPU (XNNPACK, 4 threads) XNNPACK declined the graph
TFLite benchmark_modelgfpgan_fp16.tflite CPU (XNNPACK, 4 threads) 6070.3 ms

Any on-device figure recorded when this model shipped came from a different runtime. It was taken through LiteRT's own CompiledModel accelerator (logcat reports it as LITERT_CL), which is the path the Kotlin sample app and the LiteRT API use, and it appears elsewhere on this card. The rows above are the classic TFLite OpenCL delegate, measured with a tool anyone can download and re-run. The two are not comparable, so read the rows above as a reproducible floor rather than as this model's speed on LiteRT.

XNNPACK declines these fp16 graphs — it reports failed to delegate DEPTHWISE_CONV_2D and then fails to allocate tensors — so there is no usable CPU number. Disabling XNNPACK falls back to reference kernels, which measured about 20× slower than the GPU on models of this size and would not represent CPU inference anyone would ship.

Snapdragon NPU (Hexagon)

  • gfpgan_fp16.tflite — the NPU is 2.76x faster than the GPU (32.26 ms against 88.95 ms) and loads 5.62x faster (726 ms against 4085 ms).
  • yunet_fp16.tflite — the NPU is 1.79x faster than the GPU (1.83 ms against 3.28 ms) and loads 5.89x faster (98 ms against 578 ms).
file backend compiled inference (median / min) load
gfpgan_fp16.tflite NPU (Hexagon v81) on-device JIT 32.26 ms / 30.55 ms 726 ms
gfpgan_fp16.tflite GPU (Adreno) 88.95 ms / 87.71 ms 4085 ms
yunet_fp16.tflite NPU (Hexagon v81) on-device JIT 1.83 ms / 1.78 ms 98 ms
yunet_fp16.tflite GPU (Adreno) 3.28 ms / 2.11 ms 578 ms

Measured on a Samsung Galaxy S26 (Snapdragon 8 Elite Gen 5 / SM8850, Hexagon v81, Android 16) with LiteRT CompiledModel 2.2.0, one accelerator per process, 5 warm-up runs then N=50 timed runs, median reported. Every run held thermal status NONE throughout. Headroom 0.54–0.79, where 1.0 is the throttling threshold.

The NPU rows ran the published file unchanged. LiteRT compiled it for the Hexagon on the device at first load. Those first compiles took 985 ms to 25 s here. The load column above is the cached load every later run pays. Recipe and the runtime libraries it needs: NPU guide.

GPU wiring: GPU guide.

License

Apache-2.0, following the upstream TencentARC/GFPGAN.

Downloads last month
121
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for litert-community/GFPGAN-v1.4-LiteRT

Finetuned
(1)
this model

Space using litert-community/GFPGAN-v1.4-LiteRT 1

Collection including litert-community/GFPGAN-v1.4-LiteRT