Tensorflow中自定义梯度运算的grad参数是否总是一个矩阵?

时间:2018-03-25 06:55:26

标签: python tensorflow machine-learning deep-learning

就我而言,有两种创建自定义操作的方法,如下所示:

@tf.RegisterGradient("CustomGrad")
    def _custom_grad(op, grad):
        return grad

@function.Defun(tf.float32, tf.float32)
    def bprop(op, grad):
        return grad

@function.Defun(tf.float32, grad_func=bprop)
    def fprop(W):
        W = tf.sign(W)
        return W

在我看来,无论前向道具的哪种类型的计算,自定义梯度op的grad参数始终是1的矩阵。我觉得它有点意义,因为你可以使用自定义渐变操作来让渐变通过。但是,我需要确认。

有人可以确认还是更正?

1 个答案:

答案 0 :(得分:0)

grad是使用自定义渐变后,图表中下一个实例的输入渐变。它不会受到你的前锋传球的影响。如果您更改操作后发生的事情grad可能会发生变化。

相关问题