numpy tf代理的奖励、步长类型和折扣形状

qyuhtwio  于 9个月前  发布在  其他
关注(0)|答案(1)|浏览(151)

我正在尝试基于this tutorial中的代码使用tf agent训练一个agent。我目前正在自定义py_environment供自己使用。除了与环境相关的代码外,其余代码与教程中完全相同。

def compute_avg_return(environment, policy, num_episodes=10):

  total_return = 0.0
  for _ in range(num_episodes):

    time_step = environment.reset()
    episode_return = 0.0

    while not time_step.is_last():
      action_step = policy.action(time_step) # <----- error on this line
      time_step = environment.step(action_step.action)
      episode_return += time_step.reward
    total_return += episode_return

  avg_return = total_return / num_episodes
  return avg_return.numpy()[0]

compute_avg_return(eval_env, random_policy, num_eval_episodes)

字符串
我第一次运行上面的代码时得到了以下错误:

ValueError: Received a mix of batched and unbatched Tensors, or Tensors are not compatible with Specs.  num_outer_dims: 1.
Saw tensor_shapes:
   TimeStep(
{'discount': TensorShape([1]),
 'observation': TensorShape([1, 50, 30]),
 'reward': TensorShape([1]),
 'step_type': TensorShape([1])})
And spec_shapes:
   TimeStep(
{'discount': TensorShape([]),
 'observation': TensorShape([1, 50, 30]),
 'reward': TensorShape([]),
 'step_type': TensorShape([])})


从错误日志中,我的观察形状是正确的,但它仍然说,他们是不兼容的。所以我认为问题是在'折扣','奖励'和'步骤_类型'的形状?
但是我应该怎么做呢?我找不到任何东西告诉我如何定义/改变这些属性的形状。

f8rj6qna

f8rj6qna1#

哇,原来是我观察的类型不正确。我通过在验证实用程序库中添加print语句发现了它。
这是因为我使用了pandas Dataframe.to_numpy(),它输出的是np.float64而不是float32。

相关问题