Views
No views yet
1import gymnasium as gym
2from stable_baselines3 import DQN
3from stable_baselines3.common.env_util import make_vec_env
4
5# Load the trained model
6model = DQN.load("best-model.zip")
7
8# Create the environment
9env = make_vec_env("LunarLander-v3", n_envs=1)
10
11# Reset the environment
12obs, info = env.reset()
13
14# Enjoy the trained agent
15for _ in range(1000):
16 action, _states = model.predict(obs, deterministic=True)
17 obs, rewards, terminated, truncated, info = env.step(action)
18 if terminated or truncated:
19 obs, info = env.reset()
20 env.render()
21env.close()pip install huggingface_hub1from huggingface_hub import hf_hub_download
2import torch as th
3import gymnasium as gym
4from stable_baselines3 import DQN
5
6# Download the model from the Hub
7model_path = hf_hub_download(repo_id="kuds/lunar-lander-dqn", filename="best-model.zip")
8
9# Load the model
10model = DQN.load(model_path)
11
12# Create the environment
13env = make_vec_env("LunarLander-v3", n_envs=1)
14
15# Enjoy the trained agent
16obs = env.reset()
17for i in range(1000):
18 action, _states = model.predict(obs, deterministic=True)
19 obs, rewards, dones, info = env.step(action)
20 env.render("human")