| import os |
| import json |
| import argparse |
| from VLABench.evaluation.evaluator import Evaluator |
| from VLABench.evaluation.model.policy.openvla import OpenVLA |
| from VLABench.evaluation.model.policy.base import RandomPolicy |
| from VLABench.tasks import * |
| from VLABench.robots import * |
|
|
| os.environ["MUJOCO_GL"]= "egl" |
|
|
| def get_args(): |
| parser = argparse.ArgumentParser() |
| parser.add_argument('--tasks', nargs='+', default=None, help="Specific tasks to run, work when eval-track is None") |
| parser.add_argument( |
| '--eval-track', |
| default=None, |
| type=str, |
| choices=[ |
| "track_1_in_distribution", |
| "track_sem_all_safe1", |
| "track_sem_all_safe2", |
| "track_sem_all_unsafe", |
| "custom", |
| ], |
| help="The evaluation track to run" |
| ) |
| parser.add_argument('--n-episode', default=1, type=int, help="The number of episodes to evaluate for a task") |
| parser.add_argument('--policy', default="openvla", help="The policy to evaluate") |
| parser.add_argument('--model_ckpt', default="/remote-home1/sdzhang/huggingface/openvla-7b", help="The base model checkpoint path") |
| parser.add_argument('--lora_ckpt', default="/remote-home1/pjliu/openvla/weights/vlabench/select_fruit+CSv1+lora/", help="The lora checkpoint path") |
| parser.add_argument('--save-dir', default="logs", help="The directory to save the evaluation results") |
| parser.add_argument('--visulization', action="store_true", default=False, help="Whether to visualize the episodes") |
| parser.add_argument('--metrics', nargs='+', default=["success_rate"], choices=["success_rate", "intention_score", "progress_score"], help="The metrics to evaluate") |
| parser.add_argument('--host', default="localhost", type=str, help="The host to the remote server") |
| parser.add_argument('--port', default=5555, type=int, help="The port to the remote server") |
| parser.add_argument('--replanstep', default=5, type=int, help="The step to replan") |
| parser.add_argument('--seed-base', default=42, type=int, help="Base seed for episode sampling (seed + episode_id)") |
| |
| parser.add_argument('--vla_ckpt', default=None, type=str, help="Path to VLA-Adapter checkpoint directory") |
| parser.add_argument('--vla_num_images', default=2, type=int, help="Number of images used as input (1 or 2)") |
| parser.add_argument('--vla_no_proprio', action="store_true", help="Disable proprio input for VLA-Adapter") |
| parser.add_argument('--vla_open_loop_steps', default=1, type=int, help="Number of open-loop steps (first executed)") |
| parser.add_argument('--vla_skip_center_crop', action="store_true", help="Skip center crop") |
| parser.add_argument('--vla_use_minivlm', action="store_true", help="Use mini VLM prompting") |
| parser.add_argument('--vla_use_film', action="store_true", help="Enable FiLM in VLA-Adapter vision backbone") |
| parser.add_argument('--vla_no_pro_version', action="store_true", help="Disable Pro version head logic") |
| parser.add_argument('--vla_camera_index', default=None, type=int, help="Optional camera index override") |
| parser.add_argument('--vla_wrist_index', default=None, type=int, help="Optional wrist camera index override") |
| parser.add_argument('--action_absolute', action="store_true", help="Treat model outputs as absolute target pose") |
| |
| parser.add_argument('--nora_camera_index', default=None, type=int, help="Optional camera index override for Nora") |
| parser.add_argument('--nora_time_horizon', default=1, type=int, help="Nora action time horizon used by tokenizer") |
| args = parser.parse_args() |
| return args |
|
|
| def evaluate(args): |
| episode_config = None |
| if args.eval_track is not None: |
| args.save_dir = os.path.join(args.save_dir, args.eval_track) |
| with open(os.path.join(os.getenv("VLABENCH_ROOT"), "configs/evaluation/tracks", f"{args.eval_track}.json"), "r") as f: |
| episode_config = json.load(f) |
| tasks = list(episode_config.keys()) |
| if args.tasks is not None: |
| tasks = args.tasks |
| assert isinstance(tasks, list) |
|
|
| evaluator = Evaluator( |
| tasks=tasks, |
| n_episodes=args.n_episode, |
| episode_config=episode_config, |
| max_substeps=1, |
| save_dir=args.save_dir, |
| visulization=args.visulization, |
| metrics=args.metrics, |
| seed_base=args.seed_base |
| ) |
| if args.policy.lower() == "openvla": |
| policy = OpenVLA( |
| model_ckpt=args.model_ckpt, |
| lora_ckpt=args.lora_ckpt, |
| debug_actions=True, |
| norm_config_file=os.path.join(os.getenv("VLABENCH_ROOT"), "configs/model/openvla_config.json"), |
| action_is_absolute=args.action_absolute |
|
|
| ) |
| elif args.policy.lower() == "nora": |
| from VLABench.evaluation.model.policy.nora import NoraPolicy |
|
|
| policy = NoraPolicy( |
| model_ckpt=args.model_ckpt, |
| device="cuda", |
| camera_index=args.nora_camera_index if args.nora_camera_index is not None else 2, |
| action_mode="absolute" if args.action_absolute else "delta", |
| replan_steps=args.replanstep, |
| time_horizon=max(1, args.nora_time_horizon), |
| ) |
| elif args.policy.lower() == "vla_adapter": |
| from VLABench.evaluation.model.policy.vla_adapter import VLAAdapterPolicy |
|
|
| if args.vla_ckpt is None: |
| raise ValueError("Please provide --vla_ckpt for VLA-Adapter policy") |
|
|
| policy = VLAAdapterPolicy( |
| checkpoint_path=args.vla_ckpt, |
| task_unnorm_key=args.unnorm_key if hasattr(args, "unnorm_key") else "primitive", |
| num_images_in_input=args.vla_num_images, |
| use_proprio=not args.vla_no_proprio, |
| use_film=args.vla_use_film, |
| num_open_loop_steps=args.vla_open_loop_steps, |
| center_crop=not args.vla_skip_center_crop, |
| use_minivlm=args.vla_use_minivlm, |
| use_pro_version=not args.vla_no_pro_version, |
| device="cuda", |
| camera_index=args.vla_camera_index, |
| wrist_index=args.vla_wrist_index, |
| action_is_absolute=args.action_absolute, |
| ) |
| elif args.policy.lower() == "gr00t": |
| from VLABench.evaluation.model.policy.gr00t import Gr00tPolicy |
| policy = Gr00tPolicy(host=args.host, port=args.port, replan_steps=args.replanstep) |
| elif args.policy.lower() == "openpi": |
| from VLABench.evaluation.model.policy.openpi import OpenPiPolicy |
| policy = OpenPiPolicy(host=args.host, port=args.port, replan_steps=args.replanstep) |
| else: |
| policy = RandomPolicy(None) |
|
|
| result = evaluator.evaluate(policy) |
| track = args.eval_track or "custom" |
| os.makedirs(os.path.join(args.save_dir, args.policy, track), exist_ok=True) |
| with open(os.path.join(args.save_dir, args.policy, track, "evaluation_result.json"), "w") as f: |
| json.dump(result, f) |
|
|
| if __name__ == "__main__": |
| args = get_args() |
| evaluate(args) |
|
|