-
Notifications
You must be signed in to change notification settings - Fork 118
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
Converter for pytorch models that have multiple inputs #29
Comments
@bayleef1 We do support models with multiple inputs. You need to pass the inputs as a tuple. e.g. input_1 = torch.randn(1, 3, 224, 224)
input_2 = torch.randn(1, 3, 224, 224)
converter = TFLiteConverter(model, (input_1, input_2), ...)
converter.convert() |
OK, I successfully converted pytorch model with multiple inputs and outputs that exclude lstm state parameters. |
@bayleef1 Yes, it's due to a limitation that you cannot read or write variables in the TFLite graph. So you need to export the model without adding them to inputs or outputs. But you can still use them through the variable mechanism. import tensorflow as tf
import numpy as np
interpreter = tf.lite.Interpreter(model_path='xxx.tflite')
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
tensor_details = interpreter.get_tensor_details()
tensor_shapes = {d['index']: d['shape'] for d in tensor_details}
# set inputs
for i in range(len(input_details)):
interpreter.set_tensor(input_details[i]['index'], np.random.random(input_details[i]['shape']))
# set states
state_tensors = [3, 21]
for i in state_tensors:
interpreter.set_tensor(i, np.zeros(tensor_shapes[i]))
# invoke
interpreter.invoke()
# get outputs
outputs = []
for i in range(len(output_details)):
outputs.append(interpreter.get_tensor(output_details[i]['index']))
# get states
states = []
for i in state_tensors:
states.append(interpreter.get_tensor(i)) |
Hi, thanks for your excellent work. I've converted my pytorch model that has one input to tflite model successfully.
However, the converter seems not support pytorch models that have multiple inputs yet. Any plan for it?
The text was updated successfully, but these errors were encountered: