1. 程式人生 > >TensorFlow 辨異 —— tf.add(a, b) 與 a+b(tf.assign 與 =)、tf.nn.bias_add 與 tf.add(轉)

TensorFlow 辨異 —— tf.add(a, b) 與 a+b(tf.assign 與 =)、tf.nn.bias_add 與 tf.add(轉)

fad codes live tin csdn hat targe ops 操作

1. tf.add(a, b) 與 a+b

在神經網絡前向傳播的過程中,經常可見如下兩種形式的代碼:

  • tf.add(tf.matmul(x, w), b)
  • tf.matmul(x, w) + b

簡而言之,就是 tf.add(a, b)a + b二者的區別,類似的也有,tf.assign=(賦值運算符)的差異。

在計算精度上,二者並沒有差別。運算符重載的形式a+b,會在內部轉換為,a.__add__(b),而a.__add__(b)會再一次地映射為tf.add,在 math_ops.py中相關的映射如下:

_OverrideBinaryOperatorHelper(gen_math_ops.add, "add")

In tensorflow what is the difference between tf.add and operator (+)?

2. tf.nn.bias_add 與 tf.add

tf.nn.bias_add 是 tf.add 的一個特例,也即 tf.add 支持的操作比 tf.nn.bias_add 更多。二者均支持 broadcasting(廣播機制),也即兩個操作數最後一個維度保持一致。

除了支持最後一個維度保持一致的兩個操作數相加外,tf.add 還支持第二個操作數是一維的情況。

轉自:https://blog.csdn.net/lanchunhui/article/details/66477742

TensorFlow 辨異 —— tf.add(a, b) 與 a+b(tf.assign 與 =)、tf.nn.bias_add 與 tf.add(轉)