onnx-tensorflow
onnx-tensorflow copied to clipboard
ValueError: shapes must be equal rank, but are 0 and 3 for 'onnx_tf_prefix_Where_1751' (op: 'Select') with input:[32,1,120], [], [32,3072,120]
Describe the bug Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/ops.py", line 1607, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Shapes must be equal rank, but are 0 and 3 for 'onnx_tf_prefix_Where_1751' (op: 'Select') with input shapes: [32,1,120], [], [32,3072,120].
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "torch_to_tf.py", line 621, in
The code
onnx_model = onnx.load(onnx_filename)
tf_rep = prepare(onnx_model,opset_version=11)
tf_rep.export_graph(tf_pb_path)
Hello, @chinhuang007. As mentioned above. The onnx model test is fine, exactly output with PyTorch model. if need onnx model, I'll attached it.
- Python version: 3.7.10
- ONNX version: 1.7.0
- ONNX-TF version: 1.7.0 (install with source code tf-1.x )
- Tensorflow version: 1.15.0
Thanks!!
Have you solved this problem? I have the same too.
Have you solved this problem? I have the same too.
no.
I got the similar problem when converting torch to tf through onnx with error: ValueError: Shapes must be equal rank, but are 0 and 3 for 'onnx_tf_prefix_Where_118' (op: 'Select') with input shapes: [?,16,?], [], [2,16,16]
. Then, I use this website to show the network structure and find the the op onnx_tf_prefix_Where_118
with name Where_118
. After checking my torch code, I found this operator corresponds to code:
attn = attn.masked_fill(mask, -np.inf)
So I think maybe masked_fill
is not supported. Combining the example of the Where
op from onnx, I change this line to:
attn = torch.where(mask, torch.full(mask.shape, -np.inf), attn)
And the problem is solved. Hope this helps. Good luck. 😊
I got the similar problem when converting torch to tf through onnx with error:
ValueError: Shapes must be equal rank, but are 0 and 3 for 'onnx_tf_prefix_Where_118' (op: 'Select') with input shapes: [?,16,?], [], [2,16,16]
. Then, I use this website to show the network structure and find the the oponnx_tf_prefix_Where_118
with nameWhere_118
. After checking my torch code, I found this operator corresponds to code:attn = attn.masked_fill(mask, -np.inf)
So I think maybe
masked_fill
is not supported. Combining the example of theWhere
op from onnx, I change this line to:attn = torch.where(mask, torch.full(mask.shape, -np.inf), attn)
And the problem is solved. Hope this helps. Good luck. 😊
OK. I'll verify it later. thank you!