RoboRACE-Bench / scripts /so101_score_views.py
Nabidnur's picture
sync scripts: RACE-Net-M, Track D baselines, RACE-Net-V v3
b2ead12 verified
Raw History Blame Contribute Delete
1.84 kB
#!/usr/bin/env python3
"""Score every SO-101 camera view with Cosmos-Reason2 (CPU). Resumable.
-> results/so101/vlm_scores.jsonl (one line per episode x camera; same schema as Track A)
"""
import json
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from PIL import Image # noqa: E402
from robotics.sim.so101_env import CAMERAS # noqa: E402
from robotics.vlm.cosmos_reason import CosmosVerifier # noqa: E402
ROBOT = sys.argv[1] if len(sys.argv) > 1 else "so101" # so101 | panda
if len(sys.argv) > 2: # e.g. "holdout" -> data/<robot>_holdout
ROBOT = f"{ROBOT}_{sys.argv[2]}"
def main():
out = f"results/{ROBOT}/vlm_scores.jsonl"
eps = [json.loads(line) for line in open(f"data/{ROBOT}/episodes.jsonl")]
Path(out).parent.mkdir(parents=True, exist_ok=True)
done = set()
if Path(out).exists():
done = {(json.loads(line)["scene"], json.loads(line)["camera"]) for line in open(out)}
v = CosmosVerifier()
with open(out, "a") as f:
for k, e in enumerate(eps):
for c in CAMERAS:
if (e["seed"], c) in done:
continue
t = time.perf_counter()
p = v.score(Image.open(f"data/{ROBOT}/{e['split']}/{e['seed']}/{c}.png").convert("RGB"), e["task"])
f.write(json.dumps({"seed": 100 if e["split"] == "hist" else 200, "scene": e["seed"], "camera": c,
"task": e["task"], "kind": e["mode"], "family": e["family"], "gt": e["success"],
"p": round(p, 5), "latency_s": round(time.perf_counter() - t, 3)}) + "\n")
f.flush()
print(f"{k + 1}/{len(eps)}", flush=True)
if __name__ == "__main__":
main()