python - 如果您使用加号而不是 tf.add,tensorflow 是否仍会正确计算梯度?

标签 python tensorflow

如果我有一个相当复杂的成本方程式:

cost = tf.reduce_sum( tf.multiply( y , tf.log(y/abs(yy)))  + \
                      tf.multiply( (1 - y) , tf.log((1-y)/abs(1-yy)) ) )

tensorflow 还会为此计算出正确的反向传播方程吗?换句话说,我如何确定梯度计算正确?

最佳答案

如本 anwser 中所述, __add__ 操作(和 __mul__ 以及 btw)被重载,因此

cost = tf.reduce_sum(tf.add(
    tf.multiply( y , tf.log(y/abs(yy))),
    tf.multiply((1 - y) , tf.log((1-y)/abs(1-yy)))
))

相当于

cost = tf.reduce_sum(y * tf.log(y/abs(yy))  + (1 - y) * tf.log((1-y)/abs(1-yy))) 

关于python - 如果您使用加号而不是 tf.add,tensorflow 是否仍会正确计算梯度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48767565/

相关文章:

python - Django JSON 字段。 'module' 对象没有属性 'JSONField'

python - 从源代码构建 Tensorflow 时出现非法指令错误

python - 执行 rnn model 时出错。如何修复它?

python - 在文本小部件中对索引进行排序的最佳方式

python - 尝试计算每个样本的梯度时,vmap 给出不一致的形状错误

tensorflow - Inception-v3 使用 RMSProp epsilon=1

machine-learning - 将 Keras 模型参数和模型架构与模型一起存储的最佳方法是什么?

Tensorflow自动删除旧模型文件

python - iteritems 上的 Pillar jinja 错误

python - 指定 python 字典中可能的值