python OpenAI Gym Monitor在记录目录中创建json文件 [英] python OpenAI gym monitor creates json files in the recording directory

查看:72
本文介绍了python OpenAI Gym Monitor在记录目录中创建json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在健身房 CartPole-v0 环境上实现价值迭代,并希望将代理人行为的视频记录在视频文件中.我一直在尝试使用Monitor包装器实现此功能,但是它会在记录目录中生成json文件而不是视频文件.这是我的代码:

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))

监视json文件

我已经按照教程进行了操作,但是不知道出什么问题了.我在Google上搜索了很多,但是没有发现任何有用的东西.

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.

推荐答案

我上次检查时,效果很好:

Last time I checked, this was working fine:

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

这将记录所有情节的视频.您可以使用 episode_id 选择要记录的情节.

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

这篇关于python OpenAI Gym Monitor在记录目录中创建json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