我正在尝试使用卷积神经网络对图像分类问题进行建模。我在 Github 上遇到了一个代码,其中我无法理解在训练循环中进行损失计算的以下行的含义。
我省略了大部分细节,只放置了相关代码-
for batch_idx, (data, target) in enumerate(final_train_loader):
loss = criterion(output,target)
#Idea behind the below line
train_loss = train_loss + ((1 / (batch_idx + 1)) * (loss.data - train_loss))
这里使用了交叉熵损失函数。