tf.nn.xw_plus_b函数
tf.nn.xw_plus_b(
x,
weights,
biases,
name=None
)
定义在:tensorflow/python/ops/nn_ops.py。
计算matmul(x, weights) + biases。
参数:
- x:2D Tensor。维度通常为:batch,in_units
- weights:2D Tensor。维度通常为:in_units,out_units
- biases:1D Tensor。维度为:out_units
- name:操作的名称(可选)。如果未指定,则使用“xw_plus_b”。
返回:
- 2-D Tensor用来计算matmul(x, weights) + biases。维度通常为:batch,out_units。
tf.nn.xw_plus_b((x, weights) + biases)
相当于tf.matmul(x, weights) + biases
#-*-coding:utf8-*-
import tensorflow as tf
x=[[1, 2, 3],[4, 5, 6]]
w=[[ 7, 8],[ 9, 10],[11, 12]]
b=[[3,3],[3,3]]
result1=tf.nn.xw_plus_b(x,w,[3,3])
result2=tf.matmul(x, w) + b
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
# Run the init operation.
sess.run(init_op)
print(sess.run(result1))
print(sess.run(result2))
输出:
[[ 61 67]
[142 157]]
[[ 61 67]
[142 157]]
参考:https://www.w3cschool.cn/tensorflow_python/tf_nn_xw_plus_b.html
https://blog.youkuaiyun.com/ddy_sweety/article/details/80679077