-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use converted model with dynamic input shape #521
Comments
The price of onnx2tf's considerably higher model optimization efficiency compared to onnx-tensorflow is that the optimization operation may fail if there are two or more undefined dimensions in the input tensor. If there is a series of tensors with axis size None, the correct axis position will be lost in the process of model transformation. Although the conversion of models with multiple undefined dimensions is originally supported, the probability of model conversion failure is higher, and the user must compensate for conversion errors. JSON files can be used to compensate for the axis transposition behavior of onnx2tf. In the case of RetinaFace, there was an error in the axis correction of If you do not understand what I am saying, I would not recommend dealing with a model that has a high conversion difficulty involving undefined dimensions.
https://github.com/PINTO0309/onnx2tf/releases/tag/1.18.2
|
Redundant ONNX output from PyTorch was improved by performing a proprietary optimization to eliminate the need for JSON creation. https://github.com/PINTO0309/onnx2tf/releases/tag/1.18.3
|
Good luck. |
Thanks for all your help @PINTO0309. Everything here makes sense, but I wasn't able to get to this work today. I'll review in detail on Monday and let you know if I run into any additional issues with the updates. |
Alright @PINTO0309, we're making great progress here. I can now run the dynamic input model without any shape issues on the Circling back to the
This matches the general functionality in I have updated the
This passes successfully. Printing the confidence outputs of these models ( Now, setting aside
The
Note that multiple elements that are So, am I doing something wrong with the input shapes or transpositions here? What am I doing wrong such that the |
I was late checking the issue because I was training other models. Models containing more than one None have a non-zero chance of making a transposition error. The checks performed in Forced meaning compares, for example, Thus, if you are unlucky enough to have a model with a structure like [1,9,9,9,9] in the middle of the model, the check itself will succeed correctly, but the axis of the model transformation itself may still be wrong. Structural checking of a model with multiple None is quite difficult even with the human eye, but for when such a situation arises, we have a function to check where we have made a mistake in transforming the model. The For example,
Once you know where you have made a transposition error on an axis, you can use JSON to correct the transposition error. For example, https://github.com/PINTO0309/onnx2tf#parameter-replacement https://github.com/PINTO0309/onnx2tf/blob/main/replace.json
The reason why the It would be hard to blindly examine the wrong areas, so if I were you, I would venture to generate a fixed-resolution RetinaFace model and compare its structure with the model with None. This will make it easier to understand to some extent where If I get enough time during the holidays I will check out the model too. |
Issue Type
Others
OS
Linux
onnx2tf version number
1.18.1
onnx version number
1.14.1
onnxruntime version number
1.16.0
onnxsim (onnx_simplifier) version number
0.4.31
tensorflow version number
2.14.0
Download URL for ONNX
https://drive.google.com/file/d/1XIRHjWYzWHwsZXOgcT4RLOJ6kxXE1BVT/view?usp=share_link
Parameter Replacement JSON
Unclear which parameters need replacement.
Description
Hi @PINTO0309, thanks for the great tool and all of your hard work.
I'm trying to convert a custom model from
onnx
totensorflow
totfjs
with a dynamic input shape and am having problems.As an example, take the
mobilenet0.25_Final.pth
model from https://github.com/biubug6/Pytorch_Retinaface.I'm converting from
pytorch
toonnx
using the following (where theRetinaFace
definition comes from here):I check that the
onnx
model works on the python side with the following:I then convert the
onnx
model totf
using:onnx2tf -i retinaface.onnx -osd -o retinaface_tf -cotof
When running the above, the following is the first shape issue I have:
INFO: onnx_output_name: wa/fpn/Shape_3_output_0 tf_output_name: tf.compat.v1.shape/wa/fpn/Shape_3:0 shape: (4,) dtype: int64 validate_result: Skipped (Deleted or Shape Unmatched)
Beyond a number of errors / warnings like these, the model converts successfully, but when using it in my
tfjs
-based system (after converting withtensorflowjs_converter
) I get the following shape mismatch at inference time:If remove the
dynamic_axes
, things work fine at the fixed input size. There are a number of layers with the[1,28,28,64]
shape, so it's been challenging to track down which is the problematic layer.FWIW, I've also tried wit the
-kat
and-nuo
options.This error doesn't happen during this workflow, but does the
Alternatively, if the input OP has a dynamic dimension, use the
-bor
-oisoption to rewrite it to a static shape and try again.
error message appearing in other places mean that dynamic shapes are not supported? Based on your recent commits I assume that they are indeed supported in some way.Is there simply a need for a parameter replacement in my case or am I hitting an edge case in dynamic inputs somehow? Any guidance would be appreciated. Please let me know if more information / models would be helpful - I will provide what I can.
The text was updated successfully, but these errors were encountered: