📅  最后修改于: 2022-03-11 14:59:37.857000             🧑  作者: Mango
ç±æ¤å¯ä»¥çåºï¼GNåBNæ¯æå¾å¤ç¸ä¼¼ä¹å¤çï¼ä»£ç ç¸æ¯è¾BNæ¹å¨åªæä¸ä¸¤è¡èå·²ï¼è®ºæç»åºç代ç å®ç°å¦ä¸ï¼
def GroupNorm(x, gamma, beta, G, eps=1e-5):
# x: input features with shape [N,C,H,W]
# gamma, beta: scale and offset, with shape [1,C,1,1]
# G: number of groups for GN
N, C, H, W = x.shape
x = tf.reshape(x, [N, G, C // G, H, W])
mean, var = tf.nn.moments(x, [2, 3, 4], keep dims=True)
x = (x - mean) / tf.sqrt(var + eps)
x = tf.reshape(x, [N, C, H, W])
return x * gamma + beta