2

Openai Baselines save the trained model with the following command,

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?

SD11
  • 21
  • 4

1 Answers1

1

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

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

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.

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

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

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.

hope this would help you.

hema-v0
  • 21
  • 2