Ultraface is a lightweight face detection model designed for edge computing devices. Given an RGB image, it regresses bounding boxes (4 coordinates) and a confidence score for each detected face.
This repository contains the ultraslim variant: a cut-down version of the original Ultraface
model targeted at systems with very little memory (e.g. MCUs). Compared to the standard Ultraface
model it uses a 128x128 input instead of 320x240, removes the finest output level (so it only
detects reasonably large faces), and removes the non-maximum-suppression / confidence-threshold /
top-k post-processing from the graph, returning the raw anchor detections instead (these steps are
performed in example.py / evaluate.py). It is quantized to int8 and compiled for NXP platforms:
.tflite) models at a fixed
128x128 input resolution.It also contains the scripts used to regenerate these assets (recipe.sh), an inference example
(example.py) and an evaluation script (evaluate.py).
Note: This is only a face detection model. It does not perform face recognition/identification.
This is a quantized and compiled version of the Ultraface slim face detector from Ultra-Light-Fast-Generic-Face-Detector-1MB, cut down to a smaller "ultraslim" configuration and optimized for NXP i.MX MPUs and MCUs.
This model is a derivative work with the following changes from the original:
(172, 6) tensor of raw anchor detections from the three coarsest output
levels (ultraslim.patch).convert_tensorflow.py) and then to TensorFlow Lite.(pixel - 127) / 128.--accelerator-config ethos-u65-256 --optimise Performance), tags lf-6.18.20_2.0.0 and
lf-6.18.37_2.1.0.3.1.3,
3.2.1 and 3.2.3.assets/quantized_tflite_model_mcu/ultraface_ultraslim_int8_mcu.tflite), with the same int8 /
int8 interface and no box decoding or NMS in the graph, compiled from the eIQ Neutron Compiler for
MCX-N947 (--target mcxn94x) and i.MX RT700 (--target imxrt700) using eIQ Neutron SDK versions
3.2.2 and 3.2.3, then converted into C byte arrays with xxd -i. The i.MX RT1170 header wraps
the plain int8 MCU model unchanged (no NPU compilation).example.py / evaluate.py).Original model available at: https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB.
| Information | Value |
|---|---|
| Input shape | RGB image (1, 128, 128, 3), int8 |
| Input example | |
| Output shape | Tensor of size (172, 6) with the raw detections of the three coarsest output levels (class scores + box coordinates). See example.py to decode it. |
| Output example | |
| FLOPS | 38.0M |
| Number of parameters | 257,700 |
| File size (int8) | 374 KB (assets/quantized_tflite_model/ultraface_ultraslim_int8.tflite) |
| Source framework | PyTorch |
All MPU 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). The MCU headers run with TensorFlow Lite Micro through eIQ Media Processing Pipeline (MPP). 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 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 | 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 |
| i.MX RT1170 C header | TensorFlow Lite Micro | INT8 | i.MX RT1170 | MCUXpresso SDK 26.09.00 | Download |
| i.MX RT700 C header | TensorFlow Lite Micro | INT8 | i.MX RT700 | Neutron SDK v3.2.2, MCUXpresso SDK 26.09.00 | Download |
| i.MX RT700 C header | TensorFlow Lite Micro | INT8 | i.MX RT700 | Neutron SDK v3.2.3, MCUXpresso SDK 26.09.00 | Download |
| MCX-N947 C header | TensorFlow Lite Micro | INT8 | MCX-N947 | Neutron SDK v3.2.2, MCUXpresso SDK 26.09.00 | Download |
| MCX-N947 C header | TensorFlow Lite Micro | INT8 | MCX-N947 | Neutron SDK v3.2.3, MCUXpresso SDK 26.09.00 | Download |
The i.MX 8M Plus asset is a symlink to, and byte-identical with, the hardware-independent int8 model
in assets/quantized_tflite_model/. The hardware-independent int8 models for both the MPU interface
and the MCU interface are also provided for host (x86) inference:
assets/quantized_tflite_model/ and assets/quantized_tflite_model_mcu/ respectively.
This model inherits all limitations from the original Ultraface model. Additional limitations:
The model was trained on the WIDER FACE dataset by the original authors, according to the original source. NXP did not retrain this model; the weights are those of the original Ultraface slim release, modified, converted and quantized as described in Modifications.
evaluate.py evaluates the int8 quantized "ultraslim" model
(assets/quantized_tflite_model/ultraface_ultraslim_int8.tflite) on the WIDER FACE validation set
(3226 images) using the official WIDER FACE evaluation protocol (Average Precision at IoU 0.5 for the
easy/medium/hard subsets). Unlike the "slim" variant, the ultraslim graph does not include
non-maximum suppression, so confidence thresholding and NMS are applied in NumPy before scoring. The
evaluation runs on a host PC (x86) with the LiteRT CPU runtime.
Download the WIDER FACE validation images (the ground-truth .mat files are provided in the
ground_truth/ directory), then run:
# WIDER_val/ should contain the event sub-folders (e.g. 0--Parade/)
python evaluate.py -m assets/quantized_tflite_model/ultraface_ultraslim_int8.tflite -d WIDER_val -g ground_truth
Because the ultraslim model only detects large faces, scores on the full WIDER FACE validation set will be much lower than those of the full-size model.
An example showing how to run detection on an image is in example.py (run on a PC):
python example.py -m assets/quantized_tflite_model/ultraface_ultraslim_int8.tflite -i example_input.jpg -o example_output.jpg
Because the ultraslim model only detects large faces, example.py crops a central region before
resizing to 128x128 by default (configurable with --crop "x0,y0,x1,y1"; pass an empty string to
disable).
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.
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/
recipe.sh builds both the MPU (Part A) and the MCU (Part B) artifacts. To regenerate the TFLite
model fully quantized in int8 (int8 input, int8 output) and compile it for all supported platforms,
run:
bash recipe.sh [VELA_TAG] [NEUTRON_MPU_VERSION] [NEUTRON_MCU_VERSION]
defaulting to lf-6.18.20_2.0.0, 3.2.3 and 3.2.3 respectively. The calibration dataset path
(DATASET_PATH inside the script, a commercially-usable ImageNetV2 subset) must be set before
running, since WIDER FACE cannot be redistributed/used for quantization due to licensing.
Besides the i.MX MPU files, this repository also ships Ultraface ultraslim for NXP MCUs running TensorFlow Lite Micro. The MCU has no file system, so the shippable artifact there is a C header file (model byte array) that gets compiled directly into the firmware image.
The MCU variant is a separate int8 export of the same "ultraslim" network
(assets/quantized_tflite_model_mcu/ultraface_ultraslim_int8_mcu.tflite), with the same int8 /
int8 interface as the MPU model, and no box decoding or non-maximum suppression in the graph, so the
application performs the thresholding and NMS itself.
| MCU | Core / Accelerator | Neutron target | Directory |
|---|---|---|---|
| i.MX RT1170 | Cortex-M7, CPU only | - | assets/rt1170/ |
| MCX-N947 | Cortex-M33 + Neutron-16 NPU | mcxn94x |
assets/mcxn947/3.2.2/, assets/mcxn947/3.2.3/ |
| i.MX RT700 | Cortex-M33 + Neutron-64 NPU | imxrt700 |
assets/rt700/3.2.2/, assets/rt700/3.2.3/ |
assets/quantized_tflite_model_mcu/ultraface_ultraslim_int8_mcu.tflite base int8 MCU model, 128x128
assets/rt1170/ultraface_slim_ultraslim_tflite.h i.MX RT1170 (CPU)
assets/rt1170/ultraface_slim_ultraslim_tflite_info.h matching metadata header
assets/mcxn947/<version>/ultraface_slim_ultraslim_npu16_tflite.h MCX-N947 (Neutron-16)
assets/mcxn947/<version>/ultraface_slim_ultraslim_npu16_tflite_info.h matching metadata header
assets/rt700/<version>/ultraface_slim_ultraslim_npu64_tflite.h i.MX RT700 (Neutron-64)
assets/rt700/<version>/ultraface_slim_ultraslim_npu64_tflite_info.h matching metadata header
The i.MX RT1170 header uses the plain int8 model (no NPU), so it lives directly under
assets/rt1170/. The two NPU headers are compiled with the eIQ Neutron Compiler and therefore live in
a subdirectory named after the eIQ Neutron SDK version used. Both 3.2.2 and 3.2.3 are shipped for
MCX-N947 and i.MX RT700; the compiled model payload is unchanged between the two versions (only the
version stamp embedded in the banner comment differs), so either can be used.
Each *_tflite.h declares the model byte array (ultraface_data / ultraface_data_len) and is
accompanied by the matching *_tflite_info.h metadata header, which exposes the pre/post processing
constants the application needs.
Ready-to-run application examples that use this model are included in the eIQ Media Processing Pipeline (MPP):
camera_ultraface_view example (uses this model):
https://mcuxpresso.nxp.com/mcuxsdk/latest/html/examples/eiq_examples/mpp/camera_ultraface_view/readme.htmlThis model, including the quantized and compiled assets and the scripts in this repository, is released under the MIT License (see LICENSE). The original Ultraface model is also released under the MIT License (see MODEL_LICENSE).
If you use this model, please cite both this work and the original model:
@inproceedings{yang2016wider,
title={Wider face: A face detection benchmark},
author={Yang, Shuo and Luo, Ping and Loy, Chen-Change and Tang, Xiaoou},
booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition},
pages={5525--5533},
year={2016}
}