Last active
April 10, 2020 19:13
-
-
Save araffin/0154f13e24d68fee0ddfd63a7979a909 to your computer and use it in GitHub Desktop.
Getting Started With Stable Baselines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://github.com/hill-a/stable-baselines | |
import gym | |
from stable_baselines.common.policies import MlpPolicy | |
from stable_baselines import PPO2 | |
env = gym.make('CartPole-v1') | |
model = PPO2(MlpPolicy, env, verbose=1) | |
# Train the agent | |
model.learn(total_timesteps=10000) | |
# Enjoy trained agent | |
obs = env.reset() | |
for i in range(1000): | |
action, _states = model.predict(obs, deterministic=False) | |
obs, reward, done, info = env.step(action) | |
env.render() | |
if done: | |
obs = env.reset() | |
env.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment