PINTO0309 / onnx2tf

Self-Created Tools to convert ONNX files (NCHW) to TensorFlow/TFLite/Keras format (NHWC). The purpose of this tool is to solve the massive Transpose extrapolation problem in onnx-tensorflow (onnx-tf). I don't need a Star, but give me a pull request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Op Error about "Transpose"

wondervictor opened this issue · comments

Issue Type

Others

OS

Linux

onnx2tf version number

1.20.0

onnx version number

1.15.0

onnxruntime version number

1.16.3

onnxsim (onnx_simplifier) version number

0.4.33

tensorflow version number

2.16.1

Download URL for ONNX

https://drive.google.com/file/d/1g6y2146QOOLq7RpPrxPhG7Zv-ACmznwg/view?usp=sharing

Parameter Replacement JSON

N/A

Description

Hi, I found a particularly strange issue when converting from ONNX to TFLite. One of the “Transpose”(Transpose_127) operations encountered the following problem: a prompt saying that there is no "80" index. I further discovered that the input shape of this operation (onnx____Transpose_594) is [4, 40, 40, 80] in the conversion process, while the actual input in ONNX for this operation (onnx::Transpose_594) is [4, 1, 40, 40]. The input of the same operation is different in ONNX and during the conversion process, which is very confusing.

The error log is:

ERROR: The trace log is below.
Traceback (most recent call last):
  File "/data/miniconda3/envs/env-3.9.2/lib/python3.9/site-packages/onnx2tf/utils/common_functions.py", line 310, in print_wrapper_func
    result = func(*args, **kwargs)
  File "/data/miniconda3/envs/env-3.9.2/lib/python3.9/site-packages/onnx2tf/utils/common_functions.py", line 383, in inverted_operation_enable_disable_wrapper_func
    result = func(*args, **kwargs)
  File "/data/miniconda3/envs/env-3.9.2/lib/python3.9/site-packages/onnx2tf/utils/common_functions.py", line 53, in get_replacement_parameter_wrapper_func
    func(*args, **kwargs)
  File "/data/miniconda3/envs/env-3.9.2/lib/python3.9/site-packages/onnx2tf/ops/Transpose.py", line 107, in make_node
    new_perm[tf_shape_idx] = onnx_output_shape.index(tf_shape_value)
ValueError: 80 is not in list
ERROR: onnx_op_name: Transpose_127
ERROR: Read this and deal with it. https://github.com/PINTO0309/onnx2tf#parameter-replacement
ERROR: Alternatively, if the input OP has a dynamic dimension, use the -b or -ois option to rewrite it to a static shape and try again.
ERROR: If the input OP of ONNX before conversion is NHWC or an irregular channel arrangement other than NCHW, use the -kt or -kat option.
ERROR: Also, for models that include NonMaxSuppression in the post-processing, try the -onwdt option.

Tell me how much RAM your PC has.

Glad to see your reply.

# lsmem
RANGE                                  SIZE  STATE REMOVABLE BLOCK
0x0000000000000000-0x000000007fffffff    2G online       yes   0-1
0x0000000100000000-0x000000c03fffffff  765G online       yes 4-768

Memory block size:         1G
Total online memory:     767G
Total offline memory:      0B

You seem to have noticed a problem that I have been ignoring. All ReduceXXX operations cause problems. Because of the specification that ReduceXXX allows multiple dimensions to be specified for axes, it takes a bit of time to modify and validate the tool. In other words, it can be dealt with.

image

image

Thank you, is there any way to bypass this issue?

If you are in a great hurry, you can use JSON to compensate for mistakes in the transposition behavior of axes in ReduceMax. Read the tutorial below.

https://github.com/PINTO0309/onnx2tf?tab=readme-ov-file#parameter-replacement

https://github.com/PINTO0309/onnx2tf/tree/main/json_samples

If you find the tool too cumbersome to correct its behavior, or if you have a deadline for the conversion work, you should wait until I fix the bugs.

Thank you very much, I'll first try to solve it through replacement. However I am very much looking forward to you fixing this issue, it is great!

Fixes: https://github.com/PINTO0309/onnx2tf/releases/tag/1.20.3

Note that the use of Anaconda/miniconda is strongly discouraged. Be sure to use the latest packages listed below, either by using Docker or by using Colabo.

https://github.com/PINTO0309/onnx2tf?tab=readme-ov-file#environment

image