How to save rollout video / render?

Hi everyone,

To save a video of a rollout when running rllib locally, I’ve added --video-dir outputs to the argument of rollout.py, so it goes into the if video_dir: condition of rollouts.py and creates a Monitor wrapper, and does call render() many times, but still it doesn’t save any videos in the dir outputs.

I’ve also tried to render things directly using the Procgen Wrapper env without using ray, but it still doesn’t render, and now I’m trying to render things directly with procgen, and I’m still not succeeding (cf. my comment on the procgen repo here)

What am I missing?

Thanks,

1 Like

Hello @mtrazzi

Can you share the procgen version that you are using?

Hi @jyotish,

I’m using procgen==0.10.1.

Note: it does save some files in outputs (like openaigym.episode_batch.0.27441.stats.json or openaigym.manifest.0.27441.manifest.json), just not videos.

Note2: I’ve upgraded the procgen version to 0.10.3 and it still doesn’t save any video when adding --video-dir outputs.

Hello @mtrazzi

For procgen==0.10.x, you need to pass render_mode="rgb_array" as a config option to the environment for the videos.

PS: Note that passing render_mode="rgb_array" will have a performance impact and is not recommended to be used during training.

1 Like

I also have the same issue. I tried env = gym.make(‘procgen:procgen-coinrun-v0’, render_mode=‘rgb_array’)
and wrap it with gym Monitor but still no video (it works with CartPole-v0 though). Anything I am missing?

Hello @xiaocheng_tang

Can you try the same with gym3==0.3.2 and procgen==0.10.3?

Hi @jyotish

Yes I am using gym3==0.3.2 and procgen==0.10.3

Hello @xiaocheng_tang

Do you see any warning that says something like render() returned None when you use the Monitor wrapper?

@jyotish With render_mode=‘rgb_array’ + correct version of procgen and gym3 render returns None.

@xiaocheng_tang We might need to use gym3’s VideoRecorderWrapper instead of a Monitor if we’re using gym3 environments, because when we passrender_mode=‘rgb_array’ it creates some vectorized observations (different from simple gym).

I’m still a bit uncertain about if we should use gym or gym3 in the rollouts.py file. Really seems like Monitor is for old gym environments.

EDIT: more infos in the same procgen issue.

Hello @mtrazzi @xiaocheng_tang

This example should work.

#!/usr/bin/env python

import gym
import gym.wrappers

env = gym.make("procgen:procgen-coinrun-v0", render_mode="rgb_array")
env.metadata["render.modes"] = ["human", "rgb_array"]
env = gym.wrappers.Monitor(env=env, directory="./videos", force=True)

episodes = 10
_ = env.reset()

done = False
while episodes > 0:
    _, _, done, _ = env.step(env.action_space.sample())
    if done:
        _ = env.reset()
        episodes -= 1

3 Likes

This example works, thanks!

Does it work properly for everyone else? When I run it for 100 episodes it only saves episodes number 0, 1, 8, 27, 64.

Hello @karolisram

Can you try passing the video_callable param?

Reference: https://github.com/openai/gym/blob/master/gym/wrappers/monitor.py#L54

That worked, thank you!