浏览代码

remove action spec attribute from policy

/develop/actionmodel-csharp
Andrew Cohen 4 年前
当前提交
7ba10239
共有 4 个文件被更改,包括 6 次插入7 次删除
  1. 1
      ml-agents/mlagents/trainers/policy/policy.py
  2. 2
      ml-agents/mlagents/trainers/policy/tf_policy.py
  3. 2
      ml-agents/mlagents/trainers/policy/torch_policy.py
  4. 8
      ml-agents/mlagents/trainers/torch/components/bc/module.py

1
ml-agents/mlagents/trainers/policy/policy.py


condition_sigma_on_obs: bool = True,
):
self.behavior_spec = behavior_spec
self.action_spec = behavior_spec.action_spec
self.trainer_settings = trainer_settings
self.network_settings: NetworkSettings = trainer_settings.network_settings
self.seed = seed

2
ml-agents/mlagents/trainers/policy/tf_policy.py


reparameterize,
condition_sigma_on_obs,
)
if self.action_spec.continuous_size > 0 and self.action_spec.discrete_size > 0:
if self.behavior_spec.action_spec.continuous_size > 0 and self.behavior_spec.action_spec.discrete_size > 0:
raise UnityPolicyException(
"TensorFlow does not support mixed action spaces. Please run with the Torch framework."
)

2
ml-agents/mlagents/trainers/policy/torch_policy.py


) -> Tuple[SplitObservations, np.ndarray]:
vec_vis_obs = SplitObservations.from_observations(decision_requests.obs)
mask = None
if self.action_spec.discrete_size > 0:
if self.behavior_spec.action_spec.discrete_size > 0:
mask = torch.ones([len(decision_requests), np.sum(self.act_size)])
if decision_requests.action_mask is not None:
mask = torch.as_tensor(

8
ml-agents/mlagents/trainers/torch/components/bc/module.py


expert_actions: torch.Tensor,
) -> torch.Tensor:
bc_loss = 0
if self.policy.action_spec.continuous_size > 0:
if self.policy.behavior_spec.action_spec.continuous_size > 0:
if self.policy.action_spec.discrete_size > 0:
if self.policy.behavior_spec.action_spec.discrete_size > 0:
self.policy.action_spec.discrete_branches,
self.policy.behavior_spec.action_spec.discrete_branches,
)
log_prob_branches = ModelUtils.break_into_branches(

vec_obs = [ModelUtils.list_to_tensor(mini_batch_demo["vector_obs"])]
act_masks = None
expert_actions = AgentAction.from_dict(mini_batch_demo)
if self.policy.action_spec.discrete_size > 0:
if self.policy.behavior_spec.action_spec.discrete_size > 0:
act_masks = ModelUtils.list_to_tensor(
np.ones(
(

正在加载...
取消
保存