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

Reshape with allowzero is not supported

Open buddhapuneeth opened this issue 2 years ago • 2 comments

Describe the bug

From opset-14, ONNX Reshape operator supports allowzero attribute. But how attribute got set during the conversion is not clear. Based on my investigation on the tf2onnx source code, I believe we are not setting this attribute in any of the case.

Can you help me understand why this was not handled in the converter?

Is it supposed to add using external ONNX file manipulation (search for desired reshape operator and manually set the attribute)?

Urgency We have a urgent issue to resolve in couple of days and I am seeing work around by explicit modification of the ONNX file to add this attribute.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 18.04*): Mac
  • TensorFlow Version: 2.8
  • Python version: 3.8
  • ONNX version (if applicable, e.g. 1.11*): 1.14
  • ONNXRuntime version (if applicable, e.g. 1.11*): NA

To Reproduce

import tensorflow as tf
import numpy as np
import tf2onnx
import onnx
from tensorflow.keras.models import save_model
input1 = tf.keras.Input(shape=(2,3), name='input1')
s = tf.reshape(input1, [1, 0, 6])
model = tf.keras.models.Model(inputs=input1, outputs=s)
m, _ = tf2onnx.convert.from_keras(model, opset = 14)
onnx.save_model(m, "reshape.onnx")

Visualize in netron, you cannot see allowzero attribute in the ONNX model.

buddhapuneeth avatar May 23 '23 09:05 buddhapuneeth

Yes, this attribute was not added for Reshape yet. It's not awared during the previous opset upgrade work.

We will see if this could be added in next release of tf2onnx and your contributions are definitely welcome.

ONNX provides some tools so that users could manually process the onnx file. You might refer to here for some guidance.

fatcat-z avatar May 25 '23 10:05 fatcat-z

any updates on this maybe ? also getting this err..

Tavis991 avatar Jan 07 '24 10:01 Tavis991