问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/52636899/python-openai-gym-monitor-creates-json-files-in-the-recording-directory