lerobot/examples/2_evaluate_pretrained_polic...

39 lines
1.2 KiB
Python
Raw Normal View History

2024-03-27 00:13:40 +08:00
"""
This scripts demonstrates how to evaluate a pretrained policy from the HuggingFace Hub or from your local
training outputs directory. In the latter case, you might want to run examples/3_train_policy.py first.
"""
from pathlib import Path
from huggingface_hub import snapshot_download
2024-04-18 20:47:42 +08:00
from lerobot.common.utils.utils import init_hydra_config
2024-03-27 00:13:40 +08:00
from lerobot.scripts.eval import eval
# Get a pretrained policy from the hub.
2024-04-16 20:43:58 +08:00
# TODO(alexander-soare): This no longer works until we upload a new model that uses the current configs.
2024-03-27 00:13:40 +08:00
hub_id = "lerobot/diffusion_policy_pusht_image"
folder = Path(snapshot_download(hub_id))
# OR uncomment the following to evaluate a policy from the local outputs/train folder.
2024-03-27 00:28:16 +08:00
# folder = Path("outputs/train/example_pusht_diffusion")
2024-03-27 00:13:40 +08:00
config_path = folder / "config.yaml"
weights_path = folder / "model.pt"
# Override some config parameters to do with evaluation.
overrides = [
f"policy.pretrained_model_path={weights_path}",
2024-04-30 23:08:59 +08:00
"eval.n_episodes=10",
"eval.batch_size=10",
2024-03-27 00:13:40 +08:00
"device=cuda",
]
# Create a Hydra config.
cfg = init_hydra_config(config_path, overrides)
# Evaluate the policy and save the outputs including metrics and videos.
eval(
cfg,
out_dir=f"outputs/eval/example_{cfg.env.name}_{cfg.policy.name}",
)