a-ml commited on
Commit
9dc6402
Β·
verified Β·
1 Parent(s): daa7522

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +151 -0
README.md CHANGED
@@ -1,3 +1,154 @@
1
  ---
2
  license: cc-by-nc-nd-4.0
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-nc-nd-4.0
3
+ base_model:
4
+ - UmutKocasari/FaceAnything
5
+ pipeline_tag: depth-estimation
6
+ tags:
7
+ - coreml
8
+ - Apple
9
+ - MPS
10
  ---
11
+ # FaceAnything β€” CoreML (Apple Silicon)
12
+ [Link to GH Fork](https://github.com/AristidesAI/FaceAnything-CoreML)
13
+ [Link To HuggingFace Models](https://huggingface.co/a-ml/FaceAnythingCoreML)
14
+
15
+ Convert and run **Face Anything** natively on Apple Silicon (M-series Macs) using
16
+ CoreML with Metal GPU acceleration. No CUDA required.
17
+
18
+ The full 1.39B-parameter ViT-Giant model is converted to a single CoreML
19
+ `mlpackage` with fp16 precision (~2.5 GB), deployable on macOS 15+ and iOS 18+.
20
+
21
+ ## What's Included
22
+ | File | Purpose |
23
+ |---|---|
24
+ | `coreml_scripts/convert_coreml.py` | Convert the PyTorch checkpoint β†’ CoreML mlpackage |
25
+ | `coreml_scripts/run_coreml.py` | Full inference pipeline (masks β†’ model β†’ videos + PLY) |
26
+ | `coreml_models/FaceAnything_fp16.mlpackage` | Converted model (fp16, ~2.5 GB) |
27
+ | `coreml_models/FaceAnything_palettize_4bit.mlpackage` | Quantized model (4-bit, ~624 MB) |
28
+
29
+ ## Requirements
30
+ - macOS 15+ with Apple Silicon (M1 or later)
31
+ - Python 3.11
32
+ - `venv_mps` or equivalent with `coremltools`, `torch`, `opencv-python`, `numpy`
33
+
34
+ Install from the existing `requirements_mps.txt`:
35
+ ```bash
36
+ pip install -r requirements_mps.txt
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### 1. Convert the model (one-time)
42
+ ```bash
43
+ # fp16 (2.5 GB, best quality)
44
+ python coreml_scripts/convert_coreml.py --resolution 504 --quantize none
45
+
46
+ # 4-bit palettized (~624 MB, very good quality)
47
+ python coreml_scripts/convert_coreml.py --resolution 504 --quantize palettize_4bit
48
+
49
+ # For vertical video (adjust width to match aspect ratio)
50
+ python coreml_scripts/convert_coreml.py --resolution 504 --width 280 --quantize none
51
+ ```
52
+
53
+ The model's longest side is set to the `--resolution` value (must be divisible by
54
+ 14, the ViT patch size). Use `--width` to set a non-square aspect ratio. The
55
+ output goes to `coreml_models/` by default.
56
+
57
+ ### 2. Run inference
58
+ ```bash
59
+ python coreml_scripts/run_coreml.py \
60
+ --input video.mov \
61
+ --output output_dir/ \
62
+ --render-size 1080 \
63
+ --fps 60
64
+ ```
65
+
66
+ Options:
67
+ | Flag | Default | Description |
68
+ |---|---|---|
69
+ | `--input` | (required) | Video, image, or image folder |
70
+ | `--output` | (required) | Output directory |
71
+ | `--coreml-model` | `coreml_models/FaceAnything_fp16.mlpackage` | Path to mlpackage |
72
+ | `--render-size` | 1080 | Output canvas height |
73
+ | `--fps` | 60 | Output video frame rate |
74
+ | `--outputs` | `all` | Comma-separated: `videos`, `ply`, `grandtour` or `all` |
75
+
76
+ ## Output Structure
77
+ ```
78
+ output_dir/
79
+ β”œβ”€β”€ videos/
80
+ β”‚ β”œβ”€β”€ pointcloud.mp4 # RGB-colored 3D point cloud, sway orbit
81
+ β”‚ β”œβ”€β”€ depth.mp4 # Depth-colored (jet) 3D reconstruction
82
+ β”‚ β”œβ”€β”€ normals.mp4 # Surface normal-colored 3D
83
+ β”‚ β”œβ”€β”€ canonical.mp4 # Canonical face coordinates colored
84
+ β”‚ β”œβ”€β”€ tracks.mp4 # Temporally-consistent point tracks
85
+ β”‚ └── grand_tour.mp4 # Morph through all modalities
86
+ β”œβ”€β”€ ply/
87
+ β”‚ β”œβ”€β”€ geometry/ # RGB-colored .ply per frame
88
+ β”‚ β”œβ”€β”€ depth/ # Depth-colored (jet) .ply per frame
89
+ β”‚ β”œβ”€β”€ normals/ # Normal-colored .ply per frame
90
+ β”‚ β”œβ”€β”€ canonical/ # Canonical-colored .ply per frame
91
+ β”‚ └── tracks/ # Track-colored .ply per frame
92
+ β”œβ”€β”€ masks/ # Generated RVM foreground masks
93
+ └── _frames_in/ # Extracted input frames
94
+ ```
95
+
96
+ ## Model Architecture
97
+ | Property | Value |
98
+ |---|---|
99
+ | Backbone | ViT-Giant (40 blocks, 1536-dim) |
100
+ | Parameters | 1.39B |
101
+ | Attn heads | 24 |
102
+ | Patch grid | 36 Γ— 20 (for 504Γ—280 input) |
103
+ | fp32 size | 5.6 GB |
104
+ | fp16 size | 2.5 GB |
105
+ | 4-bit size | 624 MB |
106
+ | Input | `(1, 3, 504, 280)` fp16, ImageNet-normalized |
107
+ | Outputs | depth, depth_conf, deformation, deformation_conf, intrinsics |
108
+ | Runtime | Metal GPU + AMX CPU; partial ANE for DPT heads |
109
+
110
+ ## Conversion Notes
111
+ The model required significant patching to produce a CoreML-compatible graph:
112
+
113
+ | Original Op | Replacement |
114
+ |---|---|
115
+ | `torch.einsum` | Broadcasting |
116
+ | `F.scaled_dot_product_attention` | Manual QKα΅€ Γ· √d Γ— V |
117
+ | `torch.utils.checkpoint` (7 sites) | No-op passthrough |
118
+ | `einops.rearrange` (8 patterns) | Explicit `reshape` |
119
+ | `torch.chunk` (SwiGLU) | Explicit slicing |
120
+ | `int(positions.max())` (RoPE) | Fixed 8192-length cache |
121
+ | `addict.Dict` return type | Plain tuple |
122
+ | `upsample_bicubic2d.vec` | Registered as bilinear alias |
123
+ | `aten.alias` | Identity passthrough |
124
+
125
+ Multi-view features (reference view selection, camera tokens, global attention
126
+ alternation) are disabled for the single-view export (`alt_start = -1`).
127
+
128
+ ## Quantization Options
129
+ | Method | Size | Deploy Target | Quality |
130
+ |---|---|---|---|
131
+ | `none` (fp16) | 2.5 GB | macOS 15 / iOS 18 | Reference |
132
+ | `palettize_4bit` | 624 MB | macOS 15 / iOS 18 | Very good |
133
+ | `palettize_8bit` | 1.2 GB | macOS 15 / iOS 18 | Excellent |
134
+ | `linear_8bit` | 1.2 GB | macOS 15 / iOS 18 | Excellent |
135
+
136
+ Palettization uses k-means weight clustering. The 4-bit model achieves ~75%
137
+ compression with negligible quality loss (validated numerically against fp32
138
+ PyTorch: depth max error < 0.01).
139
+
140
+ ## Citation
141
+ ```bibtex
142
+ @article{kocasari2026face,
143
+ title={Face Anything: 4D Face Reconstruction from Any Image Sequence},
144
+ author={Kocasari, Umut and Giebenhain, Simon and Shaw, Richard and Nie{\ss}ner, Matthias},
145
+ journal={arXiv preprint arXiv:2604.19702},
146
+ year={2026}
147
+ }
148
+ ```
149
+
150
+ ## License
151
+ This work is licensed under a
152
+ [Creative Commons Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/).
153
+
154
+ CoreML adaptation is provided as-is under the same license.