Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot take the length of shape with unknown rank. #1077

Open
lzfff12 opened this issue Jun 6, 2024 · 0 comments
Open

Cannot take the length of shape with unknown rank. #1077

lzfff12 opened this issue Jun 6, 2024 · 0 comments

Comments

@lzfff12
Copy link

lzfff12 commented Jun 6, 2024

Describe the bug

Traceback (most recent call last):
File "convert2onnx/convert_superglue_to_onnx.py", line 124, in
main()
File "convert2onnx/convert_superglue_to_onnx.py", line 117, in main
tf_rep.run((kpts0, scores0, desc0, kpts1, scores1, desc1))
File "/mnt/training/map/zhifeng.lin/code/SuperPoint-SuperGlue-TensorRT/onnx-tensorflow/onnx_tf/backend_rep.py", line 107, in run
output_values = self.tf_module(**input_dict)
File "/mnt/data/anaconda3/envs/lightglue/lib/python3.8/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/tmp/autograph_generated_filecuhrqz0v.py", line 30, in tf____call
ag__.for_stmt(ag__.ld(self).graph_def.node, None, loop_body, get_state, set_state, (), {'iterate_names': 'node'})
File "/tmp/autograph_generated_filecuhrqz0v.py", line 23, in loop_body
output_ops = ag
.converted_call(ag__.ld(self).backend.onnx_node_to_tensorflow_op, (ag_.ld(onnx_node), ag__.ld(tensor_dict), ag__.ld(self).handlers), dict(opset=ag__.ld(self).opset, strict=ag__.ld(self).strict), fscope)
File "/tmp/autograph_generated_file05s8tr06.py", line 50, in tf___onnx_node_to_tensorflow_op
ag
.if_stmt(ag__.ld(handlers), if_body_1, else_body_1, get_state_1, set_state_1, ('do_return', 'retval_'), 2)
File "/tmp/autograph_generated_file05s8tr06.py", line 44, in if_body_1
ag
.if_stmt(ag__.ld(handler), if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
File "/tmp/autograph_generated_file05s8tr06.py", line 36, in if_body
retval
= ag
_.converted_call(ag__.ld(handler).handle, (ag__.ld(node),), dict(tensor_dict=ag__.ld(tensor_dict), strict=ag__.ld(strict)), fscope)
File "/tmp/autograph_generated_filegv1w6atb.py", line 34, in tf__handle
ag
.if_stmt(ag__.ld(ver_handle), if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
File "/tmp/autograph_generated_filegv1w6atb.py", line 26, in if_body
retval
= ag
_.converted_call(ag__.ld(ver_handle), (ag__.ld(node),), dict(**ag__.ld(kwargs)), fscope)
File "/tmp/autograph_generated_fileg_gf0gau.py", line 12, in tf__version
retval
= ag
_.converted_call(ag__.ld(cls).conv, (ag__.ld(node), ag__.ld(kwargs)['tensor_dict']), None, fscope)
File "/tmp/autograph_generated_filekbecj_e4.py", line 12, in tf__conv
x_rank = ag
.converted_call(ag__.ld(len), (ag__.converted_call(ag__.ld(x).get_shape, (), None, fscope),), None, fscope)
ValueError: in user code:

File "/mnt/training/map/zhifeng.lin/code/SuperPoint-SuperGlue-TensorRT/onnx-tensorflow/onnx_tf/backend_tf_module.py", line 99, in __call__  *
    output_ops = self.backend._onnx_node_to_tensorflow_op(onnx_node,
File "/mnt/training/map/zhifeng.lin/code/SuperPoint-SuperGlue-TensorRT/onnx-tensorflow/onnx_tf/backend.py", line 347, in _onnx_node_to_tensorflow_op  *
    return handler.handle(node, tensor_dict=tensor_dict, strict=strict)
File "/mnt/training/map/zhifeng.lin/code/SuperPoint-SuperGlue-TensorRT/onnx-tensorflow/onnx_tf/handlers/handler.py", line 59, in handle  *
    return ver_handle(node, **kwargs)
File "/mnt/training/map/zhifeng.lin/code/SuperPoint-SuperGlue-TensorRT/onnx-tensorflow/onnx_tf/handlers/backend/conv.py", line 15, in version_11  *
    return cls.conv(node, kwargs["tensor_dict"])
File "/mnt/training/map/zhifeng.lin/code/SuperPoint-SuperGlue-TensorRT/onnx-tensorflow/onnx_tf/handlers/backend/conv_mixin.py", line 30, in conv  *
    x_rank = len(x.get_shape())

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

To Reproduce

torch.onnx.export(superpoint_model, # model being run
(kpts0, scores0, desc0, kpts1, scores1, desc1), # model input (or a tuple for multiple inputs)
onnx_filename, # where to save the model (can be a file or file-like object)
#export_params=True, # store the trained parameter weights inside the model file
opset_version=13, # the ONNX version to export the model to
#do_constant_folding=True, # whether to execute constant folding for optimization
input_names=["keypoints_0", # batch x feature_number0 x 2
"scores_0", # batch x feature_number0
"descriptors_0", # batch x feature_dims x feature_number0
"keypoints_1", # batch x feature_number1 x 2
"scores_1", # batch x feature_number1
"descriptors_1", # batch x feature_dims x feature_number1
], # the model input names
output_names=["scores"], # the model output names
dynamic_axes={'keypoints_0': {1: 'feature_number_0'},
'scores_0': {1: 'feature_number_0'},
'descriptors_0': {2: 'feature_number_0'},
'keypoints_1': {1: 'feature_number_1'},
'scores_1': {1: 'feature_number_1'},
'descriptors_1': {2: 'feature_number_1'},
} # dynamic model input names
)

# check onnx model
onnx_model = onnx.load(onnx_filename)
onnx.checker.check_model(onnx_model)

print("Exported model has been checked with ONNXRuntime.")


#spsg_model_path = "sgsg.onnx"
sgsg_tf_model="superglue.tf.pb"
#model_onnx = onnx.load(spsg_model_path)
tf_rep = prepare(onnx_model)

# Input nodes to the model
print('inputs:', tf_rep.inputs)

Output nodes from the model

print('outputs:', tf_rep.outputs)

All nodes in the model

print('tensor_dict:')
print(tf_rep.tensor_dict)
print("11111")
tf_rep.run((kpts0, scores0, desc0, kpts1, scores1, desc1))
print("2222")
# Export model as .pb file
tf_rep.export_graph(sgsg_tf_model)

A self-contained piece of code that can demonstrate the problem is required.

Please do not expect us to have PyTorch, Caffe2 installed.

If a model exported from PyTorch and Caffe2 is having trouble in ONNX-TF, use the next section to attach the model.

ONNX model file

If applicable, attach the onnx model file in question using Gist, DropBox or Google Drive.

ONNX-TF

This section can be obtained by running get_version.py from util folder.

  • Python 3.8:
  • ONNX version 1.16.1:
  • ONNX-TF version 1.10.1:
  • Tensorflow version 2.13.1:

Additional context

Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant