我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用tensorflow.contrib.slim.layer_norm()。
def __call__(self, inputs, state, scope=None): if self._apply_to == 'input': with tf.variable_scope(scope or self._name): inputs = slim.layer_norm(inputs) return self._cell(inputs, state) elif self._apply_to == 'output': output, res_state = self._cell(inputs, state) with tf.variable_scope(scope or self._name): output = slim.layer_norm(output) return output, res_state elif self._apply_to == 'state': output, res_state = self._cell(inputs, state) with tf.variable_scope(scope or self._name): res_state = slim.layer_norm(res_state) return output, res_state else: raise ValueError('Unknown apply_to: "{}"'.format(self._apply_to))
def recursive_generator(label,sp): dim=512 if sp>=128 else 1024 if sp==512: dim=128 if sp==1024: dim=32 if sp==4: input=label else: downsampled=tf.image.resize_area(label,(sp//2,sp),align_corners=False) input=tf.concat([tf.image.resize_bilinear(recursive_generator(downsampled,sp//2),(sp,sp*2),align_corners=True),label],3) net=slim.conv2d(input,dim,[3,3],rate=1,normalizer_fn=slim.layer_norm,activation_fn=lrelu,scope='g_'+str(sp)+'_conv1') net=slim.conv2d(net,dim,[3,3],rate=1,normalizer_fn=slim.layer_norm,activation_fn=lrelu,scope='g_'+str(sp)+'_conv2') if sp==1024: net=slim.conv2d(net,3,[1,1],rate=1,activation_fn=None,scope='g_'+str(sp)+'_conv100') net=(net+1.0)/2.0*255.0 return net
def _get_normalizer(is_training, use_bn, use_ln): ''' Helper to get normalizer function and params ''' batch_norm_params = {'is_training': is_training, 'decay': 0.999, 'center': True, 'scale': True, 'updates_collections': None} layer_norm_params = {'center': True, 'scale': True} if use_ln: print 'using layer norm' normalizer_fn = slim.layer_norm normalizer_params = layer_norm_params elif use_bn: print 'using batch norm' normalizer_fn = slim.batch_norm normalizer_params = batch_norm_params else: print 'not using any layer normalization scheme' normalizer_fn = None normalizer_params = None return [normalizer_fn, normalizer_params]
def _network_factory(num_classes, is_training, weight_decay=1e-8): def factory_fn(image, reuse, l2_normalize): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training): with slim.arg_scope([slim.conv2d, slim.fully_connected, slim.batch_norm, slim.layer_norm], reuse=reuse): features, logits = _create_network( image, num_classes, l2_normalize=l2_normalize, reuse=reuse, create_summaries=is_training, weight_decay=weight_decay) return features, logits return factory_fn
def recursive_generator(label,sp): dim=512 if sp>=128 else 1024 if sp==4: input=label else: downsampled=tf.image.resize_area(label,(sp//2,sp),align_corners=False) input=tf.concat([tf.image.resize_bilinear(recursive_generator(downsampled,sp//2),(sp,sp*2),align_corners=True),label],3) net=slim.conv2d(input,dim,[3,3],rate=1,normalizer_fn=slim.layer_norm,activation_fn=lrelu,scope='g_'+str(sp)+'_conv1') net=slim.conv2d(net,dim,[3,3],rate=1,normalizer_fn=slim.layer_norm,activation_fn=lrelu,scope='g_'+str(sp)+'_conv2') if sp==256: net=slim.conv2d(net,27,[1,1],rate=1,activation_fn=None,scope='g_'+str(sp)+'_conv100') net=(net+1.0)/2.0*255.0 split0,split1,split2=tf.split(tf.transpose(net,perm=[3,1,2,0]),num_or_size_splits=3,axis=0) net=tf.concat([split0,split1,split2],3) return net
def recursive_generator(label,sp): dim=512 if sp>=128 else 1024 if sp==512: dim=128 if sp==4: input=label else: downsampled=tf.image.resize_area(label,(sp//2,sp),align_corners=False) input=tf.concat([tf.image.resize_bilinear(recursive_generator(downsampled,sp//2),(sp,sp*2),align_corners=True),label],3) net=slim.conv2d(input,dim,[3,3],rate=1,normalizer_fn=slim.layer_norm,activation_fn=lrelu,scope='g_'+str(sp)+'_conv1') net=slim.conv2d(net,dim,[3,3],rate=1,normalizer_fn=slim.layer_norm,activation_fn=lrelu,scope='g_'+str(sp)+'_conv2') if sp==512: net=slim.conv2d(net,3,[1,1],rate=1,activation_fn=None,scope='g_'+str(sp)+'_conv100') net=(net+1.0)/2.0*255.0 return net