7

I am implementing value iteration on the gym CartPole-v0 environment and would like to record the video of the agent's actions in a video file. I have been trying to implement this using the Monitor wrapper but it generates json files instead of a video file in the recording directory. This is my code:

env = gym.make('FrozenLake-v0')
env = gym.wrappers.Monitor(env, 'recording', force=True)
env.seed(0)
optimalValue = valueIteration(env)
st = time.time()
policy = cal_policy(optimalValue)
policy_score = evaluate_policy(env, policy)
et = time.time()
env.close()
print('Best score: %.2f  Time: %4.4f sec' % (policy_score, et-st))

monitoring json files

I have followed this tutorial but not sure what is wrong. I have Googled a lot but haven't come across anything that could be useful.

user
  • 1,220
  • 1
  • 12
  • 31
AKuro
  • 79
  • 2
  • 8

1 Answers1

8

Last time I checked, this was working fine:

env = gym.wrappers.Monitor(env, "./vid", video_callable=lambda episode_id: True,force=True)

This will record the video for all the episodes. You can use episode_id to choose which episode to record.

Tejas
  • 520
  • 4
  • 15
  • Good answer, From the doc: `video_callable (Optional[function, False]): function that takes in the index of the episode and outputs a boolean, indicating whether we should record a video on this episode. The default (for video_callable is None) is to take perfect cubes, capped at 1000. False disables video recording.` So you need to define `video_callable` because it is False by default. – Neabfi Jan 31 '19 at 19:18