AdaFace IR-50 (MS1MV2) — ONNX
ONNX export of the AdaFace IR-50 face-recognition backbone trained on
MS1MV2. Produces a 512-dimensional face embedding for verification /
identification. Runs on onnxruntime (CPU or CUDA) with no PyTorch dependency
at inference time.
This is a straight conversion of the published PyTorch checkpoint — the weights
are unchanged. It exists because AdaFace ships only as a PyTorch .ckpt and
this project's inference worker runs on onnxruntime.
Graph signature
| Name | Shape | Notes | |
|---|---|---|---|
| Input | input | (batch, 3, 112, 112) | ArcFace-aligned BGR face, normalized (x - 127.5) / 127.5 |
| Output | embedding | (batch, 512) | Face feature; L2-normalize before cosine comparison |
- Opset: 17. Dynamic batch axis on both input and output.
- Preprocessing: align the face to the standard ArcFace 5-point template at
112×112 (e.g. OpenCV
FaceRecognizerSF.alignCrop), keep channels in BGR, then scale with(x - 127.5) / 127.5. - Compare two faces with cosine similarity on the L2-normalized embeddings.
Usage
import cv2, numpy as np, onnxruntime as ort
sess = ort.InferenceSession("adaface_ir50_ms1mv2.onnx", providers=["CPUExecutionProvider"])
def embed(aligned_bgr_112: np.ndarray) -> np.ndarray:
x = (aligned_bgr_112.astype(np.float32) - 127.5) / 127.5 # (112,112,3) BGR
x = np.transpose(x, (2, 0, 1))[None] # (1,3,112,112)
e = sess.run(["embedding"], {"input": x})[0][0] # (512,)
return e / np.linalg.norm(e)
# cosine similarity
# sim = float(embed(face_a) @ embed(face_b))
Verification
The export was checked against the source PyTorch model on identical inputs:
onnx.checkerpasses.- Max absolute difference (torch vs. onnxruntime output): ~4.3e-07.
- Output shape
(1, 512); embedding L2 norm ≈ 1.0.
Provenance & license
- Architecture / training: AdaFace (Kim et al., CVPR 2022), IR-50 backbone, MS1MV2 training set. Upstream code: https://github.com/mk-minchul/AdaFace (MIT).
- Weights: converted from the published AdaFace IR-50 MS1MV2 checkpoint. The network definition used for the export is the vendored AdaFace architecture (MIT).
- License note: the AdaFace code is MIT, but pretrained weights derive from the MS1MV2 dataset, which carries its own dataset/research-use licensing. Review the upstream terms before any production or commercial use.
Citation
@inproceedings{kim2022adaface,
title = {AdaFace: Quality Adaptive Margin for Face Recognition},
author = {Kim, Minchul and Jain, Anil K. and Liu, Xiaoming},
booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2022}
}