Closed saraphinesER closed 3 months ago
The structure of the ONNX file is broken before it can be converted by onnx2tf. Models that cannot be inferenced with onnxruntime should not be used.
sit4onnx -if best_bkuped.onnx -oep cpu
Traceback (most recent call last):
File "/home/xxxx/.local/bin/sit4onnx", line 8, in <module>
sys.exit(main())
File "/home/xxxx/.local/lib/python3.10/site-packages/sit4onnx/onnx_inference_test.py", line 506, in main
final_results = inference(
File "/home/xxxx/.local/lib/python3.10/site-packages/sit4onnx/onnx_inference_test.py", line 241, in inference
onnx_session = onnxruntime.InferenceSession(
File "/home/xxxx/.local/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in __init__
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/home/xxxx/.local/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 472, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : Load model from best_bkuped.onnx failed:This is an invalid model. Type Error: Type 'tensor(float)' of input parameter (/Mul_3_output_0) of operator (Equal) in node (/Equal) is invalid.
onnxsim best_bkuped.onnx best_bkuped.onnx
Your model contains "Tile" ops or/and "ConstantOfShape" ops. Folding these ops can make the simplified model much larger. If it is not expected, please specify "--no-large-tensor" (which will lose
some optimization chances)
Simplifying...
Traceback (most recent call last):
File "/home/xxxx/.local/bin/onnxsim", line 8, in <module>
sys.exit(main())
File "/home/xxxx/.local/lib/python3.10/site-packages/onnxsim/onnx_simplifier.py", line 481, in main
model_opt, check_ok = simplify(
File "/home/xxxx/.local/lib/python3.10/site-packages/onnxsim/onnx_simplifier.py", line 199, in simplify
model_opt_bytes = C.simplify(
File "/home/xxxx/.local/lib/python3.10/site-packages/onnxsim/onnx_simplifier.py", line 252, in Run
sess = rt.InferenceSession(
File "/home/xxxx/.local/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in __init__
self._create_inference_session(providers, provider_options, disabled_optimizers)
File "/home/xxxx/.local/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 474, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_bytes, False, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : This is an invalid model. Type Error: Type 'tensor(float)' of input parameter (/Mul_3_output_0) of operator (Equal) in node (/Equal) is invalid.
Thanks for analysis and reply. Does this mean I do something wrong when export to ONNX model from pytorch? It's upset that seems I have to check more on ONNX details to realize where cause the issues. If it's not too much trouble, please give hints or guide if you probably knew or saw this kind of errors before. Still appreciate your comment, I will keep trying to check if I can find root cause to fix this INVALID_GRAPH.
Remove from PyTorch's logic the preprocessing that prevents shape estimation at these two locations. No meaningless and redundant processes should be left behind.
Hi, sorry for late to response. Actually I saw your guide after you post while not fully understand how to do by your hint as I am a newbie. Then I tried to search around but still not know the direction to try, as you said "preprocessing that prevents shape estimation". Currently I can only share the pytorch model and json file, I am not sure if this helps. Just if it's not too much trouble, please give some hints or even some keywords that could help me to find some examples to learn more about the debug or direction to try & error. Thanks again for your kindly help on analysis. pytorch model history-json
If you share only .pth with me, I can't advise you on anything. Because the problem is the design of the model you used for your training. The ConstantOfShape [112]
part should be a constant. However, depending on how the PyTorch logic is written, it may not generate ONNX correctly.
For example, statements such as x.shape[0]
and x.shape[1]
cause major problems. You might want to reconsider whether you really need the NoneZero
, Sin
, Div
, Where
syntax. NonZero
is the most cancerous.
I assure you. Models with NonZero
are garbage.
Frankly, it's quite a hassle to have to imagine everything and deal with you. I am not a free PyTorch advisor.
Hi, PINTO0309, certainly you don't have to do so much. I am always appreciated to people who are willing to share and guide. Just there's a little misunderstanding here, I didn't mean to share a .pth model and make you confused. Let me explain a little more, actually this is a pytorch model from Facebook research in 2020, and the training script is as https://github.com/facebookresearch/denoiser/blob/main/train.py which I left in item-5 when raising question. I took this model to do some study and practice for Facebook sounds somehow representative. This reply is just for doing some clarification. You don't have to reply since it's already bothering you. I will try to check the hints above from you. Thanks again for your kindly guide during past couple days.
Issue Type
Others
OS
Windows
onnx2tf version number
1.20.0
onnx version number
1.16,0
onnxruntime version number
1.17.1
onnxsim (onnx_simplifier) version number
0.4.33
tensorflow version number
2.13.0
Download URL for ONNX
https://drive.google.com/file/d/1RQ-hO8f9UIGvrSLVv2SCvCFXVSA1zJ2H/view?usp=drive_link
Parameter Replacement JSON
Description
param_replacement_file=PROJ_PATH + r'\outputs\replace.json'
ERROR message
Original I tried onnx-tensorflow(onnx_tf.backend) and it failed, then I found here and this approach seems more flexible and compatible, so I am really wondering I can correct use and make it work since I have several pytorch model needs to deploy with Tflite model. Thanks for your patience. I will be looking forward your guide to correctly convert ONNX to TFLite.