Bug fix for discrete actions

This commit is contained in:
Antonin Raffin 2019-10-25 12:00:37 +02:00
parent f8bcb8ee16
commit 584f549fa1
2 changed files with 4 additions and 0 deletions

View file

@ -134,6 +134,7 @@ class RolloutBuffer(BaseBuffer):
if len(log_prob.shape) == 0:
# Reshape 0-d tensor to avoid error
log_prob = log_prob.reshape(-1, 1)
self.observations[self.pos] = th.FloatTensor(np.array(obs).copy())
self.actions[self.pos] = th.FloatTensor(np.array(action).copy())
self.rewards[self.pos] = th.FloatTensor(np.array(reward).copy())

View file

@ -158,6 +158,9 @@ class PPO(BaseRLModel):
self._update_info_buffer(infos)
n_steps += 1
if isinstance(self.action_space, gym.spaces.Discrete):
# Reshape in case of discrete action
actions = actions.reshape(-1, 1)
rollout_buffer.add(obs, actions, rewards, dones, values, log_probs)
obs = new_obs