使用损失函数更新神经网络的权重

Use of loss functions in updating weights of neural networks

我对 tf.reduce_mean(tf.nn.l2_loss(prediction - output)) 行的使用感到困惑。

在进行反向传播时,输出应该是一个向量,因为每个输出神经元的预测输出都从实际输出中减去,并且对所有输出神经元重复这一过程,因此我们得到一个大小为 (n,1) 的向量。如果我们使用 tf.reduce_mean(tf.nn.l2_loss(prediction - output)),则输出是单个值。我无法理解如何传播这个单一值来更新权重。它不应该总是一个向量吗?

你说得对,损失必须是向量。但是,这一行

tf.reduce_mean

正在计算批次的平均损失,而不是向量的平均损失。参见 https://stats.stackexchange.com/questions/201452/is-it-common-practice-to-minimize-the-mean-loss-over-the-batches-instead-of-the