How to average summaries over multiple batches?

后端 未结 9 1383
刺人心
刺人心 2020-12-13 09:18

Assuming I have a bunch of summaries defined like:

loss = ...
tf.scalar_summary(\"loss\", loss)
# ...
summaries = tf.m         


        
9条回答
  •  醉梦人生
    2020-12-13 09:59

    You can average store the current sum and recalculate the average after each batch, like:

    loss_sum = tf.Variable(0.)
    inc_op = tf.assign_add(loss_sum, loss)
    clear_op = tf.assign(loss_sum, 0.)
    average = loss_sum / batches
    tf.scalar_summary("average_loss", average)
    
    sess.run(clear_op)
    for i in range(batches):
        sess.run([loss, inc_op])
    
    sess.run(average)
    

提交回复
热议问题