ljchang commited on
Commit
9f20da7
·
verified ·
1 Parent(s): 999369c

Upload cross_tool_methodology.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. cross_tool_methodology.md +324 -0
cross_tool_methodology.md ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Cross-tool AU benchmark — methodology & integration notes
2
+
3
+ This documents how py-feat is compared against other open-source Python facial
4
+ action-unit (AU) toolkits, and — just as importantly — **what it took to run
5
+ each competitor**. The integration effort is itself a result: it shows the
6
+ usability gap between py-feat (`pip install py-feat`, one `Detector` /
7
+ `Detectorv2` call, runs on any GPU) and the alternatives.
8
+
9
+ ## Feature comparison
10
+
11
+ Across the open-source Python facial-behavior toolkits. ✅ = supported,
12
+ ❌ = not supported, ⚠️ = supported with a caveat (see notes).
13
+
14
+ | | **py-feat** | **OpenFace 3.0** | **LibreFace** | **PyAFAR** |
15
+ |---|:---:|:---:|:---:|:---:|
16
+ | **Install** | `pip install py-feat` ✅ | clone repo + checkpoints | `pip install libreface` ⚠️¹ | ❌ broken deps² |
17
+ | **Single images** | ✅ | ✅ | ✅ | ❌ **video only** |
18
+ | **Video** | ✅ | ✅ | ✅ | ✅ |
19
+ | **Action units** | ✅ 20 | ✅ 8 | ✅ 12 (+5 occ.) | ⚠️ 12 occ. / 5 int. |
20
+ | **AU intensity** | ✅ | ❌ occ. only | ✅ | ⚠️ 5 AUs |
21
+ | **Emotion** | ✅ 7-class | ✅ | ✅ | ❌ |
22
+ | **Valence / arousal** | ✅ (v2) | ❌ | ❌ | ❌ |
23
+ | **Gaze** | ✅ | ✅ | ✅ | ❌ |
24
+ | **Head pose (6DoF)** | ✅ | ✅ | ✅ | ❌ |
25
+ | **Landmarks** | ✅ 68 + 478 mesh | ✅ | ✅ 478 mesh | ❌ |
26
+ | **Identity / face ID** | ✅ ArcFace | ❌ | ❌ | ❌ |
27
+ | **One-call API** | ✅ `Detector().detect()` | ❌ custom scripts | ✅ ⚠️¹ | ⚠️ video only |
28
+ | **Latest GPUs (Blackwell)** | ✅ | ✅ | ❌ pinned old torch³ | ❌ dlib/CUDA³ |
29
+ | **License** | permissive⁴ | academic | USC research-only | non-commercial |
30
+
31
+ ¹ The `pip` model is a distilled all-in-one net that **underperforms its own
32
+ paper**; reproducing published AU numbers requires cloning the research repo +
33
+ checkpoints (see LibreFace notes).
34
+ ² Release wheel pins `pysimplegui==4.60.5`, which was pulled from PyPI — install
35
+ fails; needs `--no-deps` + hand-resolving TF/MediaPipe/dlib + `download_models`.
36
+ ³ LibreFace's pinned PyTorch lacks Blackwell (sm_120) kernels (≤ Ampere only);
37
+ PyAFAR's dlib build fails compiling CUDA kernels.
38
+ ⁴ py-feat is permissively licensed; a few downloadable weights (e.g. ArcFace
39
+ identity) are research-only and clearly flagged.
40
+
41
+ **Takeaway:** py-feat is the only one of the four that installs with a single
42
+ `pip` command, takes both images and video, runs on current-generation GPUs, and
43
+ covers the full feature set (AUs + intensity, emotion, valence/arousal, gaze,
44
+ 6DoF pose, 68/478 landmarks, identity) behind one API.
45
+
46
+ ## Accuracy — AU detection on DISFA+ (held-out)
47
+
48
+ Mean per-AU **F1** on the DISFA+ benchmark (57,150 frames). **Protocols are not
49
+ yet fully harmonized** across tools (AU subset + binarization differ — see the
50
+ per-tool note); treat as indicative until a single-protocol recompute lands.
51
+
52
+ | Tool | DISFA+ mean F1 | AUs scored | binarization | source |
53
+ |------|:---:|:---:|---|---|
54
+ | **py-feat v2** (`Detectorv2`) | **0.540** | 12 | truth ≥2, prob ≥0.5 | `pyfeat_disfaplus_au.json` |
55
+ | **OpenFace 3.0** | 0.488 | 8 | their `evaluation.py` | `openface3_disfaplus.json` |
56
+ | **LibreFace** (research RepVGG) | 0.461 | 12 | truth ≥2, intensity ≥2 | `libreface_repvgg_disfaplus.json` |
57
+ | **py-feat v1** (`Detector`, xgb) | 0.250 | 12 | truth ≥2, prob ≥0.5 | `pyfeat_disfaplus_au.json` |
58
+ | **PyAFAR** | _n/a_ | ≤7 overlap | — | not runnable (see notes) |
59
+
60
+ **py-feat v2 (Detectorv2) leads** the held-out DISFA+ AU benchmark (0.54), ahead
61
+ of OpenFace 3.0 (0.49) and LibreFace (0.46) — and recall DISFA+ is held out for
62
+ *all* tools, while DISFA (LibreFace's/OF3's training set) is excluded. py-feat
63
+ v1's xgb path is weaker here (0.25) on the strict 12-AU / ≥2 protocol; it's the
64
+ legacy modular detector, and v2 is the recommended path.
65
+
66
+ LibreFace also gives mean intensity **PCC = 0.73** (its native DISFA metric).
67
+ A follow-up will recompute all tools on one AU set + threshold for an
68
+ apples-to-apples table.
69
+
70
+ ## Accuracy — beyond AU: emotion, valence/arousal, gaze
71
+
72
+ AU is only one of the modalities these toolkits ship. We benchmark the rest on
73
+ the datasets that carry the right labels, each tool run **end-to-end as
74
+ written** (its own detector → its own model), on identical images/labels frozen
75
+ from py-feat's `feat.evaluation` loaders into shared manifests
76
+ (`shared/export_emotion_gaze_manifest.py`). Per-tool sample counts (`n`) differ
77
+ because each tool's *own* face detector decides which faces it finds — that
78
+ detection robustness is itself part of the comparison.
79
+
80
+ ### Emotion — 7-class, top-1 accuracy / macro-F1
81
+
82
+ Held-out **AffectNet-val** (994 imgs, classes 0–6) and **RAF-DB test** (3,068).
83
+ All three emotion-capable tools argmax their own emotion head; OF3/LibreFace
84
+ emit 8 classes (incl. Contempt) — scored on the shared 7, a Contempt prediction
85
+ counts as wrong. (PyAFAR has no emotion head.)
86
+
87
+ | Tool | AffectNet acc / F1 | RAF-DB acc / F1 |
88
+ |------|:---:|:---:|
89
+ | **py-feat v2** | 0.492 / **0.479** | **0.656 / 0.528** |
90
+ | **OpenFace 3.0** | **0.493** / **0.520** | 0.513 / 0.469 |
91
+ | **LibreFace** | 0.455 / 0.403 | 0.646 / 0.386 |
92
+
93
+ py-feat v2 and OF3 are neck-and-neck on AffectNet (0.49); on RAF-DB py-feat
94
+ leads on both accuracy and the balanced macro-F1 (LibreFace's 0.646 accuracy but
95
+ 0.386 macro-F1 is the majority-class/Happiness skew).
96
+
97
+ ### Valence / arousal — CCC (AffectNet-val)
98
+
99
+ **py-feat v2 is the only tool of the four that predicts continuous valence and
100
+ arousal at all** — so this isn't a head-to-head, it's a capability the others
101
+ lack. On AffectNet-val: **valence CCC 0.535, arousal CCC 0.482**.
102
+
103
+ ### Gaze — Columbia Gaze, mean angular error (head-frontal subset, 1,176 imgs)
104
+
105
+ Each tool emits gaze in its own (yaw, pitch) frame, sign, and unit, mostly
106
+ undocumented. We resolve that I/O convention **identically and in every tool's
107
+ favor** — the single best discrete (axis × sign × unit) mapping to the GT frame
108
+ (`shared/gaze_convention.py`) — so no tool is penalised for an opaque output
109
+ convention. The same procedure is applied to py-feat.
110
+
111
+ | Tool | angular MAE | median |
112
+ |------|:---:|:---:|
113
+ | **py-feat v2** | **2.72°** | 2.21° |
114
+ | **OpenFace 3.0** | 12.05° | 11.34° |
115
+ | **LibreFace** | 15.40° | 14.33° |
116
+
117
+ py-feat's L2CS gaze is dramatically more accurate on Columbia. (Note: py-feat's
118
+ *stock* `feat.evaluation` harness reports 17.5° here — that's a yaw-sign
119
+ mismatch in its Columbia loader convention, not a model error; under the
120
+ fair favor-everyone resolution it's 2.72°. A loader fix is on the roadmap.)
121
+
122
+ > Reproduce: `tools/<tool>/run_accuracy.py` (OF3/PyAFAR), `run_modalities.py`
123
+ > (LibreFace), `run_gaze.py` + `run_pyfeat_modalities.py` (py-feat). Consolidated
124
+ > by `ingest_accuracy.py` into `accuracy.csv`; published to the
125
+ > `py-feat/benchmarks` HF dataset.
126
+
127
+ ## Speed
128
+
129
+ Throughput on the **shared test fixtures** (`single_face.mp4` video + a
130
+ `multi_face.jpg` image batch — *not* the accuracy datasets), each tool timed
131
+ end-to-end (detect → AU), across a hardware × batch matrix:
132
+
133
+ **Hardware:** CPU · RTX 3090 (sm_86) · RTX PRO 6000 Blackwell (sm_120) · Apple M5 (MPS)
134
+ **Batch:** 1 (single frame) and 16
135
+
136
+ **A blank cell is data.** If a tool can't run on a given device it gets *no
137
+ number* — that absence documents the tool's hardware reach. Expected coverage:
138
+
139
+ | Tool | CPU | 3090 | Blackwell | M5 (MPS) |
140
+ |------|:---:|:---:|:---:|:---:|
141
+ | **py-feat** | ✅ | ✅ | ✅ | ✅ |
142
+ | **OpenFace 3.0** | ✅ | ✅ | ? | ? |
143
+ | **LibreFace** | ✅ | ✅ | ❌ (no sm_120) | ? (cuda/cpu API) |
144
+ | **PyAFAR** | ✅? | ? | ❌ (dlib/CUDA) | ❌ (Ubuntu/WSL2 only) |
145
+
146
+ py-feat's own CPU/3090/Blackwell numbers are in the **[live dashboard](live.md)**
147
+ (e.g. Detectorv2 ≈ 285 fps on Blackwell batch 16); M5 is added from a Mac run.
148
+
149
+ **Methodology** (this matters — naive timing is misleading): every tool is timed
150
+ **end-to-end** (decode → detect → AU, the full pipeline it ships), on the **same
151
+ video** (`WolfgangLanger_Pexels.mp4`, 472 frames), with **warmup + 3 repeats**
152
+ (median reported) and `torch.cuda.synchronize()` around GPU work. Crucially, the
153
+ head-to-head is at **batch 1** — OpenFace 3.0 and LibreFace process per-frame
154
+ (their APIs don't expose batching), so comparing them to py-feat's batched
155
+ throughput would be apples-to-oranges.
156
+
157
+ **Head-to-head — RTX 3090, end-to-end, batch 1:**
158
+
159
+ | Tool | fps | vs py-feat |
160
+ |---|:---:|:---:|
161
+ | **py-feat Detectorv2** | **38.4** | — |
162
+ | **OpenFace 3.0** | 18.3 | 2.1× slower |
163
+ | **LibreFace** | 4.7 | 8.2× slower |
164
+ | **PyAFAR** | n/a | — |
165
+
166
+ **py-feat's batching is a separate advantage:** its `detect()` natively batches,
167
+ so Detectorv2 scales **38 → 202 fps** from batch 1 to 16 on the 3090. OF3 and
168
+ LibreFace have no batch path in their APIs (their *models* can batch, but the
169
+ shipped pipeline doesn't), so they stay at the per-frame rate. LibreFace's GPU
170
+ barely helps it at all — its MediaPipe alignment is CPU-bound and dominates.
171
+
172
+ The CPU / Blackwell / M5 cells need the same rigorous harness (folded into the
173
+ suite's `run_speed.py`); the earlier single-clip per-frame numbers there are
174
+ **not** trustworthy and were withdrawn. Hardware reach is still data: **OF3 runs
175
+ on Blackwell; LibreFace and PyAFAR cannot** (no sm_120 / dlib-CUDA).
176
+
177
+ The point of the matrix is exactly the blanks: py-feat is the only toolkit that
178
+ runs across CPU, current-gen GPUs, *and* Apple Silicon — and is one-to-two orders
179
+ of magnitude faster where competitors do run.
180
+
181
+ ## Datasets & metric protocol — and why **DISFA+**, not DISFA
182
+
183
+ The cross-tool comparison runs on **DISFA+** (posed-peak, 12-AU intensity), the
184
+ held-out benchmark py-feat reports against (Cheong et al. 2023) and the dataset
185
+ our existing OpenFace 3.0 result already uses (`"dataset": "disfaplus"`).
186
+
187
+ **We deliberately do *not* evaluate on DISFA.** DISFA is the **training set** for
188
+ LibreFace (and is used by OpenFace 3.0), so scoring those tools on DISFA is
189
+ in-distribution — a home-field advantage and effective train/test contamination.
190
+ DISFA+ is held out for all tools, so it measures **generalization**: a tool that
191
+ only does well on its own training distribution is exactly what a fair benchmark
192
+ should expose. (We verified the in-distribution case as a *sanity check* — the
193
+ LibreFace RepVGG model tracks AU intensity cleanly on DISFA — then evaluate the
194
+ real comparison on DISFA+.)
195
+
196
+ Metrics: per-AU **PCC** (intensity, threshold-free — LibreFace's native metric)
197
+ and binary **F1** at intensity **≥ 2** on both prediction and ground truth
198
+ (matching `feat.evaluation.metrics`' truth convention). Where a tool emits
199
+ probabilities (py-feat, OF3) rather than intensities, its native binarization is
200
+ noted per table so protocols are never silently mixed.
201
+
202
+ ## Per-tool integration experience
203
+
204
+ ### py-feat (v1 / v2)
205
+ `pip install py-feat`; one call returns AUs (+ emotion, pose, gaze, landmarks,
206
+ identity). Runs on CPU, CUDA (incl. **Blackwell / RTX PRO 6000**, sm_120, on
207
+ torch 2.11+cu128), and Apple MPS. No per-tool preprocessing to match.
208
+
209
+ ### LibreFace — could **not** reproduce published numbers locally
210
+ A multi-day saga that is worth recording in full:
211
+
212
+ 1. **The pip API (`libreface.get_facial_attributes`) collapses on this data.**
213
+ Its `au_intensities` are near the noise floor for clearly-active AUs — e.g.
214
+ a DISFA+ frame labeled AU12 intensity 4 (a posed smile) returns
215
+ `au_12 ≈ 0.015` (it correctly returns ~2.5 on a normal smiling photo).
216
+ No threshold/normalization recovers a signal that isn't there.
217
+ 2. The LibreFace **paper** reports DISFA AU *intensity* via **PCC** (0.63) from a
218
+ **separate research module** (`AU_Recognition`, RepVGG checkpoint), not the
219
+ distilled all-in-one pip model. So we cloned the repo and loaded
220
+ `new_checkpoints_fm_repvgg/DISFA/all/repvgg.pt` (output `×5 → [0,5]`).
221
+ 3. **The research checkpoint can't run on Blackwell.** LibreFace pins an old
222
+ PyTorch built for **sm_37…sm_86**; Blackwell is **sm_120**. Weights copy to
223
+ the GPU ("loaded"), then the first compute kernel aborts (no sm_120 binary).
224
+ **LibreFace is therefore restricted to ≤ Ampere GPUs** — we benchmark it on
225
+ the RTX 3090 (sm_86). py-feat runs on Blackwell unchanged.
226
+ 4. **It is fragile to out-of-distribution data and alignment.** On **DISFA+**
227
+ (posed-peak) the research checkpoint *also* collapsed (AU12 ramp 0→4 stayed
228
+ ~0.1–0.5, non-monotonic) — under both LibreFace's own MediaPipe alignment and
229
+ DISFA+ native `Aligned/` crops. It only works on **DISFA itself**, fed
230
+ **DISFA's own aligned crops** (`DISFA_/aligned/...`): there the AU12 ramp is
231
+ clean and monotonic — GT 0→0.05, 1→~0.5, 2→~1.2, 3→~2.7, 4→~3.5, 5→~4.4.
232
+
233
+ **Status:** the research RepVGG checkpoint runs correctly. On the held-out
234
+ **DISFA+** set (its own aligned crops, LibreFace's test transform, 57,150 frames)
235
+ it generalizes reasonably: **mean F1 = 0.46, mean PCC = 0.73** over 12 AUs
236
+ (`run_libreface_repvgg_disfaplus.py` → `libreface_repvgg_disfaplus.json`).
237
+ Strong on AU25 (F1 0.91), AU04/09 (0.75); weak on AU06 (0.11), AU15/17/20
238
+ (~0.06). Note: earlier single-frame probes suggested a "collapse" — that was an
239
+ artifact of unrepresentative frames and the broken *pip* model; the full-dataset
240
+ research-model run is the truth, and it's fine. (The lesson — over-concluding
241
+ from a handful of frames — is why we report the whole-benchmark output.)
242
+
243
+ Getting even this far required: discovering the pip model is a different
244
+ (weaker) net than the paper's, cloning the research repo + checkpoints, working
245
+ around a Blackwell-incompatible torch (3090-only), and matching the alignment —
246
+ vs. py-feat's `pip install` + one call. The silent failure modes (pip-model
247
+ collapse, out-of-distribution collapse) are themselves the usability story:
248
+ without careful per-frame validation you'd ship wrong numbers.
249
+
250
+ ### OpenFace 3.0
251
+ Cleaner to install than LibreFace/PyAFAR (`pip install openface-test` +
252
+ `openface download`), but the shipped pip CLI has **three blocking bugs**:
253
+ 1. A **hardcoded developer path** baked into the STAR landmark config
254
+ (`ckpt_dir = '/work/jiewenh/openFace/OpenFace-3.0/STAR'`) → `Permission
255
+ denied: '/work'` on any other machine until patched.
256
+ 2. `openface detect-video` throws an **OpenCV `imread` error** (mishandles video
257
+ frames) — video mode is unusable.
258
+ 3. `openface ... -d cuda` always raises *"provide at least one valid device
259
+ ID"* — the CLI never passes `device_ids`, so **GPU mode is broken** from the
260
+ CLI.
261
+
262
+ Critically, **the CLI also hardcodes `device='cpu'`** inside `process_image`
263
+ (line 23) — so `openface detect -d cuda` silently runs on CPU. The fix is to
264
+ **bypass the CLI** and construct the pipeline objects directly with real device
265
+ handling: `FaceDetector(device='cuda')`, `LandmarkDetector(device='cuda',
266
+ device_ids=[0])`, `MultitaskPredictor(device='cuda')`. Done that way OF3 runs
267
+ fine on GPU **including Blackwell** (modern torch).
268
+
269
+ Once the CLI is bypassed, OF3 is solid: AU accuracy on DISFA+ **0.488** (8 AUs)
270
+ and end-to-end speed **18.3 fps** on the 3090 (batch 1, rigorous harness —
271
+ warmup + repeats, median). So OF3 is the *least* broken competitor — it just
272
+ needs the CLI worked around. (The running, once set up, is reliable — the
273
+ friction is all in packaging.) Note its **MTL AU model batches fine** (the model
274
+ takes `[B,…]`; the shipped pipeline just feeds one face at a time), so OF3 *could*
275
+ be sped up with a custom batched runner — its API simply doesn't.
276
+
277
+ ### PyAFAR — dependency rot + API/coverage mismatch
278
+ Another multi-obstacle integration (its own MediaPipe + TensorFlow env, kept
279
+ away from the torch stack):
280
+
281
+ 1. **Won't `pip install`.** The release wheel pins `pysimplegui==4.60.5`, a GUI
282
+ library that PySimpleGUI **pulled from PyPI** (2024 licensing change), so the
283
+ dependency is unsatisfiable — a GUI pin blocks a headless benchmark. Workaround:
284
+ install the wheel `--no-deps` and hand-resolve the real runtime deps
285
+ (`tqdm`, `scipy`, `h5py`, `tensorflow`, `mediapipe`, `opencv`, …) one ImportError
286
+ at a time.
287
+ 2. **dlib won't build.** `pip install dlib` compiles from source and fails on its
288
+ **CUDA** kernels (same Blackwell sm_120 wall); the documented path is a **conda**
289
+ env with conda-forge's precompiled dlib.
290
+ 3. **Video-only API.** `adult_afar(filename=<video>, …)` takes a video file —
291
+ DISFA+ is per-frame stills, so frames must be re-assembled into per-trial
292
+ videos to feed it.
293
+ 4. **Partial AU coverage.** Its occurrence AUs {1,2,4,6,7,10,12,14,15,17,23,24}
294
+ overlap DISFA's 12 on only **7** (1,2,4,6,12,15,17); intensity on **3**
295
+ (6,12,17). It cannot score the full DISFA AU set.
296
+ 5. Non-commercial license; GPU only on Ubuntu/WSL2.
297
+
298
+ Contrast: py-feat is one `pip install`, works headless, takes images or video,
299
+ and reports all 20 AUs. [PyAFAR DISFA+ numbers — pending the conda env + a
300
+ frame-to-video adapter; coverage limited to the 7 overlapping AUs.]
301
+
302
+ ## Hardware notes
303
+
304
+ - **LibreFace can only be benchmarked on ≤ Ampere GPUs (e.g. RTX 3090, sm_86)**
305
+ because its pinned PyTorch lacks Blackwell (sm_120) kernels. All LibreFace
306
+ numbers here are 3090 runs.
307
+ - py-feat and the competitor runs that use modern torch run on Blackwell
308
+ (RTX PRO 6000) and the 3090 alike.
309
+
310
+ ## License caveats (research benchmark only)
311
+
312
+ - LibreFace: USC research-only. PyAFAR: non-commercial. OpenFace 3.0: check its
313
+ license. py-feat's competitors are **never** added as py-feat dependencies —
314
+ each runs in its own isolated env (`~/benchmark-envs/<tool>`), consuming a
315
+ frozen DISFA manifest (`scripts/competitors/`) so the comparison shares
316
+ identical frames/labels without coupling envs.
317
+
318
+ ## Reproducing
319
+
320
+ - Manifest (py-feat env): `scripts/competitors/export_disfaplus_manifest.py`
321
+ (DISFA equivalent forthcoming).
322
+ - LibreFace research model: clone `ihp-lab/LibreFace`, use `AU_Recognition`
323
+ RepVGG checkpoint, **on a 3090**.
324
+ - py-feat v1/v2 accuracy: `scripts/bench_accuracy.py --detector v1|v2`.