ValueError:没有为损失函数中的任何变量提供梯度

时间:2020-04-11 09:00:15

标签: tensorflow loss-function

我在tensorflow中是一个新手。

prob = tf.nn.softmax_cross_entropy_with_logits(logits = self.output_layer_predictions_array, labels = y)
loss = tf.matmul( [prob] ,discounted_episode_rewards_)[0] 
train_opt = self.sess.run(tf.train.AdamOptimizer().minimize(loss))

样品
self.output_layer_predictions_array

[[-3.6822972297668457, 0.3711770176887512], [-0.8316356539726257, 0.9947062134742737],...

y

[[0.01706565 0.98293436]
 [0.13867462 0.8613254 ]..

损失

[0.08638819 0.40255022 0.20361374 0.4243075  0.5737337  0.68438727
 0.6912215  0.69195086 0.65356493 0.5951165  0.6025962 ]

我研究发现的 y 必须总计为1个
我的损失确实计算得很好


但这给了错误

> ValueError: No gradients provided for any variable, check your graph
> for ops that do not support gradients, between variables
> ["<tf.Variable 'Variable:0' shape=(4, 24) dtype=float32_ref>",
> "<tf.Variable 'Variable_1:0' shape=(24,) dtype=float32_ref>",
> "<tf.Variable 'Variable_2:0' shape=(24, 12) dtype=float32_ref>",
> "<tf.Variable 'Variable_3:0' shape=(12,) dtype=float32_ref>",
> "<tf.Variable 'Variable_4:0' shape=(12, 4) dtype=float32_ref>",
> "<tf.Variable 'Variable_5:0' shape=(4,) dtype=float32_ref>",
> "<tf.Variable 'Variable_6:0' shape=(4, 2) dtype=float32_ref>"] and
> loss Tensor("strided_slice:0", shape=(1,), dtype=float32).

我无法解决该错误。请帮助并询问是否需要

0 个答案:

没有答案