Selfie Segmenter (MediaPipe)
Overview
Selfie Segmenter segments the portrait of a person and can be used to replace or modify the background of an image. Given a normalized RGB image, the model returns a single-channel grayscale mask where each pixel value expresses the probability that the corresponding pixel belongs to the foreground (a person). Its architecture is based on MobileNetV3 with added customized decoder blocks for segmentation.
There are two variants of the same model: General (256x256) and Landscape (256x144). The general variant is more accurate than the landscape variant since its input image is larger and more features can be extracted. The landscape variant runs faster and achieves real-time performance on both CPU (XNNPack delegate) and NPU (VX Delegate and Ethos-U Delegate).
This repository ships both variants, quantized to int8 for deployment on NXP i.MX platforms (i.MX 8M Plus,
i.MX 93, i.MX 95 and i.MX 952). It also contains the scripts used to regenerate these assets (recipe.sh)
and an inference example (example.py).
Key Features
- Fully quantized int8 model ready for edge deployment, with float32 input and float32 output.
- Lightweight MobileNetV3-based backbone with customized segmentation decoder.
- Two input resolutions: general (256x256) and landscape (256x144).
- Outputs a per-pixel grayscale foreground mask in the range [0.0, 1.0].
- Compatible with i.MX 8M Plus (CPU/VX NPU delegate), i.MX 93 (Ethos-U65 NPU) and i.MX 95 / i.MX 952 (eIQ Neutron NPU).
Model Description
This is a quantized version of the MediaPipe Selfie Segmenter model, optimized for NXP i.MX platforms.
- Base Model: MediaPipe Image Segmenter - Selfie Segmenter
- Original Model Authors: Tingbo Hou, Siargey Pisarchyk, Karthik Raveendran (Google)
- Original License: Apache-2.0
- Modified by: NXP
Modifications
This model is a derivative work with the following changes from the original:
- Format conversion: the original MediaPipe float16
*.tflitemodel is converted to a TensorFlow SavedModel (*.pb) using tflite2tensorflow, then re-exported to TFLite. - Quantization: full int8 post-training quantization (weights and activations); the model keeps float32 input and float32 output. Calibration is performed with 68 images from the COCO 2017 validation dataset that do not belong to the original (proprietary) MediaPipe training dataset.
- Compilation (i.MX 93): compiled with the Vela compiler,
tags
lf-6.18.20_2.0.0andlf-6.18.37_2.1.0. - Compilation (i.MX 95 / i.MX 952): converted with the eIQ Neutron SDK, versions
3.1.3and3.2.1for i.MX 95, and3.1.3,3.2.1and3.2.3for i.MX 952.
Original model available at: https://developers.google.com/mediapipe/solutions/vision/image_segmenter.
Model Information
| Information | Value (General) | Value (Landscape) |
|---|---|---|
| Input shape | RGB image (1, 256, 256, 3), float32 | RGB image (1, 144, 256, 3), float32 |
| Input value range | [0.0, 1.0] (normalized as pixel / 255) | [0.0, 1.0] (normalized as pixel / 255) |
| Input example | ||
| Output shape | Grayscale mask (1, 256, 256, 1), float32 | Grayscale mask (1, 144, 256, 1), float32 |
| Output value range | [0.0, 1.0] | [0.0, 1.0] |
| Output example | ||
| FLOPS | 127.7 M OPS (63.84 M MACs) | 71.6 M OPS (35.78 M MACs) |
| File size (int8) | ~216 KB | ~216 KB |
| Source framework | MediaPipe (TensorFlow Lite) | MediaPipe (TensorFlow Lite) |
Supported Hardware and Software Configurations
All models run with the eIQ LiteRT (TensorFlow Lite) runtime and the corresponding NPU delegate (VX for i.MX 8M Plus, Ethos-U for i.MX 93, Neutron for i.MX 95 / i.MX 952). Each link points to a directory containing both variants (general and landscape). The same information is captured in release_manifest.json.
| Asset | Runtime | Precision | HW target | BSP & SDK versions | Link to asset |
|---|---|---|---|---|---|
| i.MX 8M Plus Quantized | LiteRT | INT8 | i.MX 8M Plus | - | Download |
| i.MX 93 Precompiled | LiteRT | INT8 | i.MX 93 | BSP lf-6.18.20_2.0.0, VELA_TAG = lf-6.18.20_2.0.0 | Download |
| i.MX 93 Precompiled | LiteRT | INT8 | i.MX 93 | BSP lf-6.18.37_2.1.0, VELA_TAG = lf-6.18.37_2.1.0 | Download |
| i.MX 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 | Download |
| i.MX 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 | Download |
The hardware-independent int8 models are also provided for host (x86) inference and as the input to the
compilers above: assets/quantized_tflite_model/.
Limitations and Biases
This model inherits all limitations from the original MediaPipe Selfie Segmenter model. Additional limitations:
- Task scope: Person/background segmentation only. The model does not identify or recognize individuals and should not be used for any form of surveillance or identity recognition.
- Distance and multi-person scenes: The model is not expected to work well for people too far away from the camera (~4 meters) or for scenes with multiple people across different scales.
- Dataset bias: The original model was trained by MediaPipe on a proprietary dataset that is not provided; any biases present in that dataset (for example with respect to pose, lighting, skin tone or demographic group) are inherited by this model and were not assessed by NXP.
For more information, see the MediaPipe Selfie Segmenter model card.
Training
The model was trained by Google/MediaPipe on a proprietary dataset which is not provided. NXP did not retrain the model; NXP's contribution is limited to quantization and compilation as described in Modifications. Calibration during quantization uses a subset of the COCO dataset [1] that does not belong to the original training dataset.
Evaluation
Because ground truths for the original (proprietary) training/validation data are not available, this model
was not evaluated for accuracy against labeled data. As an alternative, cosine similarity between the
MediaPipe FP16 model and the quantized int8 model was computed on the test dataset (Selfie) from the
Selfie-Image-Detection-Dataset
(3,931 images), on a host PC. This repository does not include an evaluate.py script; no accuracy or
performance numbers are reported here.
Download and Run
The recipe installs the eIQ Neutron SDK from the NXP eIQ PyPI Distribution Portal. Configure pip once to use it:
python -m pip config --user set global.index https://eiq.nxp.com/repository
python -m pip config --user set global.index-url https://eiq.nxp.com/repository
python -m pip config --user set global.trusted-host eiq.nxp.com
python -m pip config --user set global.extra-index-url https://pypi.org/simple
python -m pip config --user set global.find-links https://eiq.nxp.com/repository/
To download the model, quantize it, and compile it for all supported platforms, run:
bash recipe.sh [VELA_TAG] [NEUTRON_VERSION_IMX95] [NEUTRON_VERSION_IMX952]
For example, to build the second toolchain versions:
bash recipe.sh lf-6.18.37_2.1.0 3.2.1 3.2.3
This will:
- Download the MediaPipe Selfie Segmenter float16 models (general and landscape).
- Convert and quantize both to int8 TFLite (
assets/quantized_tflite_model/). - Compile them with Vela for i.MX 93 (Ethos-U65 NPU).
- Convert them with the eIQ Neutron SDK for i.MX 95 and i.MX 952.
An example of running inference is in example.py (run on a PC):
# Run on PC:
python3 example.py -m assets/quantized_tflite_model/selfie_segmenter_int8.tflite -i data/example_input.jpg -o data/example_output.jpg
example.py accepts -m/--model (default
assets/quantized_tflite_model/selfie_segmenter_int8.tflite), -i/--input (default
data/example_input.jpg), -o/--output (default data/example_output.jpg) and -t/--threshold (default
0.1, the confidence threshold for the foreground mask).
To run the model on an i.MX MPU target with the NPU delegates, see the i.MX Machine Learning User Guide.
Full on-device examples leveraging GStreamer/NNStreamer and this model can be found in nxp-nnstreamer-examples on GitHub.
Below is an NNStreamer pipeline example for the Selfie Segmenter model on i.MX 8M Plus with NPU acceleration (VX Delegate). The output shows the input camera video and the segmentation mask side by side:
gst-launch-1.0 --no-position v4l2src device=/dev/video3 ! \
video/x-raw,width=640,height=480,framerate=30/1 ! \
aspectratiocrop aspect-ratio=1/1 ! \
imxvideoconvert_g2d ! video/x-raw,width=480,height=480 ! \
tee name=t t. ! queue max-size-buffers=2 leaky=2 ! \
imxvideoconvert_g2d ! video/x-raw,width=256,height=256,format=RGBA ! \
videoconvert ! video/x-raw,format=RGB ! \
tensor_converter ! \
tensor_transform mode=arithmetic option=typecast:float32,div:255.0 ! \
tensor_filter framework=tensorflow-lite model=selfie_segmenter_int8.tflite \
custom=Delegate:External,ExtDelegateLib:libvx_delegate.so ! \
tensor_decoder mode=image_segment option1=snpe-depth option2=0 ! \
imxvideoconvert_g2d ! \
video/x-raw,width=480,height=480,format=RGBA ! \
mix. t. ! queue max-size-buffers=2 leaky=2 ! \
imxcompositor_g2d name=mix latency=30000000 min-upstream-latency=30000000 \
sink_1::ypos=0 sink_1::width=480 sink_1::height=480 \
sink_0::ypos=0 sink_0::xpos=480 sink_0::width=480 sink_0::height=480 ! \
waylandsink

