简体   繁体   English

MNIST教程中的Tensorflow tf.matmul

[英]Tensorflow tf.matmul in MNIST tutorial

I'm new in using tensorflow. 我是使用tensorflow的新手。 Here is my question : 这是我的问题:

In the MNIST tutorial : https://www.tensorflow.org/versions/master/get_started/mnist/beginners#mnist-for-ml-beginners : 在MNIST教程中: https ://www.tensorflow.org/versions/master/get_started/mnist/beginners#mnist-for-ml-beginners:

First, we multiply x by W with the expression tf.matmul(x, W). 首先,我们用表达式tf.matmul(x,W)将x乘以W。 This is flipped from when we multiplied them in our equation, where we had Wx, as a small trick to deal with x being a 2D tensor with multiple inputs. 这是从我们在方程中乘以Wx时得到的乘积翻转过来的,这是处理x为具有多个输入的2D张量的一个小技巧。 We then add b, and finally apply tf.nn.softmax. 然后,我们添加b,最后应用tf.nn.softmax。

My question is : 我的问题是:

Why b was initialized as a vector : b = tf.Variable(tf.zeros([10])) 为什么将b初始化为向量: b = tf.Variable(tf.zeros([10]))

and not as b = tf.Variable(tf.zeros([None,10])) or b = tf.Variable(tf.zeros([1,10])) ? 而不是b = tf.Variable(tf.zeros([None,10]))b = tf.Variable(tf.zeros([1,10]))吗?

Since the shapes of x * W + b are : [None , 784] * [784 , 10] + [None,10] 由于x * W + b的形状为:[无,784] * [784,10] + [无,10]

Thanks for your answers. 感谢您的回答。

This is because, we apply same operation for every "image" from the batch, not to batch. 这是因为,我们对批次中的每个“图像”(而不是批次)应用相同的操作。 Thus x * W + b are not 因此x * W + b不是

[None , 784] * [784 , 10] + [None,10]

but are 但是

results = merge(None, [784] * [784, 10] + [10])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM