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.
MIT License
712 stars 73 forks source link

Model modification issue #598

Closed akshatshah17 closed 7 months ago

akshatshah17 commented 7 months ago

Issue Type

Others

OS

Linux

onnx2tf version number

1.19.11

onnx version number

1.15.0

onnxruntime version number

1.16.3

onnxsim (onnx_simplifier) version number

0.4.33

tensorflow version number

2.15.0

Download URL for ONNX

https://github.com/akshatshah17/Models/blob/main/sample.onnx

Parameter Replacement JSON

NO Replacement JSON

Description

I have created a sample onnx model with exact same scenarios. There are 2 reshapes layers which I want to remove so in the ops/reshape.py I changed final_shape as [32, 512, 512] so those layers can omit while convert to tflite. I also change axes from [1, 2] to [1] in unsqueeze.py so that it will create [4, 1, 512] tensor rather than [4,1,1,512]. But it won't convert because of this error,

ERROR: The trace log is below. Traceback (most recent call last): File "/home/code/Akashat/python/onnx2tfconstant/lib/python3.10/site-packages/onnx2tf/utils/common_functions.py", line 310, in print_wrapper_func result = func(*args, kwargs) File "/home/code/Akashat/python/onnx2tfconstant/lib/python3.10/site-packages/onnx2tf/utils/common_functions.py", line 383, in inverted_operation_enable_disable_wrapper_func result = func(*args, *kwargs) File "/home/code/Akashat/python/onnx2tfconstant/lib/python3.10/site-packages/onnx2tf/utils/common_functions.py", line 53, in get_replacement_parameter_wrapper_func func(args, kwargs) File "/home/code/Akashat/python/onnx2tfconstant/lib/python3.10/site-packages/onnx2tf/ops/Where.py", line 185, in make_node tf.where( File "/home/code/Akashat/python/onnx2tfconstant/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler raise e.with_traceback(filtered_tb) from None File "/home/code/Akashat/python/onnx2tfconstant/lib/python3.10/site-packages/keras/src/layers/core/tf_op_layer.py", line 119, in handle return TFOpLambda(op)(*args, **kwargs) File "/home/code/Akashat/python/onnx2tfconstant/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None ValueError: Exception encountered when calling layer "tf.where" (type TFOpLambda).

Dimensions must be equal, but are 4 and 32 for '{{node tf.where/SelectV2}} = SelectV2[T=DT_FLOAT](Placeholder, tf.where/SelectV2/t, Placeholder_1)' with input shapes: [4,1,512], [], [32,512,512].

Call arguments received by layer "tf.where" (type TFOpLambda): • condition=tf.Tensor(shape=(4, 1, 512), dtype=bool) • x=array(-inf, dtype=float32) • y=tf.Tensor(shape=(32, 512, 512), dtype=float32) • name='sng_Where_2'

ERROR: input_onnx_file_path: sample.onnx ERROR: onnx_op_name: sng_Where_2 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.

Previously where layer has condition as [4, 1, 1, 512] and value from reshape is [4, 8, 512, 512] so it can convert it. I want to remove these 2 reshapes layer anyhow so help me here if there is any way around.

PINTO0309 commented 7 months ago
onnx2tf -i sample.onnx -kat input_1 input_2
akshatshah17 commented 7 months ago

I know the command to convert the model I want to remove reshape layers from my tflite graph please can you go through description once