TensorFlow基础tf.add 和 tf.nn.bias_add 的区别
Posted wuliyttaotao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TensorFlow基础tf.add 和 tf.nn.bias_add 的区别相关的知识,希望对你有一定的参考价值。
1. tf.add(x, y, name)
Args: x: A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `uint8`, `int8`, `int16`, `int32`, `int64`, `complex64`, `complex128`, `string`. y: A `Tensor`. Must have the same type as `x`. name: A name for the operation (optional). Returns: A `Tensor`. Has the same type as `x`.
2. tf.nn.bias_add(value, bias, data_format=None, name=None)
Adds `bias` to `value`. This is (mostly) a special case of `tf.add` where `bias` is restricted to 1-D. Broadcasting is supported, so `value` may have any number of dimensions. Unlike `tf.add`, the type of `bias` is allowed to differ from `value` in the case where both types are quantized. Args: value: A `Tensor` with type `float`, `double`, `int64`, `int32`, `uint8`, `int16`, `int8`, `complex64`, or `complex128`. bias: A 1-D `Tensor` with size matching the last dimension of `value`. Must be the same type as `value` unless `value` is a quantized type, in which case a different quantized type may be used. data_format: A string. ‘NHWC‘ and ‘NCHW‘ are supported. name: A name for the operation (optional).
Returns: A `Tensor` with the same type as `value`.
3. tf.add 和 tf.nn.bias_add 的区别
- tf.nn.bias_add 是 tf.add 中的一个特例,tf.nn.bias_add 中 bias 一定是 1 维的张量;
- tf.nn.bias_add 中 value 最后一维长度和 bias 的长度一定得一样;
- tf.nn.bias_add 中,当 value 是 quantized type 时,bias 可以取不同的 quantized type。但什么是 quantized type?TensorFlow API 中 tf.DType 页面显示,‘tf.qint8‘、‘tf.quint8‘、‘tf.qint16‘、‘tf.quint16‘、‘tf.qint32‘类型就是Quantized type。但这些类别具体如何使用并不知晓。
References
以上是关于TensorFlow基础tf.add 和 tf.nn.bias_add 的区别的主要内容,如果未能解决你的问题,请参考以下文章
TensorFlow 辨异 —— tf.add(a, b) 与 a+b(tf.assign 与 =)tf.nn.bias_add 与 tf.add(转)