Add RetinaFace MobileNet0.25 Core ML package
Browse files
README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: coremltools
|
| 4 |
+
pipeline_tag: object-detection
|
| 5 |
+
base_model: py-feat/retinaface
|
| 6 |
+
tags:
|
| 7 |
+
- coreml
|
| 8 |
+
- apple-silicon
|
| 9 |
+
- face-detection
|
| 10 |
+
- face-landmarks
|
| 11 |
+
- mobilenet
|
| 12 |
+
- macos
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# RetinaFace MobileNet0.25 — Core ML
|
| 16 |
+
|
| 17 |
+
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.
|
| 18 |
+
|
| 19 |
+
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.
|
| 20 |
+
|
| 21 |
+
## Model details
|
| 22 |
+
|
| 23 |
+
| Property | Value |
|
| 24 |
+
|---|---|
|
| 25 |
+
| Backbone | MobileNet0.25 |
|
| 26 |
+
| Parameters | 426,608 |
|
| 27 |
+
| Input | `image`: `1 × 3 × 640 × 640` FP32 RGB tensor |
|
| 28 |
+
| Face boxes | `locations`: `1 × 16800 × 4` FP32 |
|
| 29 |
+
| Scores | `scores`: `1 × 16800 × 2` FP32 |
|
| 30 |
+
| Landmarks | `landmarks`: `1 × 16800 × 10` FP32 |
|
| 31 |
+
| Core ML compute | FP16 |
|
| 32 |
+
| Package size | 0.94 MB |
|
| 33 |
+
|
| 34 |
+
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.
|
| 35 |
+
|
| 36 |
+
## Core ML example
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from pathlib import Path
|
| 40 |
+
|
| 41 |
+
import coremltools as ct
|
| 42 |
+
import numpy as np
|
| 43 |
+
from huggingface_hub import snapshot_download
|
| 44 |
+
from PIL import Image, ImageOps
|
| 45 |
+
|
| 46 |
+
root = Path(snapshot_download(
|
| 47 |
+
repo_id="hugging-mac/retinaface-coreml",
|
| 48 |
+
allow_patterns=["retinaface.mlpackage/**"],
|
| 49 |
+
))
|
| 50 |
+
model = ct.models.MLModel(root / "retinaface.mlpackage", compute_units=ct.ComputeUnit.ALL)
|
| 51 |
+
|
| 52 |
+
image = ImageOps.pad(Image.open("face.jpg").convert("RGB"), (640, 640))
|
| 53 |
+
value = np.asarray(image, dtype=np.float32).transpose(2, 0, 1)
|
| 54 |
+
value -= np.asarray((123.0, 117.0, 104.0), dtype=np.float32)[:, None, None]
|
| 55 |
+
outputs = model.predict({"image": np.ascontiguousarray(value[None])})
|
| 56 |
+
|
| 57 |
+
print(outputs["locations"].shape) # (1, 16800, 4)
|
| 58 |
+
print(outputs["scores"].shape) # (1, 16800, 2)
|
| 59 |
+
print(outputs["landmarks"].shape) # (1, 16800, 10)
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
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).
|
| 63 |
+
|
| 64 |
+
## Provenance and integrity
|
| 65 |
+
|
| 66 |
+
- Upstream model: [py-feat/retinaface](https://huggingface.co/py-feat/retinaface)
|
| 67 |
+
- Upstream revision: `31702389094fccc7060c15299e6ad712ee880de6`
|
| 68 |
+
- Conversion: fixed 640×640 input, ML Program, FP16 compute
|
| 69 |
+
- Directory SHA-256: `6290800b08e20d9d6506795e5e47f1da35f2586ad4e75dcbb08a14ed11b2ed6b`
|
| 70 |
+
|
| 71 |
+
## License
|
| 72 |
+
|
| 73 |
+
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.
|
retinaface.mlpackage.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c0f48becf7b5e738ce32d2c75518ef67b76705f728f42973d9978b81db843660
|
| 3 |
+
size 801236
|
retinaface.mlpackage/Data/com.apple.CoreML/model.mlmodel
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d0bc523aaf9b56772082835c5b54f17a86b9efd34074c46d14251ae53cb98bca
|
| 3 |
+
size 89900
|
retinaface.mlpackage/Data/com.apple.CoreML/weights/weight.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:125004e2e555577c8e752391876ef2b8017d4823080931a1f04f97786b88ace0
|
| 3 |
+
size 853736
|
retinaface.mlpackage/Manifest.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"fileFormatVersion": "1.0.0",
|
| 3 |
+
"itemInfoEntries": {
|
| 4 |
+
"98C97075-452E-428F-92A5-DB4988E5812E": {
|
| 5 |
+
"author": "com.apple.CoreML",
|
| 6 |
+
"description": "CoreML Model Weights",
|
| 7 |
+
"name": "weights",
|
| 8 |
+
"path": "com.apple.CoreML/weights"
|
| 9 |
+
},
|
| 10 |
+
"C1AE6ACC-E1A8-4725-929D-3E62AA628B81": {
|
| 11 |
+
"author": "com.apple.CoreML",
|
| 12 |
+
"description": "CoreML Model Specification",
|
| 13 |
+
"name": "model.mlmodel",
|
| 14 |
+
"path": "com.apple.CoreML/model.mlmodel"
|
| 15 |
+
}
|
| 16 |
+
},
|
| 17 |
+
"rootModelIdentifier": "C1AE6ACC-E1A8-4725-929D-3E62AA628B81"
|
| 18 |
+
}
|