Skip to main content
 首页 » 编程设计

python之如何理解使用 tensorflow 的 MNIST 实验中的技巧

2025年02月15日28Renyi-Fan

我是 Tensorflow 的初学者。我对教程有点困惑。作者首先给出了一个公式y=softmax(Wx+b),但是在python代码中使用xW+b并解释它是一个小技巧。我不明白其中的技巧,为什么作者需要翻转公式?

https://www.tensorflow.org/get_started/mnist/beginners

First, we multiply x by W with the expression tf.matmul(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. We then add b, and finally apply tf.nn.softmax.

请您参考如下方法:

从公式可以看出,

y=softmax(Wx + b) 

输入x乘以权重变量W,但是在doc中

y = tf.nn.softmax(tf.matmul(x, W) + b) 

为了计算方便,W乘以x,所以我们必须将W从10*784翻转为784*10,与公式保持一致。