Views
No views yet
| 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 |
(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.1from pathlib import Path
2
3import coremltools as ct
4import numpy as np
5from huggingface_hub import snapshot_download
6from PIL import Image, ImageOps
7
8root = Path(snapshot_download(
9 repo_id="hugging-mac/retinaface-coreml",
10 allow_patterns=["retinaface.mlpackage/**"],
11))
12model = ct.models.MLModel(root / "retinaface.mlpackage", compute_units=ct.ComputeUnit.ALL)
13
14image = ImageOps.pad(Image.open("face.jpg").convert("RGB"), (640, 640))
15value = np.asarray(image, dtype=np.float32).transpose(2, 0, 1)
16value -= np.asarray((123.0, 117.0, 104.0), dtype=np.float32)[:, None, None]
17outputs = model.predict({"image": np.ascontiguousarray(value[None])})
18
19print(outputs["locations"].shape) # (1, 16800, 4)
20print(outputs["scores"].shape) # (1, 16800, 2)
21print(outputs["landmarks"].shape) # (1, 16800, 10)31702389094fccc7060c15299e6ad712ee880de66290800b08e20d9d6506795e5e47f1da35f2586ad4e75dcbb08a14ed11b2ed6b