RoboRACE-Bench / scripts /trackA_score_views.py
Nabidnur's picture
RoboRACE: code, cached agent outputs, results, media, SO-101 renders (part 5)
99e41a8 verified
Raw History Blame Contribute Delete
1.93 kB
#!/usr/bin/env python3
"""Track A, stage 1: score every camera view of every scene with Cosmos-Reason2 (CPU ok).
Writes one JSON line per (scene, camera) to results/trackA/vlm_scores.jsonl and resumes
from it, so the expensive VLM pass runs once; all fusion/attack experiments reuse it.
"""
import argparse
import json
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from robotics.sim.tabletop import CAMERAS, make_suite # noqa: E402
from robotics.vlm.cosmos_reason import CosmosVerifier # noqa: E402
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--n", type=int, default=50)
ap.add_argument("--seeds", type=int, nargs="+", default=[100, 200])
ap.add_argument("--out", default="results/trackA/vlm_scores.jsonl")
a = ap.parse_args()
out = Path(a.out)
out.parent.mkdir(parents=True, exist_ok=True)
done = set()
if out.exists():
for line in out.read_text().splitlines():
r = json.loads(line)
done.add((r["seed"], r["scene"], r["camera"]))
v = CosmosVerifier()
with out.open("a") as f:
for seed in a.seeds:
suite = make_suite(a.n, seed=seed, cameras=CAMERAS)
for i, s in enumerate(suite):
for cam in CAMERAS:
if (seed, i, cam) in done:
continue
t = time.perf_counter()
p = v.score(s.views[cam], s.task)
f.write(json.dumps({"seed": seed, "scene": i, "camera": cam, "task": s.task,
"kind": s.kind, "gt": s.success, "p": round(p, 5),
"latency_s": round(time.perf_counter() - t, 3)}) + "\n")
f.flush()
print(f"seed {seed} scene {i + 1}/{len(suite)}", flush=True)
if __name__ == "__main__":
main()