| import numpy as np |
| import tensorflow_datasets as tfds |
| from VLABench.evaluation.model.policy.openvla import OpenVLA |
|
|
| |
| rlds_path = "/home/zhao.bai/ArenaVlaSafety/rlds_out_backup/rlds_out/sem_pour_water_electronics/1.0.0" |
| |
| model_ckpt = "/home/zhao.bai/arena/openvla-oft/runs/arena_single/sem_pour_water_electronics_rlds/openvla-7b-oft-finetuned-10000_chkpt" |
| lora_ckpt = model_ckpt + "/lora_adapter" |
| norm_cfg = "/tmp/zhao.bai/work/repo/VLABench/VLABench/configs/model/openvla_config.json" |
| unnorm_key = "sem_pour_water_electronics_delta" |
|
|
| |
| ds = tfds.builder_from_directory(rlds_path).as_dataset(split="train") |
|
|
| policy = OpenVLA( |
| model_ckpt=model_ckpt, |
| lora_ckpt=lora_ckpt, |
| norm_config_file=norm_cfg, |
| debug_actions=True, |
| device="cuda:0", |
| ) |
|
|
| max_episodes = 5 |
| sample_print = 10 |
|
|
| total_l2, total_l1, total_count = 0.0, 0.0, 0 |
| printed = 0 |
|
|
| for ex_id, ex in enumerate(tfds.as_numpy(ds.take(max_episodes))): |
| for step in ex["steps"]: |
| rgb = np.stack( |
| [step["observation"][k] for k in ("image_0", "image_1", "front", "wrist")], |
| axis=0, |
| ) |
| obs = { |
| "rgb": rgb, |
| |
| "ee_state": step["observation"]["ee_state"].astype(np.float32), |
| "instruction": step["language_instruction"].decode(), |
| } |
| |
| inputs = policy.process_observation(obs, unnorm_key=unnorm_key) |
| pred = np.array(policy.model.predict_action(**inputs, unnorm_key=unnorm_key, do_sample=False)) |
| gt = np.array(step["action"], dtype=np.float32) |
|
|
| |
| diff = pred[:6] - gt[:6] |
| total_l2 += np.linalg.norm(diff) |
| total_l1 += np.abs(diff).sum() |
| total_count += 1 |
|
|
| if printed < sample_print: |
| print(f"[sample {printed}] instr='{obs['instruction']}'") |
| print(f" pred: {np.round(pred, 6)}") |
| print(f" gt : {np.round(gt, 6)}") |
| print(f" diff(0:6): {np.round(diff, 6)} (l2={np.linalg.norm(diff):.6f})") |
| print(f" gripper pred={pred[-1]:.3f}, gt={gt[-1]:.3f}") |
| printed += 1 |
|
|
| mean_l2 = total_l2 / max(1, total_count) |
| mean_l1 = total_l1 / max(1, total_count) |
| print(f"\nCompared {total_count} steps across {max_episodes} episodes.") |
| print(f"Mean L2 diff per step: {mean_l2:.6f}") |
| print(f"Mean L1 diff per step: {mean_l1:.6f}") |
|
|