License
This model, including the quantized and compiled assets and the scripts in this repository, is released under the MIT License (see LICENSE). The original MediaPipe Selfie Segmenter model is released under the Apache-2.0 License (https://www.apache.org/licenses/LICENSE-2.0.html).
Citation
If you use this model, please cite both this work and the original model:
- Google MediaPipe, "Image segmentation guide." [Online]. Available: https://developers.google.com/mediapipe/solutions/vision/image_segmenter
- T. Hou, S. Pisarchyk, K. Raveendran, "MediaPipe Selfie Segmentation Model Card," Google, 2021. [Online]. Available: https://storage.googleapis.com/mediapipe-assets/Model%20Card%20MediaPipe%20Selfie%20Segmentation.pdf
- T.-Y. Lin et al., "Microsoft COCO: Common Objects in Context," European Conference on Computer Vision. Springer, Cham, 2014.
@misc{mediapipe_selfie_segmenter,
title = {MediaPipe Image Segmenter: Selfie Segmentation},
author = {Hou, Tingbo and Pisarchyk, Siargey and Raveendran, Karthik},
howpublished = {Google MediaPipe},
year = {2021},
url = {https://developers.google.com/mediapipe/solutions/vision/image_segmenter}
}
@inproceedings{lin2014microsoft,
title={Microsoft COCO: Common Objects in Context},
author={Lin, Tsung-Yi and Maire, Michael and Belongie, Serge and Hays, James and Perona, Pietro and Ramanan, Deva and Dollar, Piotr and Zitnick, C Lawrence},
booktitle={European Conference on Computer Vision},
year={2014},
organization={Springer}
}