Created
November 8, 2017 16:58
-
-
Save andrewliao11/cacb6237d2725be1c62e8d12701042a5 to your computer and use it in GitHub Desktop.
Since the structure of each algorithms in baselines is different, we implementation the sample/load function in different ways.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code locate in baselines/gail | |
def sample(algo, load_model_path, policy_fn): | |
assert algo in ['trpo', 'ppo', 'acktr', 'ddpg', 'a2c'] | |
if algo in ['trpo', 'ppo']: | |
with tf.Session() as sess: | |
# manually build graph | |
policy = policy_fn() | |
# load model | |
U.load_state(load_model_path) | |
elif algo in ['acktr', 'ddpg', 'a2c']: | |
policy = Model(policy_fn) # sess/graph declare inside | |
policy.load(load_model_path) | |
# sample expert | |
Sampler(algo, policy, sample_steps) | |
def Sampler(algo, policy, sample_steps): | |
# start sampling code | |
for _ in range(sample_steps): | |
if algo == 'ddpg': | |
actions, q = act(obs) | |
elif algo == 'a2c' or 'acktr': | |
actions, values, policy.states = policy.step(obs, policy.states, dones) | |
elif algo == 'ppo' or 'trpo: | |
actions, v = policy.act(stochastic, obs) | |
obs, rw, dones, _ = env.step(act) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about this?
Since the code in
ppo
,trpo
use act() like this