Group-Normalization-Tensorflow
Group-Normalization-Tensorflow copied to clipboard
There is a prolem for running
I want to use gn into CNN , and meet a prolem: ailed to convert object of type <class 'list'> to Tensor. Contents: [Dimension(None), 2, Dimension(14), Dimension(28), Dimension(32)]. Consider casting elements to a supported type.
this is the code: def groupnorm(x,gamma,bate,G,eps=1e-5): x=tf.transpose(x,[0,3,1,2]) N,C,H,W =x.get_shape().as_list() G=min(G,C) print('x:',x) 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) gamma=tf.get_variable('gamma',[C],initializer=tf.constant_initializer(1.0)) bate=tf.get_variable('bate',[C],initializer=tf.constant_initializer(1.0)) gamma=tf.reshape(gamma,[1,C,1,1]) bate=tf.reshape(gamma,[1,C,1,1]) x=tf.reshape(x, [N, H, W, C]) output=x*gamma+bate output=tf.transpose(output,[0,2,3,1]) print('a:',a) return output
same here. just replace N with -1, and the problem may be solved. x=tf.reshape(x,[-1,G,C//G,H,W]) x=tf.reshape(x, [-1, H, W, C])