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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With