AsianPlayer/TriDrive / code /baselines_dms /phase1_summary.py
AsianPlayer's picture
download
raw
29.3 kB
"""cwm3/baselines_dms/phase1_summary.py — results/baselines_dms/phase1/PHASE1_SUMMARY.md from the six Phase-1 measurements.json files (2026-09-14, after the shared video_io fixes).
Reads ONLY files produced by the extractors' --phase1 runs (measurements.json, cache/*.npz meta) plus the face pack for the eye-state check; writes one summary table
(row per baseline: device, n_frames, valid share, fail hist, infer / decode ms, fps, peak RSS / VRAM, rho vs lm_yaw_dev raw + circular-centred, sign-convention and eye-state
checks, readiness verdict on runnability / throughput / validity only) and one projection table (full test+val extraction time from the measured fps; shared decode floor).
Eye-state check (uniform for the three baselines with an eye channel): Spearman rho of the baseline's per-frame eye channel vs the face pack `eye_open` (EAR-based) over the
80 history steps of every manifest anchor (facehist_causal_{regime}_train.npz row `row`), computed here from the caches. No label is used for anything but a descriptive block.
python baselines_dms/phase1_summary.py [--out results/baselines_dms/phase1/PHASE1_SUMMARY.md]
"""
from __future__ import annotations
import json
import sys
import time
from pathlib import Path
import numpy as np
PKG = Path(__file__).resolve().parent
CWM3 = PKG.parent
if str(PKG) not in sys.path:
sys.path.insert(0, str(PKG))
import cache_schema as cs # noqa: E402
P1 = CWM3 / "results" / "baselines_dms" / "phase1"
MANIFEST = P1 / "manifest_v1.csv"
FACE_PACK = CWM3 / "results" / "targets_face_causal_routes_v2" / "facehist_causal_{regime}_train.npz"
BASELINES = ["ov_gaze", "ov_action", "mp_face", "openface3", "l2cs_gaze", "videomae2"]
EXPOSURE_H, EXPOSURE_FRAMES = 63.7, 2_290_000 # test+val exposure of the s12 packs -> 10 Hz frames (task statement)
GO_MAX_H, BLOCKED_MIN_H = 24.0, 72.0 # projected full-extraction time thresholds of the verdict (stated in the table)
def g(d, *path, default=None):
for k in path:
if not isinstance(d, dict) or k not in d:
return default
d = d[k]
return d
def fmt(x, nd=2, pct=False):
if x is None or (isinstance(x, float) and not np.isfinite(x)):
return "n/a"
if pct:
return f"{100 * float(x):.1f} %"
return f"{float(x):.{nd}f}" if isinstance(x, (int, float, np.floating, np.integer)) else str(x)
def hist_str(h):
if not isinstance(h, dict):
return "n/a"
return ", ".join(f"{k} {int(v)}" for k, v in h.items() if int(v) > 0)
def load_meas(b):
p = P1 / b / "measurements.json"
return json.loads(p.read_text()) if p.exists() else None
def cache_meta_summary(b, sub="cache"):
"""per-baseline aggregate of the cache meta written by the fixed runner: native_fps of every route, decoders used, seek corrections, decode_exact."""
out = {"n_caches": 0, "native_fps_ne20": [], "decoders": set(), "n_seek_corrected": 0, "max_landing_offset": 0, "n_gap_reseeks": 0, "decode_exact": True, "seek_corrected_all": True}
for p in sorted((P1 / b / sub).glob("*.npz")):
try:
c = cs.load_any(p)
except Exception:
continue
out["n_caches"] += 1
m = c.meta
fps = m.get("native_fps")
if fps is not None and abs(float(fps) - 20.0) > 1e-6:
out["native_fps_ne20"].append((c.uid.split("__")[0][:14], round(float(fps), 4)))
if not m.get("seek_corrected"):
out["seek_corrected_all"] = False
ds = m.get("decode_stats") or {}
out["decoders"].update(ds.get("decoder", []))
out["n_seek_corrected"] += int(ds.get("n_seek_corrected", 0))
out["max_landing_offset"] = max(out["max_landing_offset"], int(ds.get("max_landing_offset", 0)))
out["n_gap_reseeks"] += int(ds.get("n_gap_reseeks", 0))
out["decode_exact"] = out["decode_exact"] and bool(ds.get("decode_exact", True))
out["decoders"] = sorted(out["decoders"])
return out
def manifest_rows():
import csv
return list(csv.DictReader(open(MANIFEST)))
def face_pack_eye_open(rows):
"""{idx: (k i64[80], eye_open f32[80])} for every manifest row (same alignment as the extractors: Fh8_c[row, j] <-> t_anchor - 7.9 + 0.1 j)."""
out = {}
for reg in ("manual", "engaged"):
sub = [r for r in rows if r["regime"] == reg]
with np.load(str(FACE_PACK).format(regime=reg), allow_pickle=True) as z:
ch = [str(c) for c in z["channels"]]
j_eye = ch.index("eye_open")
rr = np.array([int(r["row"]) for r in sub])
assert all(str(z["uid"][int(r["row"])]) == r["uid"] for r in sub), f"{reg}: manifest rows do not match the face pack"
Fh = z["Fh8_c"][rr][:, :, j_eye].astype(np.float32)
Fv = z["Fh8valid"][rr]
for i, r in enumerate(sub):
ka = int(round(float(r["t_anchor"]) * cs.HZ))
out[int(r["idx"])] = (ka - 79 + np.arange(80), np.where(Fv[i], Fh[i], np.nan))
return out
def eye_state_rho(b, channels, rows, eye_ref, combine="mean"):
"""Spearman rho (pooled over anchors x 80 steps) of the baseline eye channel(s) vs the face pack eye_open; -> dict(rho, n, expected_sign, channels)."""
from scipy.stats import spearmanr
a_all, b_all = [], []
caches = {}
for r in rows:
u = r["uid"]
if u not in caches:
p = P1 / b / "cache" / f"{u}.npz"
caches[u] = cs.RouteCache.load(p) if p.exists() else None
rc = caches[u]
if rc is None:
continue
k = np.round(rc.t.astype(np.float64) * cs.HZ).astype(np.int64)
pos = {int(kk): i for i, kk in enumerate(k)}
kk, eye = eye_ref[int(r["idx"])]
feat = rc.feat.astype(np.float32)
js = [rc.channels.index(c) for c in channels]
v = np.array([np.nanmean(feat[pos[x], js]) if x in pos and rc.valid[pos[x]] else np.nan for x in kk])
a_all.append(v)
b_all.append(eye)
a, bb = np.concatenate(a_all), np.concatenate(b_all)
m = np.isfinite(a) & np.isfinite(bb)
rho = float(spearmanr(a[m], bb[m]).statistic) if m.sum() >= 8 else float("nan")
return {"rho": rho, "n": int(m.sum()), "channels": list(channels)}
def build():
rows = manifest_rows()
eye_ref = face_pack_eye_open(rows)
M = {b: load_meas(b) for b in BASELINES}
CM = {b: cache_meta_summary(b) for b in BASELINES}
R = {} # per-baseline row values
# ------------------------------------------------------------------ ov_gaze
m = M["ov_gaze"]
if m:
eye = eye_state_rho("ov_gaze", ["ov_eye_closed_l", "ov_eye_closed_r"], rows, eye_ref)
p_closed_share = None
st = m.get("extractor_stats", {})
if st.get("eye_p_open_n"):
p_closed_share = 1.0 - st["eye_p_open_sum"] / st["eye_p_open_n"] # mean p_closed over eyes (descriptive)
R["ov_gaze"] = dict(device="CPU (openvino, 4 thr)", n_frames=m["n_frames"], valid_box=m["valid_share_with_box"], valid_all=m["valid_share"], fail=m["fail_hist"],
infer=f"{fmt(g(m,'infer_ms_per_frame','p50'))} / {fmt(g(m,'infer_ms_per_frame','p95'))} per frame", decode=g(m, "decode_ms_per_frame", "p50_frame_weighted_median_of_route_p50"),
fps=m.get("fps_end_to_end"), rss=g(m, "peak_rss_mb", "self_peak_mb"), vram=m.get("vram_mb_peak"),
rho=f"head_yaw {fmt(g(m,'spearman_vs_face_pack','rho_head_yaw_vs_lm_yaw_dev_pooled'),3)} pooled / {fmt(g(m,'spearman_vs_face_pack','per_anchor_rho_head_yaw_median'),3)} per-anchor median; "
f"window-centred {fmt(g(m,'spearman_vs_face_pack','rho_head_yaw_minus_window_median_vs_lm_yaw_dev_minus_window_median_pooled'),3)}; gaze_yaw {fmt(g(m,'spearman_vs_face_pack','rho_gaze_yaw_vs_lm_yaw_dev_pooled'),3)}",
sign="confirmed (ov_head_yaw > 0 = image right, same sign as lm_yaw; contact sheet + rho > 0)",
eye=f"mean p_closed vs face-pack eye_open rho {fmt(eye['rho'],3)} (n {eye['n']}; expected < 0); own json {fmt(g(m,'eye_class_order','rho_mean_eye_closed_vs_facepack_eye_open'),3)}",
extra={"mean_p_closed": p_closed_share, "eye": eye})
# ------------------------------------------------------------------ ov_action
m = M["ov_action"]
if m:
fr, wn, run = m.get("frames", {}), m.get("windows", {}), m.get("run", {})
wall = g(run, "wall_extract_s") or g(run, "summary", "wall_s")
fps = g(run, "frames_per_s_end_to_end_extract") or (fr.get("n_frames") / wall if wall else None) # decode + crop + letterbox + encoder over the 50 spans
top = wn.get("top_class_hist_all_valid_windows", {})
top_s = ", ".join(f"{k} {v}" for k, v in sorted(top.items(), key=lambda kv: -kv[1])[:4])
rss = g(run, "peak_rss_mb_end", "self_mb") or g(run, "peak_rss_mb_after_extraction", "self_mb")
R["ov_action"] = dict(device="CPU (openvino, 4 thr)", n_frames=fr.get("n_frames"), valid_box=fr.get("valid_share_with_box"), valid_all=fr.get("valid_share"), fail=fr.get("fail_hist"),
infer=f"encoder {fmt(g(fr,'encoder_infer_ms_per_frame','p50'))} / {fmt(g(fr,'encoder_infer_ms_per_frame','p95'))} per frame; decoder {fmt(g(wn,'decoder_infer_ms_per_window','p50'))} / {fmt(g(wn,'decoder_infer_ms_per_window','p95'))} per 16-frame window",
decode=g(fr, "decode_ms_per_frame", "route_p50_median"), fps=fps, rss=rss, vram=0.0,
rho=f"no yaw channel; proxies: 1-p_safe vs |lm_yaw_dev| {fmt(g(m,'spearman_vs_face_pack','rho_1_minus_p_safe_vs_abs_lm_yaw_dev'),3)}, L/R asymmetry vs lm_yaw_dev {fmt(g(m,'spearman_vs_face_pack','rho_lr_asym_vs_lm_yaw_dev'),3)}",
sign="not applicable (action logits / embedding)", eye="not applicable (no eye channel)",
extra={"top": top_s, "windows_valid": wn.get("valid_share"), "n_windows": wn.get("n_windows"), "wall": wall})
# ------------------------------------------------------------------ mp_face
m = M["mp_face"]
if m:
eye = eye_state_rho("mp_face", ["mp_blink_l", "mp_blink_r"], rows, eye_ref)
rt = m.get("runtime", {})
fp = m.get("face_pack_yaw", {})
R["mp_face"] = dict(device="CPU (mediapipe, 4 thr)", n_frames=m["n_frames"], valid_box=m["valid_share_with_box"], valid_all=m["valid_share_overall"], fail=m["fail_hist"],
infer=f"{fmt(g(rt,'infer_ms_per_frame','p50'))} / {fmt(g(rt,'infer_ms_per_frame','p95'))} per frame", decode=g(rt, "decode_ms_per_frame_route_p50", "p50"),
fps=rt.get("fps_end_to_end"), rss=rt.get("peak_rss_mb_main"), vram=rt.get("vram_mb_peak"),
rho=f"mp_head_yaw {fmt(g(fp,'rho_pooled_vs_lm_yaw_dev','rho'),3)} pooled / {fmt(fp.get('per_anchor_rho_median'),3)} per-anchor median; window-centred {fmt(g(fp,'rho_within_window_centred_vs_lm_yaw_dev','rho'),3)}",
sign="confirmed (rho vs landmark yaw proxy " + fmt(g(m, "sign_convention", "rho_yaw_vs_landmark_yaw_proxy", "rho"), 2) + "; contact sheet inspected)",
eye=f"mean blink prob vs face-pack eye_open rho {fmt(eye['rho'],3)} (n {eye['n']}; expected < 0); vs own EAR: blink_l/ear_l {fmt(g(m,'blink_ear_pairing','rho_blink_l_vs_ear_l','rho'),2)}",
extra={"no_face_share": (m["fail_hist"].get("no_face", 0) / max(m["n_frames"], 1)), "eye": eye, "stage": m.get("stage_counts")})
# ------------------------------------------------------------------ openface3
m = M["openface3"]
if m:
eye = eye_state_rho("openface3", ["of3_eye_open_l", "of3_eye_open_r"], rows, eye_ref)
sp = m.get("spearman_vs_face_pack", {})
fc = g(m, "contact_sheet", "flip_check") or {}
corr = fc.get("head_yaw_corr_orig_vs_minus_flip")
hy = g(sp, "head_yaw", "rho_pooled")
hy_abs = g(sp, "head_yaw_vs_lm_yaw", "rho_pooled")
strong = (hy is not None and hy > 0.3 and hy_abs is not None and hy_abs > 0.5) # same sign definition as lm_yaw (+ = nose toward image right) and a strong positive rho
sign = ("confirmed" if strong else "unclear") + (f" (synthetic PnP check passed; rho vs lm_yaw +{fmt(hy_abs,2)} with the same sign definition; mirror antisymmetry only weak: corr(orig, -flip) {fmt(corr,2)}, mean sum {fmt(fc.get('head_yaw_mean_sum_orig_plus_flip_deg'),1)} deg on 12 crops)"
if strong else f" (mirror antisymmetry corr {fmt(corr,2)}, rho vs lm_yaw {fmt(hy_abs,2)})")
R["openface3"] = dict(device="cuda:0 (RetinaFace + STAR + MTL, fp32)", n_frames=m["n_frames"], valid_box=m["valid_share_with_box"], valid_all=m["valid_share_overall"], fail=m["fail_hist"],
infer=f"{fmt(g(m,'infer_ms_per_frame','p50'))} / {fmt(g(m,'infer_ms_per_frame','p95'))} per frame (det {fmt(g(m,'infer_ms_per_frame','stages_p50','det'))}, lm {fmt(g(m,'infer_ms_per_frame','stages_p50','lm'))}, mtl {fmt(g(m,'infer_ms_per_frame','stages_p50','mtl'))} p50)",
decode=g(m, "decode_ms_per_frame", "route_p50_median"), fps=m.get("fps_end_to_end"), rss=g(m, "peak_rss", "main_process_mb"), vram=g(m, "vram", "peak_allocated_mb"),
rho=f"of3_head_yaw {fmt(hy,3)} pooled / {fmt(g(sp,'head_yaw','per_anchor_median'),3)} per-anchor median; of3_gaze_yaw {fmt(g(sp,'gaze_yaw','rho_pooled'),3)} / {fmt(g(sp,'gaze_yaw','per_anchor_median'),3)}",
sign=sign, eye=f"mean EAR vs face-pack eye_open rho {fmt(eye['rho'],3)} (n {eye['n']}; expected > 0); own json {fmt(g(sp,'ear_mean_vs_facepack_eye_open','rho_pooled'),3)}",
extra={"eye": eye, "gaze_units_ok": g(m, "gaze_units", "ok"), "vram_reserved": g(m, "vram", "peak_reserved_mb")})
# ------------------------------------------------------------------ l2cs_gaze
m = M["l2cs_gaze"]
if m:
rho = m.get("rho_vs_lm_yaw_dev", {})
pf = m.get("per_frame_ms", {})
yaw_p50 = g(m, "value_distribution_valid_frames", "l2cs_yaw", "p50")
fr12 = g(m, "contact_sheet", "frames") or []
flips = [f for f in fr12 if f.get("mirrored_crop_yaw") is not None and np.isfinite(f["mirrored_crop_yaw"]) and np.sign(f["mirrored_crop_yaw"]) == -np.sign(f["l2cs_yaw"])]
R["l2cs_gaze"] = dict(device="cuda:0 (RetinaFace + L2CS ResNet50)", n_frames=m["n_frames"], valid_box=m["valid_share_with_box"], valid_all=m["valid_share"], fail=m["fail_hist"],
infer=f"{fmt(pf.get('infer_p50_route_median'))} / {fmt(pf.get('infer_p95_route_median'))} per frame (RetinaFace {fmt(pf.get('det_ms_p50'))}, L2CS {fmt(pf.get('gaze_ms_p50'))} p50)",
decode=pf.get("decode_p50_route_median"), fps=m.get("fps_end_to_end"), rss=g(m, "peak_rss_mb", "self_max_rss_mb"), vram=g(m, "peak_vram_mb", "torch_max_allocated_mb"),
rho=f"l2cs_yaw raw {fmt(g(rho,'pooled','l2cs_yaw','rho'),3)} pooled / {fmt(g(rho,'per_anchor_median_rho','l2cs_yaw','median'),3)} per-anchor median; "
f"CIRCULAR-centred (route causal median) {fmt(g(rho,'pooled_circular_centred_route_causal_median','l2cs_yaw','rho'),3)} pooled / {fmt(g(rho,'per_anchor_median_rho_circular_centred','l2cs_yaw','median'),3)} per-anchor median "
f"(sign + = image LEFT, so a tracking relation is negative)",
sign=f"unclear (mirror flipped the yaw sign on {len(flips)} / {len(fr12)} sheet crops; yaw p50 {fmt(yaw_p50,1)} deg, |yaw| > 90 regime)",
eye="not applicable (no eye channel)", extra={"yaw_p50": yaw_p50, "multi_face": m.get("n_multi_face_crops"), "vram_reserved": g(m, "peak_vram_mb", "torch_max_reserved_mb")})
# ------------------------------------------------------------------ videomae2
m = M["videomae2"]
if m:
tm, mem = m.get("timing", {}), m.get("memory", {})
R["videomae2"] = dict(device="cuda:0 (ViT-S fp16)", n_frames=m["n_frames"], valid_box=g(m, "valid_share", "per_frame_on_frames_with_box"), valid_all=g(m, "valid_share", "per_frame_overall"),
fail=m.get("fail_hist_per_frame"), infer=f"{fmt(g(tm,'infer_ms_per_window','p50'))} / {fmt(g(tm,'infer_ms_per_window','p95'))} per 16-frame window (batched); letterbox {fmt(g(tm,'preprocess_ms_per_5hz_frame','p50'))} per 5 Hz frame",
decode=g(tm, "decode_ms_per_frame", "p50"), fps=tm.get("frames_per_s_end_to_end"), rss=g(mem, "peak_rss", "main_mb"), vram=g(mem, "vram", "peak_allocated_mb"),
rho=f"no yaw channel; PC1 of the embedding vs lm_yaw_dev {fmt(g(m,'rho','spearman_pc1_vs_lm_yaw_dev_at_t_end'),3)} (window mean {fmt(g(m,'rho','spearman_pc1_vs_lm_yaw_dev_window_mean'),3)})",
sign="not applicable (384-d embedding)", eye="not applicable (no eye channel)",
extra={"n_windows": m.get("n_windows"), "n_windows_valid": m.get("n_windows_valid"), "win_valid": g(m, "valid_share", "window_overall"), "frames_in_windows": m.get("n_frames_in_manifest_windows"),
"wall": tm.get("wall_s_routes_loop"), "fail_win": m.get("fail_hist_per_window")})
return M, CM, R
def verdict(b, r, hours):
"""runnability / throughput / validity ONLY (never the label relation). go: completed, valid share with box >= 0.90, projected <= 24 h; go-with-caveat: completed but a
channel-validity caveat or 24 h < projected <= 72 h; blocked: did not complete or projected > 72 h."""
if r is None:
return "blocked", "no measurements.json (run did not complete)"
cav = []
vb = r.get("valid_box")
if vb is not None and vb < 0.90:
cav.append(f"valid share with box {fmt(vb,3)} < 0.90" + (f" (no face on {fmt(r['extra']['no_face_share'], pct=True)} of frames)" if b == "mp_face" else ""))
if hours is not None and hours > BLOCKED_MIN_H:
return "blocked", f"projected full extraction {hours:.0f} h > {BLOCKED_MIN_H:.0f} h"
if hours is not None and hours > GO_MAX_H:
cav.append(f"projected full extraction {hours:.0f} h (> {GO_MAX_H:.0f} h; decode / RetinaFace bound)")
ex = r.get("extra", {})
if b == "ov_gaze":
e = ex.get("eye", {})
cav.append(f"eye-state channel unreliable on this IR footage: mean p_closed {fmt(ex.get('mean_p_closed'), pct=True)}, rho vs face-pack eye_open {fmt(e.get('rho'),3)} (uncorrelated) -> the `closed` chain arm will over-fire")
if b == "ov_action":
cav.append(f"no head / gaze channel; top classes on this footage: {ex.get('top')}; 16-frame windows, decoder batch 1")
if b == "l2cs_gaze":
cav.append(f"l2cs_yaw centred near {fmt(ex.get('yaw_p50'),0)} deg with the +-180 wrap (side camera): use only the circular route-referenced features; raw pooled rho ~ 0; mirror-sign check unclear; RetinaFace Python post-processing bounds fps")
if b == "openface3":
e = ex.get("eye", {})
if e.get("rho") is not None and np.isfinite(e["rho"]) and e["rho"] < 0.1:
cav.append(f"EAR eye channel weakly related to the face-pack eye_open (rho {fmt(e['rho'],3)})")
if b == "mp_face" and not cav:
cav.append("")
cav = [c for c in cav if c]
return ("go-with-caveat" if cav else "go"), "; ".join(cav) if cav else "-"
def write(out_path):
M, CM, R = build()
ex_json = json.loads((P1 / "decode_exactness_check.json").read_text()) if (P1 / "decode_exactness_check.json").exists() else None
lines = [f"# Phase 1 — DMS baselines on the frozen manifest `manifest_v1.csv` (50 TRAIN anchors / 45 routes, window [t−10 s, t+0.2 s], 10 Hz) — summary after the shared video_io fixes",
"", f"Written by `baselines_dms/phase1_summary.py` on {time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())}; every number below is read from `results/baselines_dms/phase1/<baseline>/measurements.json` "
"(re-runs `--phase1 --workers 3 --force` with the fixed `video_io.py`), the cache meta, or `decode_exactness_check.json`. Nothing was tuned on labels.", "",
"## Shared fixes applied before the re-run (`baselines_dms/video_io.py`, `summarise.py`, `rules.py`)", "",
"1. `frames_in_spans` snaps span ends within 0.02 s onto the 10 Hz grid (the ends are float32 in the cache schema; the plain floor / ceil decoded one frame outside the requested span on ~half the windows).",
"2. `decode_block` is index-exact: cv2's `CAP_PROP_POS_FRAMES` seek converts the index with the container header fps, which is not exactly 20 on 6 / 45 manifest routes "
"(HYUNDAI_TUCSON 19.9894 / 19.9940 / 19.9914 → +2..+5 frames late at frame indices ~10^4; RIVIAN 20.0002 → −1; ELANTRA 20.0001; Unknown__04219e 19.9993). Header fps == 20 (39 routes, clean 50 ms pts grid): "
"the landing is read back from the pts clock and corrected (grab forward / re-seek earlier), every grabbed pts checked; header fps != 20: decord `get_batch` through the file's pts table (5 of those 6 routes have stretched pts segments, "
"so a pts-based cv2 correction alone would not be exact). Gaps > 60 frames inside a block are crossed by a fresh seek (the openface3 stall: a 64-frame block straddling two windows 600 s apart grabbed ~12,000 native HEVC frames at 947 ms / frame). "
"Cache meta now carries `native_fps`, `seek_corrected`, `decode_stats`.", ]
if ex_json:
lines += [" Exactness check (`python baselines_dms/video_io.py --verify-exact`, all 10 Hz frames of the manifest windows vs one continuous decode from frame 0):", "",
" | route | header fps | decoder | frames checked | max abs pixel diff | plain cv2 seek offset (frame → delivered − f) |", " |---|---|---|---|---|---|"]
for r in ex_json["routes"]:
lines.append(f" | {r['uid'][:52]} | {r['header_fps']} | {r['decoder']} | {r['n_frames_checked']} ({r['frame_idx_range'][0]}–{r['frame_idx_range'][1]}) | **{r['max_abs_pixel_diff']}** | " + ", ".join(f"{k}: {'+' if isinstance(v, int) and v > 0 else ''}{v}" for k, v in r["plain_cv2_seek_offset_by_frame"].items()) + " |")
lines.append(f" all_exact = **{ex_json['all_exact']}**.")
lines += ["3. `summarise.angle_block` / `rules.off_state` use the circular deviation dev = ((x − ref + 180) mod 360) − 180 for every angle_deg channel (L2CS yaw wraps near ±180 on this camera); "
"rule0 / ruleref and the hysteresis operate on |dev| (unit test `test_angle_deviation_is_circular`: 179 vs −179 → 2, not 358).",
"4. `openface3.cli_phase1` runs one `run_route` per contiguous span (no block ever straddles a gap); the frozen pose caches were produced with the plain seek, so on the fps != 20 routes the driver boxes may lag the corrected frames by up to 0.25 s (used as given).", "",
"## Table 1 — measurements per baseline (frames = 10 Hz cache rows inside the manifest windows unless stated)", "",
"| baseline | device | n_frames (with box) | valid share with box (overall) | fail hist | infer ms p50 / p95 | decode ms p50 (worker, per frame) | fps end-to-end | peak RSS MB | peak VRAM MB | rho vs lm_yaw_dev (head-yaw-like channel) | sign convention (contact sheet) | eye-state check | readiness (layers 1–3) | caveat |",
"|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|"]
hours = {}
for b in BASELINES:
r = R.get(b)
if r is None:
lines.append(f"| {b} | – | – | – | – | – | – | – | – | – | – | – | – | **blocked** | no measurements.json |")
continue
fps = r.get("fps")
frames_full = EXPOSURE_FRAMES * (r["extra"].get("frames_in_windows") and r["n_frames"] / r["extra"]["frames_in_windows"] or 1.0) if b == "videomae2" else EXPOSURE_FRAMES
hours[b] = frames_full / fps / 3600.0 if fps else None
v, cav = verdict(b, r, hours[b])
nbox = r["n_frames"] - int((r["fail"] or {}).get("no_box", 0)) if isinstance(r["fail"], dict) else None
nf = f"{r['n_frames']} ({nbox})" + (f"; incl. 3 s window lead-in, {r['extra']['frames_in_windows']} in the windows" if b == "videomae2" and r["extra"].get("frames_in_windows") else "")
lines.append(f"| **{b}** | {r['device']} | {nf} | **{fmt(r['valid_box'],3)}** ({fmt(r['valid_all'],3)}) | {hist_str(r['fail'])} | {r['infer']} | {fmt(r['decode'],1)} | **{fmt(fps,1)}** | {fmt(r['rss'],0)} | {fmt(r['vram'],0)} | {r['rho']} | {r['sign']} | {r['eye']} | **{v}** | {cav} |")
lines += ["", "Verdict rule (runnability / throughput / validity only, never the label relation): go = completed, valid share with box ≥ 0.90 and projected full extraction ≤ 24 h; go-with-caveat = completed but a channel-validity caveat or 24–72 h; blocked = did not complete or > 72 h.", "",
"Decode provenance from the cache meta (fixed runner):", ""]
for b in BASELINES:
c = CM[b]
if c["n_caches"]:
lines.append(f"- {b}: {c['n_caches']} caches, seek_corrected on all = {c['seek_corrected_all']}, decoders {c['decoders']}, routes with header fps != 20: {len(c['native_fps_ne20'])} {sorted(set(c['native_fps_ne20']))}, "
f"cv2 landings corrected {c['n_seek_corrected']} (max |offset| {c['max_landing_offset']}), gap re-seeks {c['n_gap_reseeks']}, decode_exact = {c['decode_exact']}")
lines += ["", "## Table 2 — projected full extraction for the test+val exposure (63.7 h → 2.29 M frames @ 10 Hz) from the measured end-to-end fps", "",
"| baseline | measured fps end-to-end (Phase 1, 3 decode workers) | frames to process | projected wall | decode floor (3 workers, measured decode ms p50) |", "|---|---|---|---|---|"]
for b in BASELINES:
r = R.get(b)
if r is None or not r.get("fps"):
lines.append(f"| {b} | n/a | – | – | – |")
continue
frames_full = EXPOSURE_FRAMES * (r["n_frames"] / r["extra"]["frames_in_windows"]) if (b == "videomae2" and r["extra"].get("frames_in_windows")) else EXPOSURE_FRAMES
floor_h = frames_full * (r["decode"] or float("nan")) / 3.0 / 3.6e6
lines.append(f"| {b} | {fmt(r['fps'],1)} | {frames_full/1e6:.2f} M{' (incl. 3 s window lead-in)' if b == 'videomae2' else ''} | **{hours[b]:.1f} h** | {floor_h:.1f} h |")
dec = [r["decode"] for r in R.values() if r and r.get("decode") and r["device"] and "cuda" in r["device"] or False]
native = [R[b]["decode"] for b in ("ov_gaze", "mp_face", "l2cs_gaze", "openface3") if R.get(b) and R[b].get("decode")]
if native:
med = float(np.median(native))
lines += ["", f"Shared-decode floor: at native resolution the workers measure {fmt(min(native),1)}–{fmt(max(native),1)} ms per 10 Hz frame (median {med:.1f} ms, seek + grab of 2 video frames + retrieve); with 3 workers that is "
f"≥ {EXPOSURE_FRAMES * med / 3.0 / 3.6e6:.1f} h for 2.29 M frames regardless of the model, i.e. one shared native decode pass (or a 600 px pass at "
f"{fmt(R['videomae2']['decode'],1) if R.get('videomae2') else 'n/a'} ms/frame → {EXPOSURE_FRAMES * (R['videomae2']['decode'] if R.get('videomae2') else float('nan')) / 3.0 / 3.6e6:.1f} h) should feed every per-frame baseline in layers 1–3. "
"Phase-1 fps were measured while other jobs shared the CPU / GPU (see the run logs); treat them as lower bounds."]
# descriptive by y (never used for selection)
lines += ["", "## Descriptive by manifest `y` (reported as measured; never used for any choice)", ""]
for b in BASELINES:
m = M.get(b)
if m and m.get("descriptive_by_y"):
lines.append(f"- {b}: `{json.dumps(m['descriptive_by_y'], default=str)[:600]}`")
elif m and m.get("descriptive_by_y_max_abs_yaw_3s"):
lines.append(f"- {b}: `{json.dumps(m['descriptive_by_y_max_abs_yaw_3s'], default=str)[:600]}`")
lines += ["", "Files: `<baseline>/measurements.json`, `<baseline>/cache/*.npz` (+ `windows/` / `cache_win/` for the window models), contact sheets `<baseline>/*contact_sheet*.png`, run logs `<baseline>/phase1_run*.log` / `phase1_rerun_20260914.log`, `decode_exactness_check.json`.", ""]
Path(out_path).write_text("\n".join(lines))
return out_path, R, hours
if __name__ == "__main__":
import argparse
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--out", default=str(P1 / "PHASE1_SUMMARY.md"))
a = ap.parse_args()
p, R, hours = write(a.out)
print(json.dumps({"written": str(p), "baselines": {b: {"fps": (R[b].get("fps") if R.get(b) else None), "hours": hours.get(b)} for b in BASELINES}}, indent=1, default=str))

Xet Storage Details

Size:
29.3 kB
·
Xet hash:
a146291a53289367188ae3ceaa837178694ed8e7134f651b2191cbe953cd0e67

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.