onnx / onnx-tensorflow

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

Conversion from TF to ONNX stops, throwing KeyError 20 #299

Open siddas27 opened 6 years ago

siddas27 commented 6 years ago

I am trying to convert tensorflow model for to ONNX using .ckpt file with CLI. But after the variables are converted to const it stops, throwing following KeyError :20

INFO:root:Start converting tf pb to onnx pb:
2018-10-22 15:52:54.904518: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
INFO:tensorflow:Restoring parameters from ./inference_graph/model.ckpt
INFO:tensorflow:Restoring parameters from ./inference_graph/model.ckpt
INFO:tensorflow:Froze 357 variables.
INFO:tensorflow:Froze 357 variables.
INFO:tensorflow:Converted 357 variables to const ops.
INFO:tensorflow:Converted 357 variables to const ops.
/home/surendra/onnx-tensorflow/onnx_tf/handlers/handler.py:35: UserWarning: Pack doesn't have ONNX_OP. Please use Handler.onnx_op decorator to register ONNX_OP.
  cls.__name__))
/home/surendra/onnx-tensorflow/onnx_tf/common/handler_helper.py:37: UserWarning: Unknown op Undefined in domain `ai.onnx`. Can't check specification by ONNX. Please set should_check flag to False when call make_node method in handler.
  "ai.onnx"))
/home/surendra/onnx-tensorflow/onnx_tf/handlers/handler.py:35: UserWarning: Relu6 doesn't have ONNX_OP. Please use Handler.onnx_op decorator to register ONNX_OP.
  cls.__name__))
/home/surendra/onnx-tensorflow/onnx_tf/common/handler_helper.py:37: UserWarning: Unknown op DynamicSlice in domain `ai.onnx`. Can't check specification by ONNX. Please set should_check flag to False when call make_node method in handler.
  "ai.onnx"))
/home/surendra/onnx-tensorflow/onnx_tf/handlers/handler.py:35: UserWarning: Unpack doesn't have ONNX_OP. Please use Handler.onnx_op decorator to register ONNX_OP.
  cls.__name__))
Traceback (most recent call last):
  File "/home/surendra/.local/bin/onnx-tf", line 11, in <module>
    load_entry_point('onnx-tf', 'console_scripts', 'onnx-tf')()
  File "/home/surendra/onnx-tensorflow/onnx_tf/cli.py", line 17, in main
    return onnx_tf.converter.main(args[1:])
  File "/home/surendra/onnx-tensorflow/onnx_tf/converter.py", line 20, in main
    convert(**{k: v for k, v in vars(args).items() if v is not None})
  File "/home/surendra/onnx-tensorflow/onnx_tf/converter.py", line 183, in convert
    graph_def, get_output_node_names(graph_def), **kwargs)
  File "/home/surendra/onnx-tensorflow/onnx_tf/frontend.py", line 160, in tensorflow_graph_to_onnx_model
    graph_def, output_nodes, opset, graph_name, ignore_unimplemented)
  File "/home/surendra/onnx-tensorflow/onnx_tf/frontend.py", line 67, in tensorflow_graph_to_onnx_graph
    node_tup = [(node.name, TensorflowNode(node)) for node in graph_def.node]
  File "/home/surendra/onnx-tensorflow/onnx_tf/frontend.py", line 67, in <listcomp>
    node_tup = [(node.name, TensorflowNode(node)) for node in graph_def.node]
  File "/home/surendra/onnx-tensorflow/onnx_tf/pb_wrapper.py", line 34, in __init__
    self._load_tf_node(node)
  File "/home/surendra/onnx-tensorflow/onnx_tf/pb_wrapper.py", line 51, in _load_tf_node
    new_val = attr_translator.translate_tf(key, val)
  File "/home/surendra/onnx-tensorflow/onnx_tf/common/attr_translator.py", line 28, in translate_tf
    return __tf_attr_translator.get(key, lambda x: x)(val)
  File "/home/surendra/onnx-tensorflow/onnx_tf/common/attr_translator.py", line 9, in <lambda>
    "T": lambda x: data_type.tf2onnx(list(x.list.type) or x.type),
  File "/home/surendra/onnx-tensorflow/onnx_tf/common/data_type.py", line 28, in tf2onnx
    return mapping.NP_TYPE_TO_TENSOR_TYPE[np.dtype(tf_dype.as_numpy_dtype)]
  File "/home/surendra/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py", line 128, in as_numpy_dtype
    return _TF_TO_NP[self._type_enum]
KeyError: 20

Python, ONNX, ONNX-TF, Tensorflow version

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

fumihwh commented 6 years ago

@siddas27 Did you install onnx-tf by pip install onnx-tf or from source? If is the former, could you try install from source by pip install .?

tjingrant commented 6 years ago

@siddas27 also do you mind sharing your model with us so we can do a test locally to re-produce your error?

siddas27 commented 6 years ago

@fumihwh yeah, I have installed from source only. @tjingrant faster rcnn inception v2 model.

fumihwh commented 6 years ago

@siddas27 KeyError 20 problem has been fixed.

friendshipity commented 5 years ago

@fumihwh yeah, I have installed from source only. @tjingrant faster rcnn inception v2 model.

same problem How did you solve this?