onnx / onnx-tensorflow

Tensorflow Backend for ONNX
Other
1.27k stars 296 forks source link

Fail to convert model from onnx to .pb #988

Open arseniymerkulov opened 2 years ago

arseniymerkulov commented 2 years ago

Describe the bug

I have onnx model converted from pytorch. I want to convert it to .pb via onnx_tf. Then i get following error: RuntimeError: Resize coordinate_transformation_mode=pytorch_half_pixel is not supported in Tensorflow. Looks like my problem is similair to this https://github.com/onnx/onnx-tensorflow/issues/632, but proposed solutions isnt working for me. From reading this:

  1. lowering opset version to 9 in onnx.export
  2. changing 'align_corners' property to True in torch.nn.Upsample while building model in pytorch should fix the problem

pytorch model comes to me like a black box and i cant change inner structure or tensor properties. Also, model uses dynamic padding and lowering version from 11 to 9-10 leads to this error: RuntimeError: Unsupported: ONNX export of Pad in opset 9. The sizes of the padding must be constant. Please try opset version 11. Because of this, i dont know how to apply proposed solutions in my case.

To Reproduce pytorch_half_pixel error occurs while executing following code (in func prepare):

from onnx_tf.backend import prepare
import onnx

onnx_model = onnx.load('model.onnx')

tf_rep = prepare(onnx_model)
tf_rep.export_graph('model.pb')

ONNX model file https://drive.google.com/file/d/147eZku7KXDFFD_oauijQMZKZ2-UdRTtq/view?usp=sharing

Python, ONNX, ONNX-TF, Tensorflow version

How can solve this problem? Thanks in advance

Arka161 commented 2 years ago

Were you able to find a solution?

arseniymerkulov commented 2 years ago

I successfully converted another model, nvidia ssd, which apparently doesent have Resize\Upsample layer. But with this model i have no progress