File size: 1,927 Bytes
99e41a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/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()