代码拉取完成,页面将自动刷新
class tf.nn.bias_add(value, bias, data_format=None, name=None)
For more information, see tf.nn.bias_add.
mindspore.ops.bias_add(input_x, bias)
For more information, see mindspore.ops.bias_add.
TensorFlow: Return the sum of the tensor of input value and bias, where bias is restricted to a 1D tensor and value supports various numbers of dimensions, and bias is broadcasted to be consistent with the shape of input value before the two are summed.
MindSpore: MindSpore API basically implements the same function as TensorFlow. However, MindSpore input input_x only supports 2-5 dimensional shapes.
Categories | Subcategories | TensorFlow | MindSpore | Differences |
---|---|---|---|---|
Parameters | Parameter 1 | value | input_x | Same function, different parameter names |
Parameter 2 | bias | bias | Same function | |
Parameter 3 | data_format | - | The data format of the input data. MindSpore does not have this parameter | |
Parameter 4 | name | - | Not involved |
The two APIs achieve the same function and have the same usage.
# TensorFlow
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
value = tf.constant([[1, 2], [3, 4], [5, 6]], dtype=tf.float32)
bias = tf.constant([-2, -1], dtype=tf.float32)
result = tf.nn.bias_add(value, bias)
ss = tf.compat.v1.Session()
output = ss.run(result)
print(output)
# [[-1. 1.]
# [ 1. 3.]
# [ 3. 5.]]
# MindSpore
import numpy as np
import mindspore
import mindspore.ops as ops
from mindspore import Tensor
input_x = Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)
bias = Tensor(np.array([-2 , -1]), mindspore.float32)
output = ops.bias_add(input_x, bias)
print(output)
# [[-1. 1.]
# [ 1. 3.]
# [ 3. 5.]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。