有几个教程将 reduce_mean
应用于 sparse_softmax_cross_entropy_with_logits
的输出。例如
cross_entropy = -tf.reduce_sum(y_ * tf.log(y_conv))
或
cross_entropy = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(
labels=tf.cast(y_, dtype=tf.int32), logits=y_conv))
为什么将reduce_mean
应用于sparse_softmax_cross_entropy_with_logits
的输出?是否因为我们使用的是小批量,所以我们想要计算(使用 reduce_mean
)小批量所有样本的平均损失?
最佳答案
原因是为了获得批处理的平均损失。
通常,您将训练一个输入批处理大小 > 1 的神经网络,批处理中的每个元素都会产生一个损失值,因此将这些元素合并为一个值的最简单方法是求平均值。
关于tensorflow - 为什么将reduce_mean应用于sparse_softmax_cross_entropy_with_logits的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50604095/