tensorflow - 在tensorflow MNIST softmax教程中,没有使用softmax函数

标签 tensorflow softmax

我正在关注 MNIST Softmax 教程 https://www.tensorflow.org/tutorials/mnist/beginners/

后面是文档,模型应该是

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

但在示例源代码中,如您所见

# Create the model
x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.matmul(x, W) + b

未使用softmax。我认为需要改变

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

我假设,在测试函数中它使用argmax,因此不需要将其标准化为0~1.0值。但它会给开发者带来一些困惑。

对此有何想法?

最佳答案

使用 Softmax,第 57 行:

# So here we use tf.nn.softmax_cross_entropy_with_logits on the raw
# outputs of 'y', and then average across the batch.
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))

参见softmax_cross_entropy_with_logits了解更多详情。

关于tensorflow - 在tensorflow MNIST softmax教程中,没有使用softmax函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41340879/

相关文章:

python - 使用 PyMC3 的 Softmax 回归(多项逻辑)

tensorflow - 神经网络超参数调整 - 设置随机种子是个好主意吗?

python - 如何在卷积神经网络中使用余弦函数作为激活函数?

python - Tensorflow v1.12.0中export_savedmodel的问题

neural-network - softmax 函数解释的导数

r - 使用 Softmax 转换输出激活会产生相似的值

python - softmax_loss函数: Turn the loop into matrix operation

python - 如何使用 pytorch 计算 softmax 回归的成本

tensorflow - 动态广播

machine-learning - Keras——没有带有广播的 Dot 层?