Saving a Model in OPENAI Baselines

题意:在OPENAI Baselines中保存模型

问题背景:

Openai Baselines save the trained model with the following command,

OpenAI Baselines 使用以下命令保存训练好的模型:

python -m baselines.run --alg=ppo2 --env=PongNoFrameskip-v4 --num_timesteps=2e7 --save_path=~/models/pong_20M_ppo2

But the saved trained model is not in the form of,

但是保存的训练模型并不是以下形式:

.ckpt.meta
.ckpt.index
.ckpt.data
checkpoint

which it was in this form in the earlier versions. How can we save the model as .ckpt.meta, .ckpt.index, .ckpt.data and checkpoint format?

在早期版本中模型是以这种形式保存的。我们如何将模型保存为 .ckpt.meta、.ckpt.index、.ckpt.data 和检查点格式?

问题解决:

I've encountered the same problem and I've solved the problem by making a little adjustment to the baselines code.

“我遇到了同样的问题,并通过对 baselines 代码进行一些小调整解决了这个问题。”

There are two pairs of methods in baselines for saving and loading models(the save_state&load_state pair and the save_variables&loas_variables pair) and you can see it in baselines/common/tf_util.py(line325~line372).

在 baselines 中有两对用于保存和加载模型的方法(save_stateload_state 这一对,以及 save_variablesload_variables 这一对),你可以在 baselines/common/tf_util.py 文件的第 325 行到第 372 行看到这些方法。

For the latest version of baselines, the save_state&load_state pair which saves and loads models in the .ckpt.meta, .ckpt.index, .ckpt.data and checkpoint format has been abandoned, so you need to re-enable the save_state&load_state pair.

在最新版本的 baselines 中,save_stateload_state 这对用于以 .ckpt.meta、.ckpt.index、.ckpt.data 和检查点格式保存和加载模型的方法已被弃用,因此你需要重新启用 save_stateload_state 这对方法。

Take ppo2 for example, in baselines/ppo2/model.py, make the following replacement: in line 125, replace

“以 ppo2 为例,在 `baselines/ppo2/model.py` 文件中,进行以下替换:在第 125 行,将”

self.save = functools.partial(save_variables, sess=sess)
self.load = functools.partial(load_variables, sess=sess)

with  用以下语句替换

self.save = functools.partial(save_state, sess=sess)
self.load = functools.partial(load_state, sess=sess)

and in line 4, replace        将第4行的以下语句

from baselines.common.tf_util import get_session, save_variables, load_variables

with        用以下语句替换

from baselines.common.tf_util import get_session, save_state, load_state

this will replace the save_variables&loas_variables pair with the save_state&load_state pair.

“这将把 `save_variables` 和 `load_variables` 这对方法替换为 `save_state` 和 `load_state` 这对方法。”

hope this would help you.        希望对你有帮助.

  • 26
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要本地构建OpenAI开发环境,你需要按照以下步骤进行操作: 1. 安装Python环境:首先,你需要安装Python编程语言的环境。建议使用最新的Python版本,可以从官方网站(python.org)下载并按照指示进行安装。 2. 安装虚拟环境工具:在搭建开发环境时,建议使用虚拟环境来隔离不同项目的依赖。你可以选择安装虚拟环境工具,例如virtualenv或conda。这些工具可以帮助你创建和管理多个独立的Python环境。 3. 安装OpenAI库:接下来,你需要安装OpenAI库。OpenAI有几个不同的库,例如GymBaselines和Stable Baselines等。你可以使用pip命令安装这些库,例如pip install gym或pip install baselines。 4. 设置API密钥:如果你计划使用OpenAI的API进行开发,你需要注册OpenAI账户,并获得API密钥。将API密钥设置为环境变量,以便在你的代码中进行调用。 5. 安装其他依赖:除了OpenAI库外,你的项目可能还有其他依赖项。使用pip安装这些依赖项,以确保你的项目能够正常运行。 6. 编写代码:现在,你已经搭建了OpenAI的开发环境,可以开始编写代码了!根据你的需求,使用OpenAI库创建强化学习模型、训练智能体或测试算法等。 7. 运行代码:在完成代码编写后,你可以通过运行Python脚本启动你的项目。确保你的开发环境配置正确,并按照OpenAI库的文档进行使用。 总而言之,要本地构建OpenAI开发环境,你需要安装Python环境、虚拟环境工具、OpenAI库和其他依赖项,并在代码中设置API密钥。完成这些步骤后,你就可以使用OpenAI库进行强化学习项目的开发了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值