假设以下简化代码:
x = tf.Variable(...)
y = tf.Variable(...) # y can also be some tensor computed from other variables
x_new = tf.assign(x, y)
loss = x_new * x_new
如果我优化损失,损失的梯度是反传播到x或y?
发布于 2017-10-28 18:19:13
通常,您可以在这个discussion中找到一个很好的关于赋值op的解释。
对于您的具体问题,损失梯度将不会再传播到x或y:
# Your example.
tf.gradients(x_new * x_new, [x, y]) #output: [None, None]
# Some other related examples.
tf.gradients(x_new * y, [x, y]) #output: [None, x_new_value]
tf.gradients(x * x_new, [x, y]) #output: [x_new_value, None]
https://stackoverflow.com/questions/46984316
复制相似问题