from.registerimportregisterfromx2paddle.core.utilimport*defnormalize_shape(input_shape):returninput_shapedefnormalize_layer(inputs,across_spatial=None,channel_shared=None,input_shape=None,name=None):assertacross_spatial==False,"Only support across_spatial == False for Normalize"input=inputs[0]l2_norm=fluid.layers.l2_normalize(input,axis=1,name=name+'_l2')scale_param=fluid.layers.create_parameter(shape=[1]ifchannel_sharedelse[input_shape[0][1]],dtype=input.dtype,attr=name+'_scale')out=fluid.layers.elementwise_mul(x=l2_norm,y=scale_param,axis=-1ifchannel_sharedelse1)returnoutdefnormalize_weights(name,data=None):weights_name=[name+'_scale']returnweights_nameregister(kind='Normalize',shape=normalize_shape,layer=normalize_layer,weights=normalize_weights)