python OpenAI gym monitor creates json files in the recording directory

只愿长相守 提交于 2021-01-02 07:56:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!