Previously, everything was working fine, but just a few days ago, something happened and tf2onnx stopped working in all of my Google Colab notebooks.
This is a test example with https://onnxruntime.ai/
import tensorflow as tf
import tf2onnx
import onnx
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(4, activation="relu"))
input_signature = [tf.TensorSpec([3, 3], tf.float32, name='x')]
onnx_model, _ = tf2onnx.convert.from_keras(model, input_signature, opset=13)
onnx.save(onnx_model, "test_model.onnx")
Result:
AttributeError Traceback (most recent call last)
in <cell line: 13>()
11 input_signature = [tf.TensorSpec([3, 3], tf.float32, name=’x’)]
12
—> 13 onnx_model, _ = tf2onnx.convert.from_keras(model, input_signature, opset=13)
14 onnx.save(onnx_model, “test_model.onnx”)
1 frames
/usr/local/lib/python3.10/dist-packages/tf2onnx/convert.py in _rename_duplicate_keras_model_names(model)
329 “””
330 old_out_names = None
–> 331 if model.output_names and len(set(model.output_names)) != len(model.output_names):
332 # In very rare cases, keras has a bug where it will give multiple outputs the same name
333 # We must edit the model or the TF trace will fail
AttributeError: ‘Sequential’ object has no attribute ‘output_names’
I also tried using tf2onnx.convert.from_function, but that didn’t help either.
olegeskevich is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.