File size: 2,751 Bytes
f527f30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
library_name: coremltools
pipeline_tag: object-detection
base_model: py-feat/retinaface
tags:
  - coreml
  - apple-silicon
  - face-detection
  - face-landmarks
  - mobilenet
  - macos
---

# RetinaFace MobileNet0.25 — Core ML

A lightweight Core ML conversion of [py-feat/retinaface](https://huggingface.co/py-feat/retinaface) for fast, local face detection and five-point facial landmarks on Apple Silicon.

This model is integrated into [Hugging Mac](https://github.com/devilyouwei/hugging-mac), where developers can build private camera apps, face-aware interfaces, games, plugins, and agents on macOS.

## Model details

| Property | Value |
|---|---|
| Backbone | MobileNet0.25 |
| Parameters | 426,608 |
| Input | `image`: `1 × 3 × 640 × 640` FP32 RGB tensor |
| Face boxes | `locations`: `1 × 16800 × 4` FP32 |
| Scores | `scores`: `1 × 16800 × 2` FP32 |
| Landmarks | `landmarks`: `1 × 16800 × 10` FP32 |
| Core ML compute | FP16 |
| Package size | 0.94 MB |

The ten landmark values represent five `(x, y)` points: both eyes, nose, and both mouth corners. Outputs are raw and require prior decoding, confidence filtering, NMS, and restoration to the original image coordinates.

## Core ML example

```python
from pathlib import Path

import coremltools as ct
import numpy as np
from huggingface_hub import snapshot_download
from PIL import Image, ImageOps

root = Path(snapshot_download(
    repo_id="hugging-mac/retinaface-coreml",
    allow_patterns=["retinaface.mlpackage/**"],
))
model = ct.models.MLModel(root / "retinaface.mlpackage", compute_units=ct.ComputeUnit.ALL)

image = ImageOps.pad(Image.open("face.jpg").convert("RGB"), (640, 640))
value = np.asarray(image, dtype=np.float32).transpose(2, 0, 1)
value -= np.asarray((123.0, 117.0, 104.0), dtype=np.float32)[:, None, None]
outputs = model.predict({"image": np.ascontiguousarray(value[None])})

print(outputs["locations"].shape)  # (1, 16800, 4)
print(outputs["scores"].shape)     # (1, 16800, 2)
print(outputs["landmarks"].shape)  # (1, 16800, 10)
```

For complete preprocessing and postprocessing, use the [Hugging Mac RetinaFace SDK](https://github.com/devilyouwei/hugging-mac/tree/main/packages/hugging_mac_sdk/src/hugging_mac_sdk/models/retinaface).

## Provenance and integrity

- Upstream model: [py-feat/retinaface](https://huggingface.co/py-feat/retinaface)
- Upstream revision: `31702389094fccc7060c15299e6ad712ee880de6`
- Conversion: fixed 640×640 input, ML Program, FP16 compute
- Directory SHA-256: `6290800b08e20d9d6506795e5e47f1da35f2586ad4e75dcbb08a14ed11b2ed6b`

## License

The converted model retains the upstream MIT license. Hugging Mac is an independent open-source project and is not affiliated with or endorsed by py-feat.