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

IndexError: list index out of range in parse_tflite_graph #2055

Closed
josephrocca opened this issue Oct 9, 2022 · 5 comments
Closed

IndexError: list index out of range in parse_tflite_graph #2055

josephrocca opened this issue Oct 9, 2022 · 5 comments
Labels
bug An unexpected problem or unintended behavior pending on user response Waiting for more information or validation from user

Comments

@josephrocca
Copy link

josephrocca commented Oct 9, 2022

Describe the bug
As shown in this Colab notebook, I get the following error when trying to convert this tflite file to ONNX:

/usr/lib/python3.7/runpy.py:125: RuntimeWarning: 'tf2onnx.convert' found in sys.modules after import of package 'tf2onnx', but prior to execution of 'tf2onnx.convert'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
2022-10-09 04:08:11,357 - INFO - tf2onnx: inputs: None
2022-10-09 04:08:11,357 - INFO - tf2onnx: outputs: None
2022-10-09 04:08:12,242 - INFO - tf2onnx.tfonnx: Using tensorflow=2.9.2, onnx=1.12.0, tf2onnx=1.12.0/c60c5e
2022-10-09 04:08:12,243 - INFO - tf2onnx.tfonnx: Using opset <onnx, 16>
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/dist-packages/tf2onnx/convert.py", line 706, in <module>
    main()
  File "/usr/local/lib/python3.7/dist-packages/tf2onnx/convert.py", line 291, in main
    output_path=args.output)
  File "/usr/local/lib/python3.7/dist-packages/tf2onnx/convert.py", line 165, in _convert_common
    custom_op_handlers=custom_op_handlers, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/tf2onnx/tfonnx.py", line 453, in process_tf_graph
    main_g, subgraphs = graphs_from_tflite(tflite_path, input_names, output_names)
  File "/usr/local/lib/python3.7/dist-packages/tf2onnx/tflite_utils.py", line 153, in graphs_from_tflite
    parse_tflite_graph(tfl_graph, opcodes, model, prefix, tensor_shapes_from_interpreter)
  File "/usr/local/lib/python3.7/dist-packages/tf2onnx/tflite_utils.py", line 485, in parse_tflite_graph
    onnx_node = helper.make_node(optype, input_names, output_names, name=output_names[0], **attr)
IndexError: list index out of range

Urgency
No hard deadlines. It is blocking conversion of Google's newly open-sourced Lyra v2 to ONNX so that it can work in web browsers.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 18.04*): Colab
  • TensorFlow Version: 2.9.2 (also tested in 2.8.2 - same error)
  • Python version: 3.7.14

To Reproduce
https://colab.research.google.com/gist/josephrocca/0581baa153235adf9a3e6560203edc80/lyra-v2-soundstream-tflite-to-onnx-conversion-error-indexerror-list-index-out-of-range.ipynb#scrollTo=_Our00mFGN_J

Additional Context
These issues appear to be related by the title, but looking into the specifics of the error message, I don't think they're related:

@josephrocca
Copy link
Author

I'm guessing that output_names[0] is throwing an error because there's a node that should have at least one output, but doesn't? When I open the tflite model in netron.app, I notice there's a lone CallOnce node without any inputs or outputs. Not sure if that's related - just a random guess. There's also a subgraph in the tflite model called 'NoOp' that looks like this:

image

No idea what's going on there.

@fatcat-z
Copy link
Collaborator

fatcat-z commented Oct 9, 2022

I'm guessing that output_names[0] is throwing an error because there's a node that should have at least one output, but doesn't? When I open the tflite model in netron.app, I notice there's a lone CallOnce node without any inputs or outputs. Not sure if that's related - just a random guess. There's also a subgraph in the tflite model called 'NoOp' that looks like this:

image

No idea what's going on there.

Yes, your guess is correct. When tf2onnx is processing one node TFL_ASSIGN_VARIABLE, the output of this node is None which is not expected.

How did you generate this tflite file? By Tensorflow? If so, how about filing an issue in TensorFlow repo to check if such tflite file is correct, based on the origin tf model?

@josephrocca
Copy link
Author

josephrocca commented Oct 12, 2022

Hey @fatcat-z, thanks for your reply! The Google Lyra team says that are unable to release their original TF models, but they did try doing a conversion straight to ONNX, and it apparently worked:

google/lyra#99 (comment)

Unfortunately they aren't able to release those ONNX models yet. I'm wondering whether there are any other paths toward getting an ONNX model from this tflite model, given these unusual circumstances?


Ah, so I stopped half-way through writing this comment and tried hackily patching tf2onnx to avoid this problem, but looks like it's blocked on another problem anyway:

So maybe the best option is to wait for the Lyra devs to release the "directly converted" ONNX files?

@fatcat-z
Copy link
Collaborator

fatcat-z commented Oct 12, 2022

@josephrocca ,

Thank you for your detailed descriptions and efforts. At this moment, probably the best option is as you suggested to wait for that released ONNX file. We will take a quick look at these 2 unsupported ops to see if we can figure it out soon so you can move forward.

@fatcat-z
Copy link
Collaborator

Close this since it was resolved in issue #2059 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior pending on user response Waiting for more information or validation from user
Projects
None yet
Development

No branches or pull requests

2 participants