Skip to content
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

Onnx to Tensorflow, model becomes too complicated. #515

Open
Maximilianxu opened this issue Oct 17, 2019 · 12 comments
Open

Onnx to Tensorflow, model becomes too complicated. #515

Maximilianxu opened this issue Oct 17, 2019 · 12 comments

Comments

@Maximilianxu
Copy link

Hi to all. As indicated by the title, I have some questions.
The following is the onnx graph.
onnx_graph
The following is the tensorflow graph converted from onnx.
tf_graph
I have some questions on the latter graph.

  1. The second maxpool operator is very complicated and a SparseToDense operator was added to the graph. This is the most confusing part for me. Why does a dense model have a SparseToDense operation? As I want to use TVM to compile this model which does not support SparseToDense, I am stucking at this position...
  2. The output node was missing.
@arnaudbrejeon
Copy link

I have similar issue with missing output node and I don't know how to solve it

@andreydung
Copy link

Second this too. It seems that they're trying to handle conversion from NCHW in ONNX to NHWC in tensorflow?

@jspyth
Copy link

jspyth commented Nov 29, 2019

I have same problem with it,how to solve it?

@JiayiFu
Copy link

JiayiFu commented Nov 30, 2019

About the problem: the output graph is too complicated. I guess that use the onnx node name as TensorFlow name scope may make the graph more readable... #524

@fumihwh
Copy link
Collaborator

fumihwh commented Dec 2, 2019

The reason is ONNX support 0 value in shape (second input) of Reshape which means unchanged.
https://github.com/onnx/onnx/blob/master/docs/Operators.md#reshape
In tf, no mechanism like that, so we add some codes to support such case.

For an ad-hoc fix, you can comment out onnx_tf/handlers/backend/reshape.py L25 - L36, and modify L39 to node, inputs=[tensor, shape], attrs=attrs, **kwargs).

@jakubondrus
Copy link

@Maximilianxu did you manage to solve 2nd problem? Seems like there are multiple reported issues on this topic but can't find any answer. (trying to convert arcface model from onnx model zoo)

image

@Maximilianxu
Copy link
Author

@jakubondrus No. I gave up onnx that time.

@fumihwh
Copy link
Collaborator

fumihwh commented Mar 8, 2020

@jakubondrus
BTW,

  1. which tf version you are using?
  2. What is the name of const node at the bottom of the graph?

@jakubondrus
Copy link

@fumihwh

  1. TF 2.X (I don't know what was the newest tf version at time I was dealing with this). Onnx-tf was installed from git project.
  2. If you mean that last black AddV2 node, it's name is fc1 (the same name as node that is last before output node in onnx model). If you mean that const nodes, they have names like Const_1, Const_2, ... and concat/concat_dim, concat_1/concat_dim, ...

@fumihwh
Copy link
Collaborator

fumihwh commented Mar 11, 2020

@jakubondrus Maybe we could add following code as post processing. Before that, you could try this locally.

def optimize_graph_def(graph_def, input_names, output_names):
  from tensorflow.tools.graph_transforms import TransformGraph
  transforms = [
    'remove_nodes(op=Identity)',
    'strip_unused_nodes',
    'fold_batch_norms',
    'fold_constants(ignore_errors=true)',
  ]
  optimized_graph_def = TransformGraph(graph_def, input_names, output_names,
                                       transforms)
  return optimized_graph_def

@jakubondrus
Copy link

@fumihwh I am sorry for late answer, didn't get to that immediately adn then forgot about it. Where am I supposed to put that code?

@dimitraka
Copy link

Is there any solution of this issue finally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants