File size: 1,654 Bytes
9a35af8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# ArcFace ONNX

A high-accuracy face recognition (embedding) model exported to ONNX format, ready to run with [onnxruntime](https://onnxruntime.ai/).

- **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:

```bash
wget https://huggingface.co/garavv/arcface-onnx/resolve/main/arc.onnx?download=true -O arcface.onnx
```

---

## πŸš€ Quick Start

```python
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:**

```bash
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

---