题意:在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_state
和 load_state
这一对,以及 save_variables
和 load_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_state
和 load_state
这对用于以 .ckpt.meta、.ckpt.index、.ckpt.data 和检查点格式保存和加载模型的方法已被弃用,因此你需要重新启用 save_state
和 load_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. 希望对你有帮助.