SCRFD 500M KPS
Overview
SCRFD (Sample and Computation Redistribution for Efficient Face Detection) is an efficient, high-accuracy face detector originally described in the paper and accepted at ICLR 2022. Given an RGB image, the network detects faces and, for each face, returns a bounding box, a confidence score and five facial landmarks: left eye, right eye, nose tip, left mouth corner, and right mouth corner.
This repository contains the SCRFD-500M-KPS variant, retrained by NXP, 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 four input resolutions: 128x128, 256x256, 256x320 and 512x640. - i.MX RT MCUs (i.MX RT1170, i.MX RT700) as TensorFlow Lite Micro C byte-array headers, at three input resolutions: 128x128, 256x256 and 320x256.
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 model performs face detection with 5-point facial landmark localization. It does not perform face recognition/identification.
Key Features
- Lightweight face detector (0.57M parameters) suitable for edge devices.
- Detects multiple faces per image and returns 5 facial landmarks per face.
- Fully quantized int8 model with uint8 input (values 0-255) and uint8 (quantized) outputs.
- Provided at four input resolutions for MPUs (128x128, 256x256, 256x320, 512x640); the conversion scripts accept any HEIGHT and WIDTH supported by the network.
- 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 CPU and i.MX RT700 Neutron-64 NPU), shipped as C byte-array headers at 128x128, 256x256 and 320x256.
Model Description
This is a retrained, quantized and compiled version of the SCRFD-500M-KPS face detector from InsightFace, optimized for NXP i.MX MPUs and i.MX RT MCUs.
- Base Model: SCRFD-500M-KPS (InsightFace)
- Original Model Authors: Jia Guo, Jiankang Deng, Alexandros Lattas, Stefanos Zafeiriou (InsightFace)
- Original License: MIT (InsightFace source code)
- Modified by: NXP
Modifications
This model is a derivative work with the following changes from the original:
- Retraining: NXP retrained SCRFD-500M-KPS on WIDER FACE. The
retrained weights (
scrfd_500m_kps_retrained_epoch_640.pth) are owned by NXP and released under the MIT license. - Format conversion: PyTorch -> ONNX (InsightFace
scrfd2onnx.py) -> TensorFlow saved model -> TFLite (OpenVINO Model Optimizer and openvino2tensorflow). - Quantization (MPU models): full int8 post-training quantization, uint8 input / uint8 outputs,
input normalization
data / 255, calibrated on ~100 images from the commercially-usable ImageNetV2 subset per resolution. - Compilation (i.MX 93): compiled with Vela
(
--accelerator-config ethos-u65-512 --optimise Performance), tagslf-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.3,3.2.1and3.2.3. - MCU models: a different int8 quantization of the same network (also uint8 input / uint8 outputs), taken
as-is from eIQ Media Processing Pipeline (MPP), compiled for i.MX RT700 with the eIQ Neutron SDK
3.2.2and3.2.3, and exported as C byte-array headers. - Post-processing: bounding box and landmark decoding plus non-maximum suppression are performed
outside the model (see
utils/scrfd.py).
Original model available at: https://github.com/deepinsight/insightface/tree/master/detection/scrfd.
Model Information
| Information | Value |
|---|---|
| Input shape | RGB image (1, H, W, 3), uint8 - shipped at 128x128, 256x256, 256x320, 512x640 (MPU) |
| Input example | (Image generated on thispersondoesnotexist.com) |
| Output shape | 9 tensors (per-stride scores, bbox distances, and keypoint distances for strides 8, 16 and 32), uint8 quantized; dequantize with each tensor's scale / zero point. See example.py to decode them. |
| Output example | (blue = bounding box, red = landmarks) |
| Version | SCRFD_500M_KPS (retrained by NXP) |
| FLOPS | ~0.5 GFLOPs at VGA (640x480) input, as defined by the original authors; scales with input resolution |
| Number of parameters | 0.57M |
| File size (int8) | 794 KB (assets/quantized_tflite_model/*.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 MCU headers run with TensorFlow Lite Micro through eIQ Media Processing Pipeline (MPP). Each link points to a directory containing one asset per listed resolution. The same information is captured in release_manifest.json.
| Asset | Runtime | Precision | HW target | BSP & SDK versions | Resolutions | Link to asset |
|---|---|---|---|---|---|---|
| i.MX 8M Plus Quantized | LiteRT | INT8 | i.MX 8M Plus | - | 128x128, 256x256, 256x320, 512x640 | 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 | 128x128, 256x256, 256x320, 512x640 | 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 | 128x128, 256x256, 256x320, 512x640 | Download |
| i.MX 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 | 128x128, 256x256, 256x320, 512x640 | Download |
| i.MX 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 | 128x128, 256x256, 256x320, 512x640 | Download |
| i.MX 95 Precompiled | LiteRT | INT8 | i.MX 95 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 | 128x128, 256x256, 256x320, 512x640 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.20_2.0.0, Neutron SDK v3.1.3 | 128x128, 256x256, 256x320, 512x640 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.1 | 128x128, 256x256, 256x320, 512x640 | Download |
| i.MX 952 Precompiled | LiteRT | INT8 | i.MX 952 | BSP lf-6.18.37_2.1.0, Neutron SDK v3.2.3 | 128x128, 256x256, 256x320, 512x640 | Download |
| i.MX RT1170 C header | TensorFlow Lite Micro | INT8 | i.MX RT1170 | MCUXpresso SDK 26.09.00 | 128x128, 256x256, 320x256 | Download |
| i.MX RT700 C header | TensorFlow Lite Micro | INT8 | i.MX RT700 | MCUXpresso SDK 26.09.00, Neutron SDK v3.2.2 | 128x128, 256x256, 320x256 | Download |
| i.MX RT700 C header | TensorFlow Lite Micro | INT8 | i.MX RT700 | MCUXpresso SDK 26.09.00, Neutron SDK v3.2.3 | 128x128, 256x256, 320x256 | Download |
The hardware-independent int8 models are also provided for host (x86) inference and as inputs to the
compilers: assets/quantized_tflite_model/ (MPU quantization) and assets/quantized_tflite_model_mcu/
(MCU quantization).
Limitations and Biases
This model inherits all limitations from the original SCRFD-500M-KPS model. Additional limitations:
- Task scope: Face detection and 5-point landmark localization only. The model does not identify or recognize individuals and does not estimate attributes such as age, gender or emotion.
- Hardware-specific: The Vela-compiled models only run on the i.MX 93 Ethos-U65 NPU and the
Neutron-converted models only run on the i.MX 95 / i.MX 952 / i.MX RT700 Neutron NPU with the
matching BSP / SDK versions listed above. Use the assets in
assets/quantized_tflite_model/for other targets. - Quantization effects: int8 quantization may introduce accuracy differences relative to the FP32 baseline. The MPU and MCU models use different quantizations and may produce slightly different results.
- Input resolution: Lower input resolutions (e.g. 128x128) reduce compute but also reduce the ability to detect small or distant faces.
- 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 original SCRFD model was trained by its authors on the WIDER FACE
training set. NXP retrained the SCRFD-500M-KPS variant on WIDER FACE using the InsightFace training code;
the resulting weights (scrfd_500m_kps_retrained_epoch_640.pth) are provided in this repository under the
MIT license.
Evaluation
evaluate.py compares the int8 quantized model against its FP32 reference (the float32 TFLite model
exported at the same resolution by tflite/convert2tflite.sh) on the full WIDER FACE validation set
(3226 images). The evaluation runs on a host PC (x86) with the LiteRT CPU runtime, using the
hardware-independent models (assets/quantized_tflite_model/), not the NPU-compiled assets.
Download the WIDER FACE validation images, then run:
python evaluate.py \
--dataset WIDER_val/images \
--model_fp32 tflite/saved_model_scrfd_500m_bnkps_128x128/model_float32.tflite \
--model_quant assets/quantized_tflite_model/scrfd_500m_128x128_uint8.tflite \
--input_size 128,128
Download and Run
Running the example
example.py runs detection on an image on a host PC, draws bounding boxes (blue) and keypoints (red), and
saves example_output.jpg. Install the dependencies from requirements.txt first.
# Run on PC with the 128x128 model:
python example.py --model assets/quantized_tflite_model/scrfd_500m_128x128_uint8.tflite --image example_input.jpg --input_size 128,128
# Run on PC with the 512x640 model (input_size is WIDTH,HEIGHT):
python example.py --model assets/quantized_tflite_model/scrfd_500m_512x640_uint8.tflite --image example_input.jpg --input_size 640,512
To run the models on an i.MX MPU target with the NPU delegates, see the i.MX Machine Learning User Guide.
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 everything with the
default toolchain versions, run:
bash recipe.sh
The script takes four optional positional arguments:
bash recipe.sh [VELA_TAG] [NEUTRON_MPU_VER] [IMAGENETV2_PATH] [NEUTRON_MCU_VER]
defaulting to lf-6.18.20_2.0.0, 3.2.3, the dataset placeholder, and 3.2.3 respectively. The MCU
Neutron SDK version is the LAST argument so the pre-existing MPU arguments keep their positions.
Part A converts the retrained PyTorch weights in two Docker-based steps, per resolution:
- PyTorch to ONNX (
onnx/convert2onnx.sh): uses the InsightFacescrfd2onnx.pyexporter inside thepinto0309/mmtrackingimage. - ONNX to int8 TFLite (
tflite/convert2tflite.sh): uses OpenVINO Model Optimizer andopenvino2tensorflowinside theghcr.io/pinto0309/openvino2tensorflowimage, producing the float32 and full int8 (uint8 input / uint8 output) TFLite models. The calibration data is created bycreate_calib_data.py, which samples ~100 ImageNetV2 images, resizes them to the target HxW and stores the raw pixel values (0-255) as a.npyof shape(N, H, W, 3)(consumed with--calib_ds_type numpy; thedata / 255normalization is applied during calibration).
Both scripts accept HEIGHT and WIDTH positional arguments and therefore support any resolution:
cd onnx && ./convert2onnx.sh 512 640
cd tflite && ./convert2tflite.sh 512 640
The int8 model is then compiled with Vela for i.MX 93 and converted with the eIQ Neutron SDK for
i.MX 95 / i.MX 952. The generated MPU files (one set per resolution, <H>x<W> in
{128x128, 256x256, 256x320, 512x640}) are:
assets/quantized_tflite_model/scrfd_500m_<H>x<W>_uint8.tflite- hardware-independent int8 modelassets/imx8mplus/scrfd_500m_<H>x<W>_uint8.tflite- int8 model for i.MX 8M Plus (identical to the hardware-independent int8 model)assets/imx93/<VELA_TAG>/scrfd_500m_<H>x<W>_uint8_vela.tflite- Vela-compiled for i.MX 93assets/imx95/<NEUTRON_MPU_VER>/scrfd_500m_<H>x<W>_uint8_converted.tflite- Neutron-converted for i.MX 95assets/imx952/<NEUTRON_MPU_VER>/scrfd_500m_<H>x<W>_uint8_converted.tflite- Neutron-converted for i.MX 952
Part B compiles the MCU base models for i.MX RT700 with the eIQ Neutron Compiler and regenerates every
header with xxd -i plus the NXP banner (see the next section).
MCU targets (TensorFlow Lite Micro)
On MCUs the shippable artifacts are C header files containing the model as a byte array, to be
compiled directly into the firmware image - not .tflite files. The base .tflite models are provided in
assets/quantized_tflite_model_mcu/ for reference and for re-running the conversion.
Note: the MCU models are a different quantization of the same network than the MPU models above (same uint8 input / uint8 output interface, but different quantization parameters) and are taken as-is from eIQ MPP, so they are neither re-trained nor re-quantized by
recipe.sh. They are shipped side by side with the MPU models under their eIQ MPP names.
Three input resolutions are available for MCUs, named WIDTHxHEIGHT following the eIQ MPP convention
(so 320x256 is the landscape variant that the MPU section calls 256x320). There is no 512x640 MCU
build.
| MCU | Compute | Neutron target | Directory |
|---|---|---|---|
| i.MX RT1170 | Cortex-M7 (CPU, no NPU) | - | assets/rt1170/ |
| i.MX RT700 | Neutron-64 NPU | imxrt700 | assets/rt700/3.2.2/, assets/rt700/3.2.3/ |
The i.MX RT700 build converts 133/133 operators to the NPU (100%, a single Neutron graph), for both SDK versions.
For each resolution <RES> in {128x128, 256x256, 320x256}:
assets/quantized_tflite_model_mcu/scrfd_kps_500m_full_integer_quant_<RES>.tflite- base int8 modelassets/rt1170/scrfd_kps_500m_full_integer_quant_<RES>_tflite.h- model byte array for i.MX RT1170 (CPU)assets/rt1170/scrfd_kps_500m_full_integer_quant_<RES>_tflite_info.h- pre/post-processing constantsassets/rt700/<neutron_sdk_version>/scrfd_kps_500m_full_integer_quant_<RES>_npu64_tflite.h- model byte array for i.MX RT700, for<neutron_sdk_version>in {3.2.2,3.2.3}
The CPU target (i.MX RT1170) has no NPU toolchain, so its headers live directly under assets/rt1170/. The
Neutron (NPU) headers are versioned by the eIQ Neutron SDK used to compile them and therefore live in a
version-named subdirectory (assets/rt700/<neutron_sdk_version>/), mirroring the assets/imx95/<version>/
layout used for the MPU targets.
Each header declares the array as scrfd_kps_data with its length in scrfd_kps_data_len, aligned to
16 bytes. The i.MX RT700 headers additionally place the array in the .modeldata linker section via the
__PLACEMENT macro.
Pre- and post-processing constants are taken from the *_tflite_info.h headers. Input is RGB, normalized
with mean 0 and std 255 (that is, pixels scaled to [0, 1]):
| Constant | 128x128 | 256x256 | 320x256 |
|---|---|---|---|
| Input width x height | 128x128 | 256x256 | 320x256 |
| Boxes at stride 8 | 512 | 2048 | 2560 |
| Boxes at stride 16 | 128 | 512 | 640 |
| Boxes at stride 32 | 32 | 128 | 160 |
The model has 9 output tensors - per-stride scores, bounding-box distances and keypoint distances for the small (stride 8), medium (stride 16) and large (stride 32) levels - and regresses 5 landmarks per detected box.
Runnable MCU examples are provided by eIQ Media Processing Pipeline (MPP), not by this repository. See the eIQ MPP User's Guide.
License
This model, including the NXP-retrained weights, the quantized and compiled assets and the scripts in this repository, is released under the MIT License (see LICENSE). The original InsightFace SCRFD source code is also released under the MIT License.
Citation
If you use this model, please cite both this work and the original model:
- J. Guo, J. Deng, A. Lattas and S. Zafeiriou, "Sample and Computation Redistribution for Efficient Face Detection," International Conference on Learning Representations (ICLR), 2022. arXiv:2105.04714.
- S. Yang, P. Luo, C. C. Loy and X. Tang, "WIDER FACE: A Face Detection Benchmark," Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2016.
@inproceedings{guo2022sample,
title={Sample and Computation Redistribution for Efficient Face Detection},
author={Guo, Jia and Deng, Jiankang and Lattas, Alexandros and Zafeiriou, Stefanos},
booktitle={International Conference on Learning Representations},
year={2022}
}
@inproceedings{yang2016wider,
title={WIDER FACE: A Face Detection Benchmark},
author={Yang, Shuo and Luo, Ping and Loy, Chen Change and Tang, Xiaoou},
booktitle={IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year={2016}
}