Skip to content

"IndexError: list index out of range" occurs when trying to convert BigGAN tflite model to ONNX format #2388

Open
@xtrizeShino

Description

@xtrizeShino

Ask a Question

Question

"IndexError: list index out of range" occurs when I try to convert a BigGAN tflite model to ONNX format. Can you tell me the correct command or source code to convert this model?

https://drive.google.com/file/d/149nTlPi0WlQZn3F_IAUlzfWkZkMnVok1/view?usp=drive_link

Commands I tried

$ python -m tf2onnx.convert --tflite biggan-128.tflite --output biggan-128_nchw_output.onnx --outputs-as-nchw "StatefulPartitionedCall:0" --inputs "serving_default_y:0,serving_default_z:0,serving_default_truncation:0" --outputs "StatefulPartitionedCall:0"

Error that occurred when executing the command

2025-04-11 23:58:33.873525: I tensorflow/core/util/util.cc:169] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2025-04-11 23:58:33.875774: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:
2025-04-11 23:58:33.875787: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
/home/shino/anaconda3/envs/movenet/lib/python3.10/runpy.py:126: 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))
2025-04-11 23:58:34.619575: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2025-04-11 23:58:34.622735: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2025-04-11 23:58:34.625844: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:
2025-04-11 23:58:34.625873: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublas.so.11'; dlerror: libcublas.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:
2025-04-11 23:58:34.625896: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublasLt.so.11'; dlerror: libcublasLt.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:
2025-04-11 23:58:34.625918: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcufft.so.10'; dlerror: libcufft.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:
2025-04-11 23:58:34.647138: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusparse.so.11'; dlerror: libcusparse.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:
2025-04-11 23:58:34.647185: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:
2025-04-11 23:58:34.647189: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1850] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2025-04-11 23:58:34.647389: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2025-04-11 23:58:34,649 - INFO - Using tensorflow=2.9.0, onnx=1.14.1, tf2onnx=1.13.0/2c1db5
2025-04-11 23:58:34,649 - INFO - Using opset <onnx, 13>
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
  File "/home/shino/anaconda3/envs/movenet/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/shino/anaconda3/envs/movenet/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/shino/.local/lib/python3.10/site-packages/tf2onnx/convert.py", line 706, in <module>
    main()
  File "/home/shino/.local/lib/python3.10/site-packages/tf2onnx/convert.py", line 269, in main
    model_proto, _ = _convert_common(
  File "/home/shino/.local/lib/python3.10/site-packages/tf2onnx/convert.py", line 164, in _convert_common
    g = process_tf_graph(tf_graph, const_node_values=const_node_values,
  File "/home/shino/.local/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 "/home/shino/.local/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 "/home/shino/.local/lib/python3.10/site-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

Further information

  • Is this issue related to a specific model?
    Model name:

https://drive.google.com/file/d/149nTlPi0WlQZn3F_IAUlzfWkZkMnVok1/view?usp=drive_link

The model downloaded from Kaggle was converted to TFlite using the following source code:

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import tensorflow_hub as hub

# https://www.kaggle.com/models/deepmind/biggan
model_url = "https://www.kaggle.com/models/deepmind/biggan/TensorFlow1/128/2"
input_truncation = keras.Input(batch_shape=(), name='truncation')
input_y = keras.Input(shape=(1000, ), name='y')
input_z = keras.Input(shape=(120, ), name='z')
hub_layer = hub.KerasLayer(
            model_url,
            trainable=False,
            signature="default", 
            signature_outputs_as_dict=True,
        )

inputs = dict(y=input_y, z=input_z, truncation=input_truncation)
output = hub_layer(inputs)
model = tf.keras.models.Model(inputs=[input_truncation, input_y, input_z], outputs=[output])
model.build(([1], [1, 1000], [1, 120]))
model.summary()
model.save("biggan-128")

converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
open("biggan-128.tflite", "wb").write(tflite_model)

Model opset:

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAn issue, pull request, or discussion needs more information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions