MPolaris / onnx2tflite

Tool for onnx->keras or onnx->tflite. Hope this tool can help you.
Apache License 2.0
526 stars 42 forks source link

Error when specifying need_simplify=False when converting #79

Closed enzoferrari1 closed 3 months ago

enzoferrari1 commented 3 months ago

When doing conversion of my YOLOv10 n model, an error occurs while using the converter with need_simplify = False. I don't want to quantize the model because it loses too much accuracy in the case of YOLO.

from onnx2tflite import onnx_converter
res = onnx_converter(
        onnx_model_path = "/content/yolo-single-detector.onnx",
        need_simplify = False,
        fp16_model = True,
        native_groupconv = True,
        output_path = "/content",
        target_formats = ['tflite'],
    ) 

shows error

[/content/onnx2tflite/onnx2tflite/components/builder.py](https://localhost:8080/#) in keras_builder(onnx_model, native_groupconv)
     49         # init layout
     50         for index in range(len(node_outputs)):
---> 51             layout_dict[node_outputs[index]] = layout_dict.get(node_inputs[0], Layout.Default)
     52 
     53         res = tf_operator(tf_tensor, onnx_weights, node_inputs, op_attr, node_outputs, layout_dict)(_inputs)

IndexError: list index (0) out of range
MPolaris commented 3 months ago

need_simplify is recommended to be enabled as it will optimize the compute graph without affecting accuracy.

abhijeetsourav commented 2 months ago

The below code gives the same error

`from onnx2tflite import onnx_converter

res = onnx_converter( onnx_model_path = "/content/parseq.onnx", need_simplify = True, output_path = "/content/", target_formats = ['tflite'], )`

`2024-08-30 21:17:31,309 - onnx_loader running: - WARNING - onnxsim is failed, maybe make convert fails.

IndexError Traceback (most recent call last) in <cell line: 3>() 1 from onnx2tflite import onnx_converter 2 ----> 3 res = onnx_converter( 4 onnx_model_path = "/content/parseq.onnx", 5 need_simplify = True,

1 frames /content/onnx2tflite/onnx2tflite/components/builder.py in keras_builder(onnx_model, native_groupconv) 49 # init layout 50 for index in range(len(node_outputs)): ---> 51 layout_dict[node_outputs[index]] = layout_dict.get(node_inputs[0], Layout.Default) 52 53 res = tf_operator(tf_tensor, onnx_weights, node_inputs, op_attr, node_outputs, layout_dict)(_inputs)

IndexError: list index (0) out of range`