Skip to content

Instantly share code, notes, and snippets.

@araffin
Last active April 10, 2020 19:13
Show Gist options
  • Save araffin/0154f13e24d68fee0ddfd63a7979a909 to your computer and use it in GitHub Desktop.
Save araffin/0154f13e24d68fee0ddfd63a7979a909 to your computer and use it in GitHub Desktop.
Getting Started With Stable Baselines
# 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