Ultraface slim

Overview

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. The bounding box decoding and non-maximum suppression steps are included in the model graph.

This repository contains the Ultraface slim variant, quantized to int8 and compiled for NXP platforms:

  • i.MX MPUs (i.MX 8M Plus, i.MX 93, i.MX 95, i.MX 952) as LiteRT (.tflite) models at a fixed 320x240 input resolution.
  • i.MX RT MCUs (i.MX RT1170) as a TensorFlow Lite Micro C byte-array header.

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.

Key Features

  • Very small (~400 KB int8) and fast face detector suitable for 320x240 inputs.
  • Bounding box decoding and NMS are baked into the MPU model graph, so its output is a ready-to-use list of faces.
  • Fully quantized int8 model with uint8 input and float32 output (MPU variant).
  • Compiled for the i.MX 93 Ethos-U65 NPU (Vela) and converted for the i.MX 95 / i.MX 952 eIQ Neutron NPU.
  • Also available for MCUs under TensorFlow Lite Micro (i.MX RT1170), shipped as a C byte-array header.

Model Description

This is a quantized and compiled version of the Ultraface slim face detector from Ultra-Light-Fast-Generic-Face-Detector-1MB, optimized for NXP i.MX MPUs and i.MX RT MCUs.

Modifications

This model is a derivative work with the following changes from the original:

  • Format conversion: the original PyTorch model is converted to a TensorFlow saved model (convert_tensorflow.py) and then to TensorFlow Lite. A patch (slim.patch) adapts the post-processing so that the box decoding and non-maximum suppression are folded into the exported graph, producing a fixed-size (100, 6) output tensor.
  • Quantization (MPU model): full int8 post-training quantization, uint8 input (values 0-255) / float32 output, calibrated on 100 images sampled from a commercially-usable ImageNetV2 subset (WIDER FACE cannot be used for calibration due to licensing).
  • Compilation (i.MX 93): compiled with Vela (--accelerator-config ethos-u65-256 --optimise Performance), tag lf-6.18.20_2.0.0 (the lf-6.18.37_2.1.0 directory ships a byte-identical copy of the same Vela-compiled model, rebuilt against that BSP for compatibility).
  • Compilation (i.MX 95 / i.MX 952): converted with the eIQ Neutron SDK, versions 3.1.3, 3.2.1 and 3.2.3.
  • MCU model: a different int8 quantization/export of the same network (int8 input / int8 output, no in-graph NMS, raw (1, 4420, 6) output), taken as-is from eIQ Media Processing Pipeline (MPP) and exported as a C byte-array header for i.MX RT1170.
  • Post-processing (MCU model only): thresholding and non-maximum suppression are performed outside the graph by the application.

Original model available at: https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB.

Model Information

Information Value
Input shape RGB image (1, 240, 320, 3), uint8
Input example
Output shape Tensor of size (100, 6) containing up to 100 detected faces (class scores + box coordinates)
Output example
FLOPS 168,707,432
Number of parameters 264,732
File size (int8) 403 KB (assets/quantized_tflite_model/ultraface_slim_uint8_float32.tflite)
Source framework PyTorch

Supported Hardware and Software Configurations

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 i.MX RT1170 header runs 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

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 (uint8 input / float32 output) and the MCU interface (int8 input / int8 output) are also provided for host (x86) inference: assets/quantized_tflite_model/ and assets/quantized_tflite_model_mcu/ respectively.

Limitations and Biases

This model inherits all limitations from the original Ultraface slim model. Additional limitations:

  • Task scope: Face detection only. The model does not identify or recognize individuals and does not estimate attributes such as age, gender or emotion.
  • Dataset bias: The model is trained on WIDER FACE. Detection quality may vary for faces, poses, lighting conditions, occlusions or demographic groups that are under-represented in that dataset.

Training

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, converted and quantized as described in Modifications.

Evaluation

evaluate.py evaluates the int8 quantized model (assets/quantized_tflite_model/ultraface_slim_uint8_float32.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). 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_slim_uint8_float32.tflite -d WIDER_val -g ground_truth

Download and Run

Running the example

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_slim_uint8_float32.tflite -i example_input.jpg -o example_output.jpg

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.

Regenerating the assets with recipe.sh

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 (uint8 input, float32 output), compile it for all supported MPU platforms and generate the MCU C header, run:

bash recipe.sh

The generated model files are:

  • assets/quantized_tflite_model/ultraface_slim_uint8_float32.tflite - hardware-independent int8 model for i.MX 8M Plus
  • assets/imx93/lf-6.18.20_2.0.0/ultraface_slim_uint8_float32_vela.tflite - Vela-compiled for i.MX 93
  • assets/imx95/3.2.3/ultraface_slim_uint8_float32_converted.tflite - Neutron-converted for i.MX 95
  • assets/imx952/3.2.3/ultraface_slim_uint8_float32_converted.tflite - Neutron-converted for i.MX 952
  • assets/rt1170/ultraface_slim_tflite.h - C byte array of the int8 MCU model for i.MX RT1170

MCU targets (TensorFlow Lite Micro)

Besides the i.MX MPU files, this repository also ships Ultraface slim 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 quantization/export of the same network (assets/quantized_tflite_model_mcu/ultraface_slim_int8_mcu.tflite, int8 input / int8 output). It ships in its own assets/quantized_tflite_model_mcu/ directory. Unlike the MPU model files, it does NOT include the box decoding and non-maximum suppression in the graph: its output is the raw (1, 4420, 6) tensor ([no_face_score, face_score, left, top, right, bottom] per center prior), so the application performs the thresholding and NMS itself.

MCU Core / Accelerator Directory
i.MX RT1170 Cortex-M7, CPU only assets/rt1170/
assets/quantized_tflite_model_mcu/ultraface_slim_int8_mcu.tflite   base int8 MCU model, 320x240

assets/rt1170/ultraface_slim_tflite.h                  i.MX RT1170 (CPU)
assets/rt1170/ultraface_slim_tflite_info.h             matching metadata header

The i.MX RT1170 header uses the plain int8 model (no NPU), found directly under assets/rt1170/. The *_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 (ULTRAFACE_INPUT_MEAN 128, ULTRAFACE_INPUT_STD 127, ULTRAFACE_WIDTH 320, ULTRAFACE_HEIGHT 240, ULTRAFACE_OUTPUT_SCALE 0.00392156f, ULTRAFACE_OUTPUT_ZERO_POINT -128.0f).

Ready-to-run application examples that use this model are included in the eIQ Media Processing Pipeline (MPP):

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 Ultraface slim model is also released under the MIT License (see MODEL_LICENSE).

Citation

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}
}
Downloads last month
268
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collections including nxp/ultraface-slim-imx