mirror of
https://github.com/saymrwulf/stable-baselines3.git
synced 2026-07-30 20:18:15 +00:00
Bug fix actor forward
This commit is contained in:
parent
525fe43552
commit
149148d4c7
2 changed files with 8 additions and 4 deletions
|
|
@ -55,13 +55,17 @@ class PPOPolicy(BasePolicy):
|
|||
value = self.value_net(latent)
|
||||
return action, value, log_prob
|
||||
|
||||
def actor_forward(self, state):
|
||||
def actor_forward(self, state, deterministic=False):
|
||||
latent = self.shared_net(state)
|
||||
# TODO: initialize pi_mean weights properly
|
||||
mean_actions = self.actor_net(latent)
|
||||
action_distribution = Normal(mean_actions, self.log_std)
|
||||
action_std = th.ones(mean_actions.size()) * self.log_std.exp()
|
||||
action_distribution = Normal(mean_actions, action_std)
|
||||
# Sample from the gaussian
|
||||
action = action_distribution.rsample()
|
||||
if deterministic:
|
||||
action = mean_actions
|
||||
else:
|
||||
action = action_distribution.rsample()
|
||||
return action
|
||||
|
||||
def get_policy_stats(self, state, action):
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class PPO(BaseRLModel):
|
|||
observation = np.array(observation)
|
||||
with th.no_grad():
|
||||
observation = th.FloatTensor(observation.reshape(1, -1)).to(self.device)
|
||||
return self.policy.actor_forward(observation).cpu().data.numpy().flatten()
|
||||
return self.policy.actor_forward(observation, deterministic=False).cpu().data.numpy().flatten()
|
||||
|
||||
def predict(self, observation, state=None, mask=None, deterministic=True):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue