(n_out, use_scale, use_bias, gamma_init)
| 19 | |
| 20 | |
| 21 | def get_bn_variables(n_out, use_scale, use_bias, gamma_init): |
| 22 | if use_bias: |
| 23 | beta = tf.get_variable('beta', [n_out], initializer=tf.constant_initializer()) |
| 24 | else: |
| 25 | beta = tf.zeros([n_out], name='beta') |
| 26 | if use_scale: |
| 27 | gamma = tf.get_variable('gamma', [n_out], initializer=gamma_init) |
| 28 | else: |
| 29 | gamma = tf.ones([n_out], name='gamma') |
| 30 | # x * gamma + beta |
| 31 | |
| 32 | moving_mean = tf.get_variable('mean/EMA', [n_out], |
| 33 | initializer=tf.constant_initializer(), trainable=False) |
| 34 | moving_var = tf.get_variable('variance/EMA', [n_out], |
| 35 | initializer=tf.constant_initializer(1.0), trainable=False) |
| 36 | return beta, gamma, moving_mean, moving_var |
| 37 | |
| 38 | |
| 39 | def update_bn_ema(xn, batch_mean, batch_var, |
no test coverage detected