8

Is there a way to disable video rendering in OpenAI gym while still recording it?

When I use the atari environments and the Monitor wrapper, the default behavior is to not render the video (the video is still recorded and saved to disk). However in simple environments such as MountainCarContinuous-v0, CartPole-v0, Pendulum-v0, rendering the video is the default behavior and I cannot find how to disable it (I still want to save it to disk).

I am running my jobs on a server and the officially suggested workaround with xvfb does not work. I saw that a lot of people had problems with it as it clashes with nvidia drivers. The most common solution I found was to reinstall nvidia drivers, which I cannot do as I do not have root access over the server.

nbro
  • 15,395
  • 32
  • 113
  • 196
niko
  • 1,128
  • 1
  • 11
  • 25

2 Answers2

6

Yes you have video_callable=False kwarg in gym.wrappers.Monitor()

import gym

from gym import wrappers

env = gym.make(env_name) # env_name = "Pendulum-v0"

env = wrappers.Monitor(env, aigym_path, video_callable=False ,force=True)

then you wish to use

s = env.reset() # do this for initial time-step of each episode
s_next, reward, done = env.step(a) # do this for every time-step with action 'a'

to run your episodes

sdr2002
  • 542
  • 2
  • 6
  • 16
  • `NameError: name 'aigym_path' is not defined` – gvgramazio Jul 20 '18 at 12:35
  • 1
    aigym_path is a directory you wish to save the videos rendered UNLESS you set the 'video_callable' being False. Give it a string of directory sth like '/home//bla/bla/savedFilms' – sdr2002 Aug 12 '18 at 12:00
1

Call this function before calling env.render(), since rendering is not imported before your first render() call, and this function will replace the default viewer constructor.

def disable_view_window():
    from gym.envs.classic_control import rendering
    org_constructor = rendering.Viewer.__init__

    def constructor(self, *args, **kwargs):
        org_constructor(self, *args, **kwargs)
        self.window.set_visible(visible=False)

    rendering.Viewer.__init__ = constructor

IffI
  • 11
  • 5