【发布时间】:2016-09-23 09:16:32
【问题描述】:
我正在通过斯坦福课程学习使用 Tensorflow 的神经网络。我在实现 RNN 时发现了这一点,但不太明白为什么会累积损失:
# This adds a loss operation to the Graph for batch training
def add_loss_op(self, output):
all_ones = [tf.ones([self.config.batch_size * self.config.num_steps])]
cross_entropy = sequence_loss(
[output], [tf.reshape(self.labels_placeholder, [-1])], all_ones, len(self.vocab))
tf.add_to_collection('total_loss', cross_entropy)
# Doesn't this increase in size every batch of training?
loss = tf.add_n(tf.get_collection('total_loss'))
return loss
get_collection()here 的文档没有提到任何关于清除变量的内容。由于这是针对每个训练步骤运行的,因此每个训练阶段/小批量训练的损失是否都会增加并结转?
我还是个神经网络新手,所以请纠正我对此的任何误解!
【问题讨论】:
标签: python neural-network tensorflow recurrent-neural-network