đ Face Parsing
This is a Semantic segmentation model fine - tuned from nvidia/mit-b5 with CelebAMask-HQ for face parsing. It provides solutions for face parsing tasks.

This Semantic segmentation model is fine - tuned from nvidia/mit-b5 using the CelebAMask-HQ dataset for face parsing. For more options, refer to the Transformers Segformer docs.
The ONNX model for web inference is contributed by Xenova.
đ Quick Start
đģ Usage Examples
Basic Usage in Python
An exhaustive list of labels can be extracted from config.json.
id |
label |
note |
0 |
background |
|
1 |
skin |
|
2 |
nose |
|
3 |
eye_g |
eyeglasses |
4 |
l_eye |
left eye |
5 |
r_eye |
right eye |
6 |
l_brow |
left eyebrow |
7 |
r_brow |
right eyebrow |
8 |
l_ear |
left ear |
9 |
r_ear |
right ear |
10 |
mouth |
area between lips |
11 |
u_lip |
upper lip |
12 |
l_lip |
lower lip |
13 |
hair |
|
14 |
hat |
|
15 |
ear_r |
earring |
16 |
neck_l |
necklace |
17 |
neck |
|
18 |
cloth |
clothing |
import torch
from torch import nn
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
from PIL import Image
import matplotlib.pyplot as plt
import requests
device = (
"cuda"
if torch.cuda.is_available()
else "mps"
if torch.backends.mps.is_available()
else "cpu"
)
image_processor = SegformerImageProcessor.from_pretrained("jonathandinu/face-parsing")
model = SegformerForSemanticSegmentation.from_pretrained("jonathandinu/face-parsing")
model.to(device)
url = "https://images.unsplash.com/photo-1539571696357-5a69c17a67c6"
image = Image.open(requests.get(url, stream=True).raw)
inputs = image_processor(images=image, return_tensors="pt").to(device)
outputs = model(**inputs)
logits = outputs.logits
upsampled_logits = nn.functional.interpolate(logits,
size=image.size[::-1],
mode='bilinear',
align_corners=False)
labels = upsampled_logits.argmax(dim=1)[0]
labels_viz = labels.cpu().numpy()
plt.imshow(labels_viz)
plt.show()
Basic Usage in the browser (Transformers.js)
import {
pipeline,
env,
} from "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.14.0";
env.allowLocalModels = false;
model = await pipeline("image-segmentation", "jonathandinu/face-parsing");
const output = await model(url);
for (const m of output) {
print(`Found ${m.label}`);
m.mask.save(`${m.label}.png`);
}
Advanced Usage - p5.js
Since p5.js uses an animation loop abstraction, we need to take care loading the model and making predictions.
async function preload() {
const { pipeline, env } = await import(
"https://cdn.jsdelivr.net/npm/@xenova/transformers@2.14.0"
);
env.allowLocalModels = false;
model = await pipeline("image-segmentation", "jonathandinu/face-parsing");
print("face-parsing model loaded");
}
full p5.js example
đ Documentation
Model Description
Property |
Details |
Developed by |
Jonathan Dinu |
Model Type |
Transformer-based semantic segmentation image model |
License |
non - commercial research and educational purposes |
Resources for more information |
Transformers docs on Segformer and/or the original research paper. |
đ§ Technical Details
Limitations and Bias
â ī¸ Important Note
While the capabilities of computer vision models are impressive, they can also reinforce or exacerbate social biases. The CelebAMask-HQ dataset used for fine-tuning is large but not necessarily perfectly diverse or representative. Also, they are images of.... just celebrities.