From 097ca2ddf3c74c4ebba5c4186f88cee341ba858b Mon Sep 17 00:00:00 2001 From: Yamada Date: Fri, 7 Aug 2020 13:08:06 +0900 Subject: [PATCH 1/4] Ensure tf.Tensor for DDPG._get_action_body --- tf2rl/algos/ddpg.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tf2rl/algos/ddpg.py b/tf2rl/algos/ddpg.py index d3772d0..d48499b 100755 --- a/tf2rl/algos/ddpg.py +++ b/tf2rl/algos/ddpg.py @@ -97,7 +97,8 @@ def get_action(self, state, test=False, tensor=False): state = np.expand_dims(state, axis=0).astype( np.float32) if is_single_state else state action = self._get_action_body( - tf.constant(state), self.sigma * (1. - test), + tf.constant(state), + tf.constant(self.sigma * (1. - test), dtype=tf.float32), tf.constant(self.actor.max_action, dtype=tf.float32)) if tensor: return action From 023331cf85d3a8c0d14e3fe4000b31cb9e3962ae Mon Sep 17 00:00:00 2001 From: Yamada Date: Fri, 7 Aug 2020 13:18:33 +0900 Subject: [PATCH 2/4] Ensure tf.Tensor for VPG._get_action_body --- tf2rl/algos/vpg.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tf2rl/algos/vpg.py b/tf2rl/algos/vpg.py index bb3224d..4c31bc4 100644 --- a/tf2rl/algos/vpg.py +++ b/tf2rl/algos/vpg.py @@ -93,7 +93,8 @@ def get_action(self, state, test=False): is_single_input = state.ndim == self._state_ndim if is_single_input: state = np.expand_dims(state, axis=0).astype(np.float32) - action, logp, _ = self._get_action_body(state, test) + action, logp, _ = self._get_action_body(tf.constant(state, dtype=tf.float32), + tf.constant(test)) if is_single_input: return action.numpy()[0], logp.numpy() From 12e581d01eda7d6b850fedd6420a2a4305c968a7 Mon Sep 17 00:00:00 2001 From: Yamada Date: Fri, 7 Aug 2020 13:27:09 +0900 Subject: [PATCH 3/4] Ensure tf.Tensor SAC._get_action_body --- tf2rl/algos/sac.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf2rl/algos/sac.py b/tf2rl/algos/sac.py index f1ace1a..985c559 100644 --- a/tf2rl/algos/sac.py +++ b/tf2rl/algos/sac.py @@ -114,7 +114,7 @@ def get_action(self, state, test=False): state = np.expand_dims(state, axis=0).astype( np.float32) if is_single_state else state - action = self._get_action_body(tf.constant(state), test) + action = self._get_action_body(tf.constant(state), tf.constant(test)) return action.numpy()[0] if is_single_state else action From 1ba62f8b74122754e701b02205056b60029c8673 Mon Sep 17 00:00:00 2001 From: Yamada Date: Fri, 7 Aug 2020 20:32:18 +0900 Subject: [PATCH 4/4] Ensure tf.Tensor at DQN._train_body --- tf2rl/algos/dqn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tf2rl/algos/dqn.py b/tf2rl/algos/dqn.py index 6bdae9c..038169e 100644 --- a/tf2rl/algos/dqn.py +++ b/tf2rl/algos/dqn.py @@ -192,7 +192,8 @@ def train(self, states, actions, next_states, rewards, done, weights=None): if weights is None: weights = np.ones_like(rewards) td_errors, q_func_loss = self._train_body( - states, actions, next_states, rewards, done, weights) + tf.constant(states), tf.constant(actions), tf.constant(next_states), + tf.constant(rewards), tf.constant(done), tf.constant(weights)) tf.summary.scalar(name=self.policy_name + "/q_func_Loss", data=q_func_loss)