MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / GroupNorm

Function GroupNorm

examples/FasterRCNN/modeling/backbone.py:17–44  ·  view source on GitHub ↗

More code that reproduces the paper can be found at https://github.com/ppwwyyxx/GroupNorm-reproduce/.

(x, group=32, gamma_initializer=tf.constant_initializer(1.))

Source from the content-addressed store, hash-verified

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

Callers 3

fastrcnn_Xconv1fc_headFunction · 0.70
fpn_modelFunction · 0.70
maskrcnn_upXconv_headFunction · 0.70

Calls 2

shapeMethod · 0.80
get_variableMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…