Gym: Monitor recording upon request

Created on 18 Feb 2017  路  2Comments  路  Source: openai/gym

Right now monitor video callable takes only a single parameter, which is episode count, but, in general, it makes more sense to record video during test periods only and not record it otherwise.
In general, it would make sense to have conditional recording and start/stop video recording when it is explicitly requested and don't record otherwise.

Hence the question. Is there a way to do it now, and if not, can we expect such feature in the nearest future.
Thank you in advance.

Most helpful comment

Sure, the video_callable function you provide can look at any variables it needs to make its decision. For instance, an agent could do something like this to record every 10th episode only in test mode:

class MyAgent:
    def __init__(self):
        env = gym.make(...)
        self.env = gym.wrappers.Monitor(env, '/tmp/mylog', video_callable=self.video_callable)
...
    def video_callable(self, episode_id):
        return episode_id%10 == 0 and self.test_mode

it could be a method of the agent and can look at self.test_mode or whatever.

All 2 comments

Sure, the video_callable function you provide can look at any variables it needs to make its decision. For instance, an agent could do something like this to record every 10th episode only in test mode:

class MyAgent:
    def __init__(self):
        env = gym.make(...)
        self.env = gym.wrappers.Monitor(env, '/tmp/mylog', video_callable=self.video_callable)
...
    def video_callable(self, episode_id):
        return episode_id%10 == 0 and self.test_mode

it could be a method of the agent and can look at self.test_mode or whatever.

Oh, I see. Somehow I thought they should only have access to local variables and provided id only.
Thanks a lot ! I believe it would make sense to add this answer to the tutorial page :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RuofanKong picture RuofanKong  路  3Comments

zhan0903 picture zhan0903  路  4Comments

pickittwice picture pickittwice  路  4Comments

RuofanKong picture RuofanKong  路  4Comments

RuofanKong picture RuofanKong  路  4Comments