Skip to content

AttributeError: 'NoneType' object has no attribute 'decode' during TFLite to ONNX conversion #2362

Open
@kismeter

Description

@kismeter

Describe the bug

I encountered an error while attempting to convert a TFLite model to ONNX using the tf2onnx tool. using the following command:
python -m tf2onnx.convert --tflite keyword_scrambled.tflite
The error seems to originate from the tf2onnx/tflite_utils.py file, where it attempts to call tensor.Name().decode(). However, tensor appears to be None, resulting in an AttributeError.

Urgency

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 18.04*):
  • TensorFlow Version: tf-nightly 2.18.0.dev20240706
  • Python version: 3.10.14
  • ONNX version (if applicable, e.g. 1.11*): 1.13.0
  • ONNXRuntime version (if applicable, e.g. 1.11*): 1.13.0
  • tf2onnx: 1.16.1

To Reproduce

  1. Install TensorFlow nightly version (2.18.0.dev20240706), ONNX 1.13.0, and tf2onnx 1.16.1.
  2. Use tf2onnx.convert to attempt to convert a TensorFlow Lite model to ONNX.
  3. The conversion fails with an AttributeError.

Screenshots

Additional context

tflite model from https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/models/keyword_scrambled.tflite

2024-10-21 11:40:04,176 - INFO - Using tensorflow=2.18.0.dev20240706, onnx=1.13.0, tf2onnx=1.16.1/15c810
2024-10-21 11:40:04,176 - INFO - Using opset <onnx, 15>
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/site-packages/tf2onnx/convert.py", line 714, in
main()
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/site-packages/tf2onnx/convert.py", line 273, in main
model_proto, _ = _convert_common(
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/site-packages/tf2onnx/convert.py", line 168, in _convert_common
g = process_tf_graph(tf_graph, const_node_values=const_node_values,
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/site-packages/tf2onnx/tfonnx.py", line 453, in process_tf_graph
main_g, subgraphs = graphs_from_tflite(tflite_path, input_names, output_names)
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/site-packages/tf2onnx/tflite_utils.py", line 153, in graphs_from_tflite
parse_tflite_graph(tfl_graph, opcodes, model, prefix, tensor_shapes_from_interpreter)
File "/opt/homebrew/Caskroom/miniforge/base/envs/tf-nightly/lib/python3.10/site-packages/tf2onnx/tflite_utils.py", line 325, in parse_tflite_graph
name = tensor.Name().decode()
AttributeError: 'NoneType' object has no attribute 'decode'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions