R4R-Auto-Eval / scripts /session_visual_review.py
cobo2026's picture
Initial R4R Auto Eval progress release v0.1.0 (part 4)
0904fd2 verified
Raw History Blame Contribute Delete
2.91 kB
"""Prepare local visual evidence for a Codex session (no API, no labels)."""
import argparse
import json
import sys
from pathlib import Path
import cv2
import numpy as np
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
import benchmark_gpt6_astra as runner
ROOT = Path('gpt6-reassemble40/results/codex-session')
ROLES = ['main', 'wrist', 'external_2']
def main():
p = argparse.ArgumentParser()
p.add_argument('--case', type=int, action='append')
p.add_argument('--full', action='store_true', help='Sheets covering every baseline sample')
p.add_argument('--tail', action='store_true', help='Last three timepoints at native resolution')
args = p.parse_args()
dest = ROOT / 'evidence'
dest.mkdir(parents=True, exist_ok=True)
for number in args.case or range(31, 71):
cid = f'case_{number:03d}'
path = Path('gpt6-reassemble40/benchmark/cases') / cid
instruction, meta, videos = runner.load_case(path)
timestamps, _ = runner.choose_timestamps(meta, 3, 2, 1, 30, 900)
if args.tail:
selected = timestamps[-3:]
width, height, rows = 640, 480, 3
suffix = 'tail'
elif args.full:
selected = timestamps
width, height, rows = 320, 240, 8
suffix = 'full'
else:
selected = [timestamps[i] for i in sorted({round(i * (len(timestamps)-1)/7) for i in range(8)})]
width, height, rows = 320, 240, 8
suffix = 'overview'
captures = {r: cv2.VideoCapture(str(path / f'{r}.mp4')) for r in ROLES}
for page in range(0, len(selected), rows):
subset = selected[page:page+rows]
canvas = np.full((50 + (height+24)*len(subset), width*3, 3), 245, dtype=np.uint8)
cv2.putText(canvas, f'{cid}: {instruction}', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, .65, (0,0,0), 2)
for row,t in enumerate(subset):
for col,role in enumerate(ROLES):
stream = meta['videos'][role]
idx = min(int(stream['num_frames'])-1, round(t*stream['fps']))
cap=captures[role]
cap.set(cv2.CAP_PROP_POS_FRAMES, idx)
ok, frame = cap.read()
if not ok:
raise RuntimeError(f'{cid} {role} frame {idx}')
y=50+row*(height+24)
cv2.putText(canvas, f'{role} t={t:.3f}s', (col*width+5,y+17), cv2.FONT_HERSHEY_SIMPLEX,.5,(0,0,0),1)
canvas[y+24:y+24+height,col*width:(col+1)*width] = cv2.resize(frame,(width,height))
name=dest/f'{cid}_{suffix}_{page//rows:02d}.jpg'
assert cv2.imwrite(str(name), canvas, [cv2.IMWRITE_JPEG_QUALITY,95])
print(name, flush=True)
for cap in captures.values():
cap.release()
if __name__ == '__main__':
main()