#!/usr/bin/env python3 """Within-robot progress CV for new tasks (from dataset manifest).""" from __future__ import annotations import json import re import subprocess import sys from pathlib import Path from path_detect import detect_share_roots ROOT = Path(__file__).resolve().parent PY = sys.executable LABEL_ROOT, VIDEO_ROOT = detect_share_roots() OUT = ROOT / "outputs" MANIFEST = OUT / "dataset_manifest.json" NEW_TASKS = { "blocks_ranking_rgb", "dump_bin_bigbin", "handover_mic", "hanging_mug", "lift_pot", } def natural_key(value: str | Path) -> list[object]: stem = Path(value).name return [int(p) if p.isdigit() else p.lower() for p in re.split(r"(\d+)", stem)] def load_jobs() -> list[dict]: data = json.loads(MANIFEST.read_text(encoding="utf-8")) jobs = [] for entry in data["entries"]: if entry["task"] not in NEW_TASKS: continue kind_dir = Path(entry["label_dir"]).parent siblings = sorted(kind_dir.glob("validation-*-label"), key=natural_key) label_dir = Path(entry["label_dir"]) val_idx = siblings.index(label_dir) if label_dir in siblings else 0 probe_name = f"{entry['label_kind']}_val{val_idx}_960" jobs.append( { **entry, "validation_index": val_idx, "tag": f"{entry['task']}__{entry['demo']}__{entry['label_kind']}__val{val_idx}", "probe_dir": OUT / "probes" / entry["task"] / entry["demo"] / probe_name, } ) return jobs def run(cmd: list[str]) -> None: print("+", " ".join(cmd), flush=True) subprocess.run(cmd, check=True, cwd=str(ROOT)) def main() -> None: print(f"LABEL_ROOT={LABEL_ROOT}", flush=True) print(f"VIDEO_ROOT={VIDEO_ROOT}", flush=True) run( [ PY, "progress_probe.py", "scan-dataset", "--label-root", str(LABEL_ROOT), "--video-root", str(VIDEO_ROOT), "--output-json", str(MANIFEST), ] ) jobs = load_jobs() print(f"jobs={len(jobs)}", flush=True) for i, job in enumerate(jobs): print(f"\n===== [{i+1}/{len(jobs)}] {job['tag']} =====", flush=True) run( [ PY, "progress_probe.py", "fit-cv", "--task", job["task"], "--demo", job["demo"], "--label-kind", job["label_kind"], "--label-root", str(LABEL_ROOT), "--task-dir", job["label_dir"], "--validation-index", str(job["validation_index"]), "--allow-multiple-validation-dirs", "--output-dir", str(job["probe_dir"]), "--feature-start", "0", "--alpha", "0.0", "--seed", "42", ] ) print("done", flush=True) if __name__ == "__main__": main()