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

前端 未结 15 1944
囚心锁ツ
囚心锁ツ 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 11:02

    I managed to run and render openai/gym (even with mujoco) remotely on a headless server.

    # Install and configure X window with virtual screen
    sudo apt-get install xserver-xorg libglu1-mesa-dev freeglut3-dev mesa-common-dev libxmu-dev libxi-dev
    # Configure the nvidia-x
    sudo nvidia-xconfig -a --use-display-device=None --virtual=1280x1024
    # Run the virtual screen in the background (:0)
    sudo /usr/bin/X :0 &
    # We only need to setup the virtual screen once
    
    # Run the program with vitural screen
    DISPLAY=:0 
    
    # If you dont want to type `DISPLAY=:0` everytime
    export DISPLAY=:0
    

    Usage:

    DISPLAY=:0 ipython2
    

    Example:

    import gym
    env = gym.make('Ant-v1')
    arr = env.render(mode='rgb_array')
    print(arr.shape)
    # plot or save wherever you want
    # plt.imshow(arr) or scipy.misc.imsave('sample.png', arr)
    

提交回复
热议问题