MediaPipe Hair Segmenter

Real-time selfie hair segmentation model (hair_segmenter.tflite, 782 KB, FP32) returning per-pixel probabilities for 0: background and 1: hair for virtual hair recoloring and AR filters via the MediaPipe Image Segmenter (ImageSegmenter) task.

Documentation: MediaPipe Image Segmenter Docs

Samples: Android · iOS · Python Colab · Web · Flutter

Try live: Web Demo

Encoder-decoder architecture with skip connections taking a 4-channel [1, 512, 512, 4] input (RGB plus temporal/prior channel, populated automatically by MediaPipe ImageSegmenter) and predicting a 2-channel hair segmentation mask (background, hair).

Files

File Precision Size SHA-256
hair_segmenter.tflite float32 781.6 KB (781,618 B) 2628cf3ce5f695f604cbea2841e00befcaa3624bf80caf3664bef2656d59bf84

Companion Files in Repo Root

File Role Size SHA-256
Model Card - Hair Segmentation.pdf Upstream Google model card (PDF) 341.9 KB (341,893 B) 369a9ded9ed15dce5525d05ff00bedce54f9e3b9033195609eff49f479c94c67

Download

pip install -U huggingface_hub
hf download litert-community/MediaPipe-ImageSegmenter-Hair hair_segmenter.tflite --local-dir .

Inputs, Outputs, and Model Specifications

hair_segmenter.tflite

  • Embedded TFLITE_METADATA: name ImageSegmenter · version 1 · author MediaPipe · packed associated files: labels.txt
Direction Tensor Shape Type Notes
Input input_1 [1, 512, 512, 4] float32 image — Input image to be processed. — Normalization: mean=[0.0], std=[255.0]
Output conv2d_transpose_4 [1, 512, 512, 2] float32 segmentation_masks — Masks over the target objects with high accuracy. — Labels: labels.txt

Use with MediaPipe Tasks

Python Quickstart

pip install -U mediapipe huggingface_hub
import mediapipe as mp
from huggingface_hub import hf_hub_download

model_path = hf_hub_download(
    repo_id="litert-community/MediaPipe-ImageSegmenter-Hair",
    filename="hair_segmenter.tflite",
)

BaseOptions = mp.tasks.BaseOptions
ImageSegmenter = mp.tasks.vision.ImageSegmenter
ImageSegmenterOptions = mp.tasks.vision.ImageSegmenterOptions
VisionRunningMode = mp.tasks.vision.RunningMode

options = ImageSegmenterOptions(
    base_options=BaseOptions(model_asset_path=model_path),
    running_mode=VisionRunningMode.IMAGE,
    output_category_mask=True,
    output_confidence_masks=True,
)

with ImageSegmenter.create_from_options(options) as runner:
    mp_image = mp.Image.create_from_file("input.jpg")
    result = runner.segment(mp_image)
    print("Labels:", runner.labels, "masks:", len(result.confidence_masks))

Cross-Platform Guides & Samples

Latency Benchmarks

End-to-end MediaPipe Task pipeline average latency reported by the Image Segmenter documentation:

Model Variant Device CPU Latency GPU Latency
HairSegmenter Pixel 6 57.90 ms 52.14 ms

Intended Use, Limitations, and Fairness

Summarized from the bundled Model Card - Hair Segmentation.pdf (Google, 2019-01-14):

  • Intended applications: Segmenting a single person's hair in front-facing selfie images or video for AR recoloring and entertainment effects.
  • Out-of-scope & limitations:
    • Not appropriate for human life-critical decisions (primary intended application is entertainment).
    • Optimized for close front-facing selfies; not suitable for subjects > 1.5 m (5 ft) away or multiple people in a frame.
    • May miss thin hair strands, elongated braids, mohawks, or hair occluded by headwear.
  • Fairness evaluation (1,445 real-world selfies, 85 from each of 17 UN geographic subregions): Overall mean IoU 81.5% ± 0.8% (SD 16.3%, regional range from 75.2% Western Africa to 86.9% Southern Asia).

Provenance

Every model binary in this repository is byte-identical (unmodified FlatBuffer weights and embedded TFLITE_METADATA bytes) to the official artifact served by Google from storage.googleapis.com/mediapipe-models.

Repo File Upstream URL GCS Generation Upstream Last-Modified Pinned Bucket Version
hair_segmenter.tflite hair_segmenter.tflite 1682480018539483 Wed, 26 Apr 2023 03:33:38 GMT /1/

License and Citation

  • License: apache-2.0 — Stated as Apache License, Version 2.0 in the bundled upstream Google model-card PDF.

Citation

@inproceedings{tkachenka2019hair,
  title     = {Real-time Hair Segmentation and Recoloring on Mobile GPUs},
  author    = {Tkachenka, Artsiom and Karpushin, Gregory and Vakunov, Andrey and Tkachenka, Valentin},
  booktitle = {CVPR Workshop on Computer Vision for Augmented and Virtual Reality},
  year      = {2019}
}
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including litert-community/MediaPipe-ImageSegmenter-Hair