ArcFace ONNX
A high-accuracy face recognition (embedding) model exported to ONNX format, ready to run with onnxruntime.
- Input: Cropped RGB face image, resized to 112x112.
- Output: 512-dimensional embedding (vector).
- Use case: Face verification and recognition (compare two faces for similarity).
π₯ Download Model
Download the ONNX model using:
wget https://huggingface.co/garavv/arcface-onnx/resolve/main/arc.onnx?download=true -O arcface.onnx
π Quick Start
import cv2
import numpy as np
import onnxruntime as ort
def preprocess(img_path):
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (112, 112))
img = (img.astype(np.float32) - 127.5) / 128.0
return img[np.newaxis, ...] # shape: (1, 112, 112, 3)
sess = ort.InferenceSession("arcface.onnx")
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name
emb1 = sess.run([output_name], {input_name: preprocess("face1.jpg")})[0][0]
emb2 = sess.run([output_name], {input_name: preprocess("face2.jpg")})[0][0]
# Normalize
emb1 = emb1 / np.linalg.norm(emb1)
emb2 = emb2 / np.linalg.norm(emb2)
cosine_sim = np.dot(emb1, emb2)
print("Cosine similarity:", cosine_sim)
π¦ Dependencies
- Python 3.7+
- onnxruntime
- numpy
- opencv-python
Install with:
pip install onnxruntime numpy opencv-python
π Model Details
- Architecture: ArcFace (ONNX, 512-dim output)
- Input shape: (1, 112, 112, 3) (batch, height, width, channels)
- Output: (1, 512) embedding vector