totes-emosh / scratch /smoke_upstream.py
drdeception
feat: six-emotion replication challenge — totes-emosh EmotionMap build
0d27c43
Raw
History Blame Contribute Delete
1.5 kB
"""End-to-end smoke test of the post-R0 pipeline.
Calls preprocess_image_and_predict on each bundled sample face. After
R0 the function uses the MediaPipe Face Landmarker (tasks API) for
face detection + bbox, and the upstream ResNet50 + Grad-CAM for
emotion classification. This exercises both halves of the new
pipeline together.
Run from repo root: `cd ~/Code/research/totes-emosh && uv run python scratch/smoke_upstream.py`
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
from PIL import Image
ROOT = Path(__file__).parent.parent
os.chdir(ROOT)
sys.path.insert(0, str(ROOT))
def main() -> None:
from app.app_utils import preprocess_image_and_predict
images_dir = ROOT / "images"
samples = sorted(
p for p in images_dir.glob("*.png")
if p.stem not in {"LMLLOGO", "LMLOBS"}
)
print(f"{'sample':<14} {'top-1':<14} {'p':>5} {'top-2':<14} {'p':>5} {'top-3':<14} {'p':>5}")
print("-" * 90)
for sample in samples:
img = Image.open(sample).convert("RGB")
face, _heatmap, confidences = preprocess_image_and_predict(img)
if confidences is None:
print(f"{sample.stem:<14} NO FACE")
continue
ranked = sorted(confidences.items(), key=lambda x: -x[1])
top3 = ranked[:3]
row = [sample.stem.ljust(14)]
for label, p in top3:
row.append(f"{label:<14} {p:.3f}")
print(" ".join(row))
if __name__ == "__main__":
main()