I am trying to convert an ONNX model with a dynamic input shape to TensorFlow format using the onnx_tf package. I am using TensorFlow 2.11.0, ONNX 1.13.0, and onnx_tf 1.10.0. The input to the model contains 3 arrays: the data with dynamic shape (1, None) and 2 arrays with fixed shapes (2,1,64). When I run the following code, I get on the last line a "ValueError: Cannot take the length of shape with unknown rank" :

# Imports
import onnx
from onnx import version_converter
import os
from onnx_tf.backend import prepare

# load onnx model
model_dir = r'model\vad'
model_name = 'vad.onnx'
onnx_model = onnx.load(os.path.join(model_dir,'onnx', model_name))  # load onnx model

# Export to Tensorflow
os.makedirs(os.path.join(model_dir ,'tensorflow'), exist_ok=True)
tf_rep = prepare(onnx_model)  # prepare tf representation
tf_rep.export_graph(os.path.join(model_dir,'tensorflow','vad'))  # export the model

What could be causing this error and how can I fix it?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.