OpenAI Gym 库使用小技巧
Published:
OpenAI Gym 库使用小技巧。
gym 库渲染显示
1、使用虚拟帧缓冲区打开 notebook
xvfb-run -s "-screen 0 1400x900x24" jupyter notebook
2、实现在 notebook 中显示 gym 库的渲染显示
import matplotlib.pyplot as plt
%matplotlib inline
from IPython import display
def show_state(env, step=0, info=""):
plt.figure(1)
plt.clf()
plt.imshow(env.render(mode='rgb_array'))
plt.title("Step: %d %s" % (step, info))
plt.axis('off')
display.display(plt.gcf())
display.clear_output(wait=True)
gym 库列出所有环境
# copy from https://github.com/openai/gym/blob/master/gym/envs/__init__.py
from gym import envs
envids = [spec.id for spec in envs.registry.all()]
for envid in sorted(envids):
print(envid)
使用某个环境
import gym
env = gym.make('CartPole-v0')