onnx / onnx-tensorflow

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

Mismatched attribute type in ' : kernel_shape' #694

Open duchengyao opened 4 years ago

duchengyao commented 4 years ago

When running OnnxTensorflowImport.ipynb

import onnx
import warnings
from onnx_tf.backend import prepare

warnings.filterwarnings('ignore') # Ignore all the warning messages in this tutorial
model = onnx.load('assets/super_resolution.onnx') # Load the ONNX file
tf_rep = prepare(model) # Import the ONNX model to Tensorflow
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-1-2aa043b56652> in <module>
      5 warnings.filterwarnings('ignore') # Ignore all the warning messages in this tutorial
      6 model = onnx.load('assets/super_resolution.onnx') # Load the ONNX file
----> 7 tf_rep = prepare(model) # Import the ONNX model to Tensorflow

~/project/ONNX/onnx-tensorflow/onnx_tf/backend.py in prepare(cls, model, device, strict, logging_level, **kwargs)
     60     :returns: A TensorflowRep class object representing the ONNX model
     61     """
---> 62     super(TensorflowBackend, cls).prepare(model, device, **kwargs)
     63     common.logger.setLevel(logging_level)
     64     common.logger.handlers[0].setLevel(logging_level)

~/.pyenv/versions/anaconda3-2020.02/lib/python3.7/site-packages/onnx/backend/base.py in prepare(cls, model, device, **kwargs)
     72                 ):  # type: (...) -> Optional[BackendRep]
     73         # TODO Remove Optional from return type
---> 74         onnx.checker.check_model(model)
     75         return None
     76 

~/.pyenv/versions/anaconda3-2020.02/lib/python3.7/site-packages/onnx/checker.py in check_model(model, full_check)
     91         m = onnx.load(model)
     92     else:
---> 93         C.check_model(model.SerializeToString())
     94         m = model
     95     if full_check:

ValidationError: Mismatched attribute type in ' : kernel_shape'

==> Context: Bad node spec: input: "1" input: "2" output: "11" op_type: "Conv" attribute { name: "kernel_shape" ints: 5 ints: 5 } attribute { name: "strides" ints: 1 ints: 1 } attribute { name: "pads" ints: 2 ints: 2 ints: 2 ints: 2 } attribute { name: "dilations" ints: 1 ints: 1 } attribute { name: "group" i: 1 }

Now we have tf_rep, which is a python class containing four members: graph, inputs, outputs, and tensor_dict.

Python, ONNX, ONNX-TF, Tensorflow version

This section can be obtained by running get_version.py from util folder.

chinhuang007 commented 4 years ago

Looks like the onnx file doesn't pass the standard onnx checker, which is invoked by the onnx-tf prepare API.

You could just run onnx checker as below. If you see the same error, it means the onnx file is incorrectly constructed.

import onnx
model = onnx.load('assets/super_resolution.onnx')
onnx.checker.check_model(model)
rallen10 commented 4 years ago

I was running into a similar (perhaps the exact same) problem. If I remember correctly, my fix involved installing the current master branch on ONNX-TF instead of 1.7.0. pip install git+https://github.com/onnx/onnx-tensorflow