How to average summaries over multiple batches?

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

Assuming I have a bunch of summaries defined like:

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


        
9条回答
  •  -上瘾入骨i
    2020-12-13 09:55

    I would avoid calculating the average outside the graph.

    You can use tf.train.ExponentialMovingAverage:

    ema = tf.train.ExponentialMovingAverage(decay=my_decay_value, zero_debias=True)
    maintain_ema_op = ema.apply(your_losses_list)
    
    # Create an op that will update the moving averages after each training step.
    with tf.control_dependencies([your_original_train_op]):
        train_op = tf.group(maintain_ema_op)
    

    Then, use:

    sess.run(train_op)
    

    That will call maintain_ema_op because it is defined as a control dependency.

    In order to get your exponential moving averages, use:

    moving_average = ema.average(an_item_from_your_losses_list_above)
    

    And retrieve its value using:

    value = sess.run(moving_average)
    

    This calculates the moving average within your calculation graph.

提交回复
热议问题