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

how to convert a keras or tensorflow model with multiple inputs to a onnx one? #18964

Closed
lk1983823 opened this issue Dec 30, 2023 · 1 comment
Labels
converter related to ONNX converters

Comments

@lk1983823
Copy link

Describe the issue

how to convert a keras or tensorflow model with multiple inputs to a onnx one?

To reproduce

I have a tensorflow model with inputs like this:
model(past_data1,past_data2, past_data3, future_features1,future_features2, tsidx)
where:
past_data1.shape,past_data2.shape, past_data3.shape, future_features1.shape,future_features2.shape, tsidx.shape are:

(TensorShape([64, 720]),
 TensorShape([8, 720]),
 TensorShape([1, 720]),
 TensorShape([8, 30]),
 TensorShape([1, 30]),
 TensorShape([64]))

Now I try to convert this model to a onnx one to gain some accelerations with the code:

input1 = tf.TensorSpec(shape=(64, 720), dtype=tf.float32, name='x1')
input2 = tf.TensorSpec(shape=(8, 720), dtype=tf.float32, name='x2')
input3 = tf.TensorSpec(shape=(1, 720), dtype=tf.float32, name='x3')
input4 = tf.TensorSpec(shape=(8, 30), dtype=tf.float32, name='x4')
input5 = tf.TensorSpec(shape=(1, 30), dtype=tf.float32, name='x5')
input6 = tf.TensorSpec(shape=(64, ), dtype=tf.float32, name='x6')
model_input_signature = (input1, input2, input3, input4, input5, input6)

output_path = "./modellk.onnx"
onnx_model, _ = tf2onnx.convert.from_keras(model,
    output_path=output_path,
    input_signature=model_input_signature
)

Finally, it gives errors:

TypeError                                 Traceback (most recent call last)
Cell In[46], line 10
      7 model_input_signature = (input1, input2, input3, input4, input5, input6)
      9 output_path = "[./modellk.onnx](https://file+.vscode-resource.vscode-cdn.net/media/lk/disk1/lk_git/2_TimeSeries/2023_TimeSeries/google_ts/tide/modellk.onnx)"
---> 10 onnx_model, _ = tf2onnx.convert.from_keras(model,
     11     output_path=output_path,
     12     input_signature=model_input_signature
     13 )

File [~/anaconda3/envs/dpc/lib/python3.8/site-packages/tf2onnx/convert.py:452](https://file+.vscode-resource.vscode-cdn.net/media/lk/disk1/lk_git/2_TimeSeries/2023_TimeSeries/google_ts/tide/~/anaconda3/envs/dpc/lib/python3.8/site-packages/tf2onnx/convert.py:452), in from_keras(model, input_signature, opset, custom_ops, custom_op_handlers, custom_rewriter, inputs_as_nchw, outputs_as_nchw, extra_opset, shape_override, target, large_model, output_path, optimizers)
    449 except TypeError as e:
    450     # Legacy keras models don't accept the training arg tf provides so we hack around it
    451     if "got an unexpected keyword argument 'training'" not in str(e):
--> 452         raise e
    453     model_call = model.call
    454     def wrap_call(*args, training=False, **kwargs):

File [~/anaconda3/envs/dpc/lib/python3.8/site-packages/tf2onnx/convert.py:448](https://file+.vscode-resource.vscode-cdn.net/media/lk/disk1/lk_git/2_TimeSeries/2023_TimeSeries/google_ts/tide/~/anaconda3/envs/dpc/lib/python3.8/site-packages/tf2onnx/convert.py:448), in from_keras(model, input_signature, opset, custom_ops, custom_op_handlers, custom_rewriter, inputs_as_nchw, outputs_as_nchw, extra_opset, shape_override, target, large_model, output_path, optimizers)
    446 function = _saving_utils.trace_model_call(model, input_signature)
    447 try:
--> 448     concrete_func = function.get_concrete_function()
    449 except TypeError as e:
    450     # Legacy keras models don't accept the training arg tf provides so we hack around it
    451     if "got an unexpected keyword argument 'training'" not in str(e):
...
TypeError: in user code:


    TypeError: tf__call() missing 5 required positional arguments: 'past_data2', 'past_data3', 'future_features1', 'future_features2', and 'tsidx'

So how could I deal with it ? Thanks!

Urgency

No response

Platform

Linux

OS Version

Ubuntu 18.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.12.0

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@justinchuby justinchuby added the converter related to ONNX converters label Jan 3, 2024
@justinchuby
Copy link
Contributor

justinchuby commented Jan 3, 2024

Please create an issue in https://github.com/onnx/tensorflow-onnx/issues instead. Be sure to include all the relavent package versions. Thanks!

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

No branches or pull requests

2 participants