BiSeNet face parsing (fastforks)

BiSeNet (Yu et al. 2018) face parsing from face-parsing.PyTorch: a ResNet-18 context path with attention refinement and feature fusion, 19 CelebAMask-HQ face-part classes (skin, brows, eyes, glasses, ears, earrings, nose, mouth, lips, neck, necklace, cloth, hair, hat) on a 512 x 512 face crop. The parser that GFPGAN / CodeFormer pipelines use through facexlib; MIT code and weights.

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/xinntao/facexlib at 260620ae9399.

Task: segmentation. Tier: experimental. Outputs: logits. Backends: portable.

Input: one RGB image. Output: per-pixel class labels (logits with logits=True).

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
bisenet-face-parsing@1 parsing_bisenet.pth 468e13ca13a9 MIT yes

Licence

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

Training data: ImageNet-1k (ILSVRC 2012 classification), CelebAMask-HQ (30 000 CelebA-HQ faces, 19 face-part masks) (face-parsing.PyTorch train.py: CelebAMask-HQ (non-commercial research only), ResNet-18 initialised from torchvision's ImageNet weights.).

Licence evidence: https://github.com/zllrunning/face-parsing.PyTorch/blob/d2e684cf1588b46145635e8fe7bcc29544e5537e/LICENSE ; https://github.com/xinntao/facexlib/blob/260620ae93990a300f4b16448df9bb459f1caba9/LICENSE ; https://github.com/xinntao/facexlib/blob/260620ae93990a300f4b16448df9bb459f1caba9/facexlib/parsing/__init__.py

Input size

any H x W >= 1, resized or padded inside the model Tested up to (portable, fp16, RTX 5060 Ti 16 GB): bisenet-face-parsing 512x512 (0.0 GiB peak allocated, 0.1 reserved)

Speed and memory

Segmentation, synthetic

model input time (ms): original fp32 original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
bisenet-face-parsing 512x512 – 5.94 2.41 – – – 69 / 94 51 / 72 –

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
bisenet-face-parsing 0.31 (512x512) 0.20 (512x512) – 0.41 (512x512) 0.28 (512x512) –

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)
bisenet-face-parsing 512x512 2.41 ms 1.34 ms 0.678 ms – 5.79 s 12.9 s 51 / 72 76 / 110 – 85 / 110

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| <= 2.6e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0042 and p99 <= 0.02 (absolute error of the output logits).

Usage

from fastforks import segmentation

model = segmentation.load("bisenet-face-parsing")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.labels  # [H, W] per-pixel class index
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: bisenet-face-parsing.

Kernels backend

No kernels backend: measured slower: cudnn_hacc fp16-accumulate convolutions 2.77 ms vs 2.41 ms portable (512x512).

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/bisenet