为什么tf.gradients不适用于整数常量?

时间:2019-08-26 22:46:23

标签: python tensorflow

为什么下面的函数显示None

a = tf.constant(4)
b = tf.constant(2)

gr = tf.gradients(a + b, [a, b])

print(sess.run(gr))

但是当我改变

-a = tf.constant(4)
-b = tf.constant(2)
+a = tf.constant(4.0)
+b = tf.constant(2.0)

它打印渐变。是什么原因呢?

1 个答案:

答案 0 :(得分:2)

根据https://github.com/tensorflow/tensorflow/issues/20524 出于这个原因,tensorflow团队使tf.gradients与整数张量不兼容:

  

实际上,允许整数张量上的梯度导致   tf.while_loop中的错误,并且没有令人满意的方法   无需更改即可解决它们。

相关问题