模型:
sb3/demo-hf-CartPole-v1
这是一个使用 stable-baselines3 库训练的 PPO 代理在 CartPole-v1 上进行游戏的预训练模型。
当您安装了 stable-baselines3 和 huggingface_sb3 后,使用此模型变得很容易:
pip install stable-baselines3 pip install huggingface_sb3
然后,您可以像这样使用该模型:
import gym
from huggingface_sb3 import load_from_hub
from stable_baselines3 import PPO
from stable_baselines3.common.evaluation import evaluate_policy
# Retrieve the model from the hub
## repo_id = id of the model repository from the Hugging Face Hub (repo_id = {organization}/{repo_name})
## filename = name of the model zip file from the repository
checkpoint = load_from_hub(
repo_id="sb3/demo-hf-CartPole-v1",
filename="ppo-CartPole-v1",
)
model = PPO.load(checkpoint)
# Evaluate the agent and watch it
eval_env = gym.make("CartPole-v1")
mean_reward, std_reward = evaluate_policy(
model, eval_env, render=True, n_eval_episodes=5, deterministic=True, warn=False
)
print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
平均奖励:500.0