DQN Agent playing LunarLander-v2
This is a trained model of a DQN agent playing LunarLander-v2 using the stable-baselines3 library.
Usage (with Stable-Baselines3)
from huggingface_sb3 import load_from_hub<br /> from stable_baselines3 import DQN<br /> from stable_baselines3.common.env_util import make_vec_env<br /> from stable_baselines3.common.evaluation import evaluate_policy<br /> # Download checkpoint<br /> checkpoint = load_from_hub("araffin/dqn-LunarLander-v2", "dqn-LunarLander-v2.zip")<br /> # Remove warning<br /> kwargs = dict(target_update_interval=30)<br /> # Load the model<br /> model = DQN.load(checkpoint, **kwargs)<br /> env = make_vec_env("LunarLander-v2", n_envs=1)<br /> # Evaluate<br /> print("Evaluating model")<br /> mean_reward, std_reward = evaluate_policy(<br /> model,<br /> env,<br /> n_eval_episodes=20,<br /> deterministic=True,<br /> )<br /> print(f"Mean reward = {mean_reward:.2f} +/- {std_reward:.2f}")<br /> # Start a new episode<br /> obs = env.reset()<br /> try:<br /> while True:<br /> action, _states = model.predict(obs, deterministic=True)<br /> obs, rewards, dones, info = env.step(action)<br /> env.render()<br /> except KeyboardInterrupt:<br /> pass<br />
Training Code (with Stable-baselines3)
from stable_baselines3 import DQN<br /> from stable_baselines3.common.env_util import make_vec_env<br /> from stable_baselines3.common.callbacks import EvalCallback<br /> # Create the environment<br /> env_id = "LunarLander-v2"<br /> n_envs = 8<br /> env = make_vec_env(env_id, n_envs=n_envs)<br /> # Create the evaluation envs<br /> eval_envs = make_vec_env(env_id, n_envs=5)<br /> # Adjust evaluation interval depending on the number of envs<br /> eval_freq = int(1e5)<br /> eval_freq = max(eval_freq // n_envs, 1)<br /> # Create evaluation callback to save best model<br /> # and monitor agent performance<br /> eval_callback = EvalCallback(<br /> eval_envs,<br /> best_model_save_path="./logs/",<br /> eval_freq=eval_freq,<br /> n_eval_episodes=10,<br /> )<br /> # Instantiate the agent<br /> # Hyperparameters from https://github.com/DLR-RM/rl-baselines3-zoo<br /> model = DQN(<br /> "MlpPolicy",<br /> env,<br /> learning_starts=0,<br /> batch_size=128,<br /> buffer_size=100000,<br /> learning_rate=7e-4,<br /> target_update_interval=250,<br /> train_freq=1,<br /> gradient_steps=4,<br /> # Explore for 40_000 timesteps<br /> exploration_fraction=0.08,<br /> exploration_final_eps=0.05,<br /> policy_kwargs=dict(net_arch=[256, 256]),<br /> verbose=1,<br /> )<br /> # Train the agent (you can kill it before using ctrl+c)<br /> try:<br /> model.learn(total_timesteps=int(5e5), callback=eval_callback)<br /> except KeyboardInterrupt:<br /> pass<br /> # Load best model<br /> model = DQN.load("logs/best_model.zip")<br />
收录说明:
1、本网页并非 araffin/dqn-LunarLander-v2 官网网址页面,此页面内容编录于互联网,只作展示之用;2、如果有与 araffin/dqn-LunarLander-v2 相关业务事宜,请访问其网站并获取联系方式;3、本站与 araffin/dqn-LunarLander-v2 无任何关系,对于 araffin/dqn-LunarLander-v2 网站中的信息,请用户谨慎辨识其真伪。4、本站收录 araffin/dqn-LunarLander-v2 时,此站内容访问正常,如遇跳转非法网站,有可能此网站被非法入侵或者已更换新网址,导致旧网址被非法使用,5、如果你是网站站长或者负责人,不想被收录请邮件删除:i-hu#Foxmail.com (#换@)
前往AI网址导航
2、本站所有文章、图片、资源等如果未标明原创,均为收集自互联网公开资源;分享的图片、资源、视频等,出镜模特均为成年女性正常写真内容,版权归原作者所有,仅作为个人学习、研究以及欣赏!如有涉及下载请24小时内删除;
3、如果您发现本站上有侵犯您的权益的作品,请与我们取得联系,我们会及时修改、删除并致以最深的歉意。邮箱: i-hu#(#换@)foxmail.com