How to run OpenAI Gym .render() over a server

前端 未结 15 2160
囚心锁ツ
囚心锁ツ 2020-12-12 10:07

I am running a python 2.7 script on a p2.xlarge AWS server through Jupyter (Ubuntu 14.04). I would like to be able to render my simulations.

Minimal working example<

15条回答
  •  温柔的废话
    2020-12-12 10:51

    Got a simple solution working:

    CartPole

    If on a linux server, open jupyter with
    $ xvfb-run -s "-screen 0 1400x900x24" jupyter notebook
    
    In Jupyter
    import matplotlib.pyplot as plt
    %matplotlib inline
    from IPython import display
    
    After each step
    def show_state(env, step=0, info=""):
        plt.figure(3)
        plt.clf()
        plt.imshow(env.render(mode='rgb_array'))
        plt.title("%s | Step: %d %s" % (env._spec.id,step, info))
        plt.axis('off')
    
        display.clear_output(wait=True)
        display.display(plt.gcf())
    

    Note: if your environment is not unwrapped, pass env.env to show_state.

提交回复
热议问题