执行以下代码时获取错误:W tensorflow/core/framework/op_kernel.cc:1622]op_REQUIRES在跨步_slice_op处失败。cc:108:无效参数:使用输入dim 1索引超出范围;输入只有1个DIM
def random_actions(self,cur_state):
s=[]
dest=9
states=self.get_state(cur_state)
for index, tuple in enumerate(states):
actions=tuple[0]
weights=tuple[1]
s.append(actions)
actions=list(s)
return actions
num_hidden = 2
num_actions =env.random_actions(3)
inputs = layers.Input(shape=(2))
common = layers.Dense(num_hidden, activation="relu")(inputs)
action = layers.Dense(len(num_actions), activation="softmax")(common)
critic = layers.Dense(1)(common)
model = keras.Model(inputs=inputs, outputs=[action, critic])
state = env.reset()
state=list(state)
with tf.GradientTape() as tape:
for timestep in range(1, max_steps_per_episode):
state = tf.convert_to_tensor(state,np.float32)
action_probs, critic_value = model(state)
critic_value_history.append(critic_value[0, 0])
action = np.random.choice(num_actions, p=np.squeeze(action_probs[0]))
action_probs_history.append(tf.math.log(action_probs[0, action]))
state, next_state,reward, = env.step(action)
rewards_history.append(reward)
steps.append(action)
错误:
在处理以下行时:
action_probs_history.append(tf.math.log(action_probs[0, action]))
InvalidArgumentError: slice index 7 of dimension 1 out of bounds. [Op:StridedSlice] name: strided_slice/
2020-11-23 06:09:03.890424: W tensorflow/core/framework/op_kernel.cc:1622] OP_REQUIRES failed at strided_slice_op.cc:108 : Invalid argument: Index out of range using input dim 1; input has only 1 dims
需要建议。
我想你重新定义了“行动”这个名字。您将其用作密集层输出,并在稍后使用与random.choice()的输出相同的名称。我不知道这是否是错误的原因,但它看起来肯定不正确
相关问题 更多 >
编程相关推荐