Face ID
Easily run face detection, landmark prediction, facial recognition, and attribute estimation in Rust via ONNX Runtime.

Features
- Detection: Face detection using SCRFD. Coordinates are relative to image dimensions (0.0 to 1.0).
- Landmarks: Predict 5 facial keypoints (eyes, nose, mouth) for alignment (also relative).
- Recognition: Generate 512-d embeddings using ArcFace for identity verification.
- Attributes: Estimate gender and age.
- Automatic Alignment: Built-in transforms to align faces to the pose required by recognition models.
- HF Integration: Automatically download pre-trained models from HuggingFace.
Usage
The FaceAnalyzer is the easiest way to use this crate. It handles the entire pipeline: detecting faces, aligning them,
and running recognition/attribute models in batches.
use FaceAnalyzer;
async
Usage: Individual Components
You can also use the components individually if you don't need the full pipeline.
Face Detection only
The ScrfdDetector finds face bounding boxes when given an image. When using a _kps model, it also returns the
location of the eyes, nose and mouth.
use ScrfdDetector;
async
Facial Recognition (Embeddings)
Recognition requires aligned face crops, meaning the eyes, nose and mouth are warped to the spot the embedding model
expects them. This crate provides face_align::norm_crop to transform a face based on its landmarks into the 112x112
format required by ArcFace.
use ArcFaceEmbedder;
use norm_crop;
async
Clustering & Face Crop
You can cluster faces from many images and then extract cropped faces using two helper functions:
use FaceAnalyzer;
use ;
async
Loading Local Models
If you want to use local ONNX model files instead of downloading from HuggingFace,
use the builder method.
use FaceAnalyzer;
Customizing Hugging Face Models
You can mix and match specific model versions from Hugging Face repositories.
For example, using the medium-complexity 10g_bnkps detector instead of the default:
use FaceAnalyzer;
use HfModel;
async
Execution Providers (Nvidia, AMD, Intel, Mac, Arm, etc.)
Since this is implemented with ort, many execution providers are available to enable hardware acceleration. You can
enable an execution provider in this crate with cargo features. A full list of execution providers is
available here.
To use CUDA, add the cuda feature to your Cargo.toml and configure the builder:
use FaceAnalyzer;
use ;
async
Model Details
Detection (SCRFD)
The naming convention for SCRFD models indicates complexity (FLOPs) and whether they include 5-point facial keypoints (
kps).
| Name | Easy | Medium | Hard | FLOPs | Params(M) | Infer(ms) | BBox | Facial Keypoints |
|---|---|---|---|---|---|---|---|---|
| 500m.onnx | 90.57 | 88.12 | 68.51 | 500M | 0.57 | 3.6 | ✅ | ❌ |
| 1g.onnx | 92.38 | 90.57 | 74.80 | 1G | 0.64 | 4.1 | ✅ | ❌ |
| 34g.onnx | 96.06 | 94.92 | 85.29 | 34G | 9.80 | 11.7 | ✅ | ❌ |
| 2.5g_bnkps.onnx | 93.80 | 92.02 | 77.13 | 2.5G | 0.82 | 4.3 | ✅ | ✅ |
| 10g_bnkps.onnx | 95.40 | 94.01 | 82.80 | 10G | 4.23 | 5.0 | ✅ | ✅ |
| 34g_gnkps.onnx | 96.17 | 95.19 | 84.88 | 34G | 9.84 | 11.8 | ✅ | ✅ |
- BN vs GN:
bnkps(Batch Norm) models have higher general recall.gnkps(Group Norm) models are specifically better at handling very large faces or faces rotated past 90 degrees. - Easy/Medium/Hard refers to accuracy on training data, source: insightface.
34g_gnkpsis an evolution of thebnkpsmodels, more info, and source for thegnkpsnumbers here: https://modelscope.cn/models/iic/cv_resnet_facedetection_scrfd10gkps/summary
Recognition (ArcFace)
The default recognition model is w600k_r50.onnx (ResNet-50) from the InsightFace "Buffalo_L" bundle. It produces a *
512-dimensional* L2-normalized vector.
Features
hf-hub(Default): Allows downloading models from Hugging Face.copy-dylibs/download-binaries(Default): Simplifiesortsetup.serde: Enables serialization/deserialization for results.clustering(Default): Enables face clustering using HDBSCAN.- Execution Providers:
cuda,tensorrt,coreml,directml,openvino, etc.
Troubleshooting
Dynamic Linking
If you are using the load-dynamic feature and encounter library errors:
- Download the
onnxruntimelibrary from GitHub Releases. - Set the
ORT_DYLIB_PATHenvironment variable:# Linux/macOS export ORT_DYLIB_PATH="/path/to/libonnxruntime.so" # Windows (PowerShell) $env:ORT_DYLIB_PATH = "C:/path/to/onnxruntime.dll"