https://arxiv.org/abs/1803.08494 More code that reproduces the paper can be found at https://github.com/ppwwyyxx/GroupNorm-reproduce/.
(x, group, gamma_initializer=tf.constant_initializer(1.))
| 15 | |
| 16 | |
| 17 | def GroupNorm(x, group, gamma_initializer=tf.constant_initializer(1.)): |
| 18 | """ |
| 19 | https://arxiv.org/abs/1803.08494 |
| 20 | More code that reproduces the paper can be found at https://github.com/ppwwyyxx/GroupNorm-reproduce/. |
| 21 | """ |
| 22 | shape = x.get_shape().as_list() |
| 23 | ndims = len(shape) |
| 24 | assert ndims == 4, shape |
| 25 | chan = shape[1] |
| 26 | assert chan % group == 0, chan |
| 27 | group_size = chan // group |
| 28 | |
| 29 | orig_shape = tf.shape(x) |
| 30 | h, w = orig_shape[2], orig_shape[3] |
| 31 | |
| 32 | x = tf.reshape(x, tf.stack([-1, group, group_size, h, w])) |
| 33 | |
| 34 | mean, var = tf.nn.moments(x, [2, 3, 4], keep_dims=True) |
| 35 | |
| 36 | new_shape = [1, group, group_size, 1, 1] |
| 37 | |
| 38 | beta = tf.get_variable('beta', [chan], initializer=tf.constant_initializer()) |
| 39 | beta = tf.reshape(beta, new_shape) |
| 40 | |
| 41 | gamma = tf.get_variable('gamma', [chan], initializer=gamma_initializer) |
| 42 | gamma = tf.reshape(gamma, new_shape) |
| 43 | |
| 44 | out = tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-5, name='output') |
| 45 | return tf.reshape(out, orig_shape, name='output') |
| 46 | |
| 47 | |
| 48 | def convnormrelu(x, name, chan): |
no test coverage detected