| 37 | |
| 38 | |
| 39 | def update_bn_ema(xn, batch_mean, batch_var, |
| 40 | moving_mean, moving_var, decay, internal_update): |
| 41 | update_op1 = moving_averages.assign_moving_average( |
| 42 | moving_mean, batch_mean, decay, zero_debias=False, |
| 43 | name='mean_ema_op') |
| 44 | update_op2 = moving_averages.assign_moving_average( |
| 45 | moving_var, batch_var, decay, zero_debias=False, |
| 46 | name='var_ema_op') |
| 47 | |
| 48 | if internal_update: |
| 49 | with tf.control_dependencies([update_op1, update_op2]): |
| 50 | return tf.identity(xn, name='output') |
| 51 | else: |
| 52 | tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_op1) |
| 53 | tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_op2) |
| 54 | return tf.identity(xn, name='output') |
| 55 | |
| 56 | |
| 57 | @layer_register() |