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
662 stars 65 forks source link

How to keep input op shape static #674

Closed suyash-narain closed 1 month ago

suyash-narain commented 1 month ago

Issue Type

Others

OS

Linux

onnx2tf version number

1.22.4

onnx version number

1.15.0

onnxruntime version number

1.17.1

onnxsim (onnx_simplifier) version number

0.4.35

tensorflow version number

2.16.1

Download URL for ONNX

None

Parameter Replacement JSON

None

Description

  1. purpose: product development
  2. what: I have an ONNX model which has input shape: 1,224,320,3 (NHWC) and input op name "input_1:0". I am trying to convert it to tflite using onnx2tf -i -kat input_1:0. the input shape is still getting jumped up and converting the shape to (1,320,3,240). i even tried using the arguments keep_nwc_or_nhwc_or_ndhwc_input_names=['input_1:0'] keep_ncw_or_nchw_or_ncdhw_input_names=['input_1:0'] and keep_shape_absolutely_input_names=['input_1:0'] in my python script when calling onnx2tf.convert. The converted tflite model still has the shape (1,320,3,224)

what am I doing wrong here? Am i missing something? i want the input shape to remain constant. its jumbling the input shape and then inserting the transpose op to change the shape to NHWC (1,224,320,3). thanks

PINTO0309 commented 1 month ago

If you don't even provide a partial ONNX, I have no idea what kind of mistake you are making. I will not answer the question because it is a waste of survey time unless a small portion of the model entrance, not the entire model, is shared with me.

You are definitely using tf2onnx in the wrong way.

suyash-narain commented 1 month ago

my apologies. i thought the model url was shared by me already please find the model url attached: https://catalog.ngc.nvidia.com/orgs/nvidia/teams/tao/models/bodyposenet/files?version=deployable_onnx_v1.0.1 model name: model.onnx

PINTO0309 commented 1 month ago

NVIDIA engineers' use of tf2onnx is totally useless.

sor4onnx \
--input_onnx_file_path model.onnx \
--old_new ":0" "" \
--mode full \
--search_mode suffix_match \
--output_onnx_file_path model_renamed.onnx
onnx2tf -i model_renamed.onnx -ois input_1:1,224,320,3 -kat input_1

image

suyash-narain commented 1 month ago

thank you for your prompt reply. I am using onnx2tf.convert using python API to automate the conversion. can you tell me what are the corresponding arguments which i can use instead of kat when using onnx2tf.convert() function in python?

thanks for your help

PINTO0309 commented 1 month ago

There is no such method; it is correct to convert to NCHW at the point of generating ONNX.

suyash-narain commented 1 month ago

okay thank you.