onnx-tensorflow icon indicating copy to clipboard operation
onnx-tensorflow copied to clipboard

Fail to convert model from onnx to .pb

Open arseniymerkulov opened this issue 4 years ago • 2 comments

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

  • Python version: 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)]
  • ONNX version: 1.10.2
  • ONNX-TF version: 1.9.0
  • Tensorflow version: 2.5.0

How can solve this problem? Thanks in advance

arseniymerkulov avatar Nov 17 '21 10:11 arseniymerkulov

Were you able to find a solution?

Arka161 avatar Dec 01 '21 16:12 Arka161

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

arseniymerkulov avatar Dec 01 '21 18:12 arseniymerkulov