Views
No views yet
pip install stable-baselines3
pip install huggingface_sb31import gym
2
3from huggingface_sb3 import load_from_hub
4from stable_baselines3 import PPO
5from stable_baselines3.common.evaluation import evaluate_policy
6
7# Retrieve the model from the hub
8## repo_id = id of the model repository from the Hugging Face Hub (repo_id = {organization}/{repo_name})
9## filename = name of the model zip file from the repository
10checkpoint = load_from_hub(repo_id="TrabajoAprendizajeProfundo/Trabajo", filename="Asteroids-v0.zip")
11model = PPO.load(checkpoint)
12
13# Evaluate the agent
14eval_env = gym.make('Asteroids-v0')
15mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes=10, deterministic=True)
16print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
17
18# Watch the agent play
19directory = './video'
20env = Recorder(env, directory)
21
22obs = env.reset()
23done = False
24while not done:
25 action, _state = model2.predict(obs)
26 obs, reward, done, info = env.step(action)
27
28env.play()