Buckets:
| #!/usr/bin/env python3 | |
| """cwm3/baselines_dms/phase1_manifest.py — Phase-1 integration set (TRAIN / development only; owner-approved rule of 2026-09-14, docs/decisions.md): | |
| from the 979 human-consensus TRAIN warning anchors (data/labels.py train_label_table), seed 0, draw 25 manual + 25 engaged anchors, within each regime | |
| 10 warranted (y = 1) + 15 not warranted (y = 0), at most 2 anchors per device, only routes whose cabin video (dcamera.mp4) and causal driver-box cache | |
| (results/pose_causal_routes[_v2]/<uid>.npz) are local. Window per anchor = [t_anchor − 10 s, t_anchor + 0.2 s]. The manifest is written BEFORE any | |
| baseline is run on these clips; it is used only to measure runnability, validity shares, sign conventions and throughput (never to select results). | |
| python baselines_dms/phase1_manifest.py [--out results/baselines_dms/phase1/manifest_v1.csv] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| import time | |
| from pathlib import Path | |
| import numpy as np | |
| import pandas as pd | |
| CWM3 = Path(__file__).resolve().parents[1] | |
| for p in (CWM3 / "data", CWM3 / "eval", CWM3 / "train", CWM3 / "common", CWM3 / "baselines_dms"): | |
| sys.path.insert(0, str(p)) | |
| import labels as LB # noqa: E402 (data/labels.py — the 979-row consensus TRAIN table) | |
| import video_io as VIO # noqa: E402 | |
| RULE = {"seed": 0, "per_regime": 25, "warranted": 10, "not_warranted": 15, "device_cap": 2, "hist_s": 10.0, "post_s": 0.2, | |
| "requires": ["local dcamera.mp4", "pose_causal_routes[_v2] cache"]} | |
| def main(argv=None) -> int: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--out", default=str(CWM3 / "results" / "baselines_dms" / "phase1" / "manifest_v1.csv")) | |
| a = ap.parse_args(argv) | |
| out = Path(a.out) | |
| if out.exists(): | |
| print(f"{out} exists — manifest is frozen once written; nothing done") | |
| return 0 | |
| T = LB.train_label_table(("consensus",)) | |
| assert len(T) == 979, len(T) | |
| T = T.copy() | |
| T["local_video"] = [VIO.video_path(u).exists() for u in T.uid] | |
| T["pose_cache"] = [VIO.pose_path(u) is not None for u in T.uid] if hasattr(VIO, "pose_path") else [ | |
| (CWM3 / "results" / "pose_causal_routes_v2" / f"{u}.npz").exists() or (CWM3 / "results" / "pose_causal_routes" / f"{u}.npz").exists() for u in T.uid] | |
| elig = T[T.local_video & T.pose_cache] | |
| rng = np.random.default_rng(RULE["seed"]) | |
| rows = [] | |
| for regime in ("manual", "engaged"): | |
| for y, k in ((1, RULE["warranted"]), (0, RULE["not_warranted"])): | |
| pool = elig[(elig.regime == regime) & (elig.y == y)].sample(frac=1.0, random_state=int(rng.integers(0, 2**31 - 1))) | |
| taken_dev = {} | |
| for _, r in pool.iterrows(): | |
| if taken_dev.get(r.dongle, 0) >= RULE["device_cap"]: | |
| continue | |
| if sum(1 for x in rows if x["regime"] == regime and x["y"] == y) >= k: | |
| break | |
| taken_dev[r.dongle] = taken_dev.get(r.dongle, 0) + 1 | |
| rows.append({"idx": int(r.idx), "uid": r.uid, "dongle": r.dongle, "regime": regime, "y": int(y), "t_anchor": float(r.t_anchor), "row": int(r.row), | |
| "t0": float(r.t0), "win_start": float(r.t_anchor) - RULE["hist_s"], "win_end": float(r.t_anchor) + RULE["post_s"], | |
| "leaf": VIO.leaf_of(r.uid), "video": str(VIO.video_path(r.uid))}) | |
| M = pd.DataFrame(rows) | |
| out.parent.mkdir(parents=True, exist_ok=True) | |
| M.to_csv(out, index=False) | |
| meta = {"rule": RULE, "eligible_rows": int(len(elig)), "of_rows": int(len(T)), "drawn": int(len(M)), | |
| "per_regime_y": M.groupby(["regime", "y"]).size().to_dict() and {f"{k[0]}_y{k[1]}": int(v) for k, v in M.groupby(["regime", "y"]).size().items()}, | |
| "devices": int(M.dongle.nunique()), "routes": int(M.uid.nunique()), "written_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())} | |
| json.dump(meta, open(out.with_suffix(".json"), "w"), indent=1) | |
| print(json.dumps(meta, indent=1)) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |
Xet Storage Details
- Size:
- 4.16 kB
- Xet hash:
- 248ba7c31cd3b65dc6a990ea5282985a52b77456ef7301357ea998f4bea4119f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.