Skip to content

Instantly share code, notes, and snippets.

@araffin
Last active August 18, 2018 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save araffin/9a5be160b42a24bfd3e33ba9621b5e7c to your computer and use it in GitHub Desktop.
Save araffin/9a5be160b42a24bfd3e33ba9621b5e7c to your computer and use it in GitHub Desktop.
import imageio
import numpy as np
from stable_baselines.common.policies import MlpPolicy
from stable_baselines import A2C
model = A2C(MlpPolicy, "LunarLander-v2").learn(100000)
images = []
obs = model.env.reset()
img = model.env.render(mode='rgb_array')
for i in range(350):
images.append(img)
action, _ = model.predict(obs)
obs, _, _ ,_ = model.env.step(action)
img = model.env.render(mode='rgb_array')
imageio.mimsave('lander_a2c.gif', [np.array(img[0]) for i, img in enumerate(images) if i%2 == 0], fps=29)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment