used in collect_rollouts(), do not clamp actions
(self, obs_dict: Dict[str, np.ndarray], deterministic: bool = False, clip_action: bool = False, only_feature: bool = False, feature_input: np.ndarray = None)
| 140 | return values.flatten(), distribution.distribution |
| 141 | |
| 142 | def forward(self, obs_dict: Dict[str, np.ndarray], deterministic: bool = False, clip_action: bool = False, only_feature: bool = False, feature_input: np.ndarray = None): |
| 143 | ''' |
| 144 | used in collect_rollouts(), do not clamp actions |
| 145 | ''' |
| 146 | with th.no_grad(): |
| 147 | if feature_input is None: |
| 148 | obs_tensor_dict = dict([(k, th.as_tensor(v).to(self.device).unsqueeze(0)) for k, v in obs_dict.items()]) |
| 149 | features = self._get_features(**obs_tensor_dict) |
| 150 | else: |
| 151 | features = th.tensor(feature_input).to(self.device) |
| 152 | if only_feature: |
| 153 | return features.cpu().numpy() |
| 154 | values = self.value_head(features) |
| 155 | distribution, mu, sigma = self._get_action_dist_from_features(features) |
| 156 | actions = distribution.get_actions(deterministic=deterministic) |
| 157 | log_prob = distribution.log_prob(actions) |
| 158 | actions = actions.cpu().numpy() |
| 159 | actions = self.unscale_action(actions) |
| 160 | if clip_action: |
| 161 | actions = np.clip(actions, self.action_space.low, self.action_space.high) |
| 162 | values = values.cpu().numpy().flatten() |
| 163 | log_prob = log_prob.cpu().numpy() |
| 164 | features = features.cpu().numpy() |
| 165 | return actions, values, log_prob, mu, sigma, features |
| 166 | |
| 167 | def forward_value(self, obs_dict: Dict[str, np.ndarray]) -> np.ndarray: |
| 168 | with th.no_grad(): |
nothing calls this directly
no test coverage detected