tensorflow-onnx icon indicating copy to clipboard operation
tensorflow-onnx copied to clipboard

LayerNormalization is not show as LayerNormalization in onnx graph

Open Azulita0317 opened this issue 2 years ago • 2 comments

Ask a Question

Question

The LayerNormalization was translate to some operators and BatchNormalization, when I use opset=17。 I hope it could be a unique operator rather than a series of operator list like this: image

any parameter should I add? here is my code :

`

class Test_Model(tf.keras.Model):
  def __init__(self):
      super(Test_Model, self).__init__()
      self.input_layer = tf.keras.layers.Input((1,256,1))
      self.conv1 = layers.Conv2D(128, (1, 3), activation='relu',padding='same')
      self.norm1 = layers.LayerNormalization(axis=-1)
      self.conv2 = layers.Conv2D(64, (1, 4), activation='relu',padding='same')
      self.norm2 = layers.LayerNormalization(axis=3)
 def call(self, inputs):
      x = self.conv1(inputs)
      x = self.norm1(x)
      x = self.conv2(x)
      x = self.norm2(x)
      return x

input_shape = [1, 1, 256, 1]
inputs = tf.random.uniform(input_shape)
model = Test_Model()
model(inputs)
model.summary() 

onnx_model, _ = tf2onnx.convert.from_keras(model,opset=18)
new_model = onnxoptimizer.optimize(onnx_model)
inferred_model = onnx.shape_inference.infer_shapes(new_model)
onnx_name = r'./models/operators/layer_norm_tf' + '.onnx'
onnx.save_model(inferred_model, onnx_name) 

`

Azulita0317 avatar Oct 18 '23 10:10 Azulita0317

So far, LayerNormalization will be transferred to some tf nodes in tf graph by TensorFlow, tf2onnx doesn't have a pattern to identify this so we can't convert it to one node in ONNX graph.

fatcat-z avatar Oct 27 '23 10:10 fatcat-z

#2183 (feature request) #2250 (implementation attempt, deleted though)

pwuertz avatar Mar 12 '24 00:03 pwuertz