totes-emosh / scratch /smoke_pyfeat.py
drdeception
feat: six-emotion replication challenge — totes-emosh EmotionMap build
0d27c43
Raw
History Blame Contribute Delete
1.71 kB
"""Smoke test py-feat AU + emotion detection on bundled sample faces.
Verifies py-feat installs cleanly on macOS, downloads its model
weights, and returns AU intensities that look sane for the labelled
sample faces (e.g. Happy.png should fire AU 6 / AU 12).
Run from repo root: `uv run python scratch/smoke_pyfeat.py`
"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).parent.parent
def main() -> None:
from feat import Detector
detector = Detector(
face_model="retinaface",
landmark_model="mobilefacenet",
au_model="xgb",
emotion_model="resmasknet",
facepose_model="img2pose",
device="cpu",
)
images_dir = ROOT / "images"
samples = sorted(
p for p in images_dir.glob("*.png")
if p.stem not in {"LMLLOGO", "LMLOBS"}
)
for sample in samples:
print(f"\n=== {sample.name} ===")
try:
result = detector.detect_image(str(sample))
except Exception as exc:
print(f" FAILED: {exc}")
continue
aus = result.aus()
emotions = result.emotions()
if aus.empty:
print(" no face detected")
continue
au_row = aus.iloc[0].sort_values(ascending=False)
top_aus = au_row[au_row > 0.5].head(6)
print(" top AUs (>0.5):")
for au, score in top_aus.items():
print(f" {au:>6} {score:.2f}")
emo_row = emotions.iloc[0]
ranked = emo_row.sort_values(ascending=False)
print(" emotions:")
for emo, p in ranked.items():
print(f" {emo:<10} {p:.3f}")
if __name__ == "__main__":
main()