onnx / onnx-tensorflow

Tensorflow Backend for ONNX
Other
1.27k stars 296 forks source link

ValueError: Cannot take the length of shape with unknown rank. during evaluation #890

Open Tpt opened 3 years ago

Tpt commented 3 years ago

Describe the bug

ValueError: Cannot take the length of shape with unknown rank. exception is raised from convolution implementation during ONNX evaluation.

ONNX model file

stt_fr_quartznet15x5.onnx

To Reproduce

import numpy
import onnx
from onnx_tf.backend import prepare

onnx_model = onnx.load("stt_fr_quartznet15x5.onnx")
tf_model = prepare(onnx_model, device='CPU')

input_example = numpy.random.rand(1, 2048).astype('float32')
input_example_size = numpy.array([2048])
tf_model.run({'input_signal': input_example, 'input_signal_length': input_example_size})

Backtrace

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    tf_model.run({'input_signal': input_example, 'input_signal_length': input_example_size})
  File "venv/lib/python3.8/site-packages/onnx_tf/backend_rep.py", line 93, in run
    output_values = self.tf_module(**input_dict)
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 828, in __call__
    result = self._call(*args, **kwds)
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 871, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 725, in _initialize
    self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 2969, in _get_concrete_function_internal_garbage_collected
    graph_function, _ = self._maybe_define_function(args, kwargs)
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3361, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3196, in _create_graph_function
    func_graph_module.func_graph_from_py_func(
  File "venv/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 990, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py", line 634, in wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "venv/lib/python3.8/site-packages/tensorflow/python/eager/function.py", line 3887, in bound_method_wrapper
    return wrapped_fn(*args, **kwargs)
  File "venv/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 977, in wrapper
    raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:

    venv/lib/python3.8/site-packages/onnx_tf/backend_tf_module.py:98 __call__  *
        output_ops = self.backend._onnx_node_to_tensorflow_op(onnx_node,
    venv/lib/python3.8/site-packages/onnx_tf/backend.py:289 _onnx_node_to_tensorflow_op  *
        return handler.handle(node, tensor_dict=tensor_dict, strict=strict)
    venv/lib/python3.8/site-packages/onnx_tf/handlers/handler.py:59 handle  *
        return ver_handle(node, **kwargs)
    venv/lib/python3.8/site-packages/onnx_tf/handlers/backend/conv.py:15 version_11  *
        return cls.conv(node, kwargs["tensor_dict"])
    venv/lib/python3.8/site-packages/onnx_tf/handlers/backend/conv_mixin.py:30 conv  *
        x_rank = len(x.get_shape())
    venv/lib/python3.8/site-packages/tensorflow/python/autograph/operators/py_builtins.py:252 len_  **
        return _py_len(s)
    venv/lib/python3.8/site-packages/tensorflow/python/autograph/operators/py_builtins.py:317 _py_len
        return len(s)
    venv/lib/python3.8/site-packages/tensorflow/python/framework/tensor_shape.py:848 __len__
        raise ValueError("Cannot take the length of shape with unknown rank.")

    ValueError: Cannot take the length of shape with unknown rank.

Python, ONNX, ONNX-TF, Tensorflow version

Additional context

The ONNX file has been generated using Torch 1.8 with ONNX opset 12. The ONNX file is valid according to the onnx library validator and evaluated without problems with onnxruntime.

Rechargeablezz commented 1 year ago

我也遇到了相同的问题,请问您解决了吗