onnx / onnx-tensorflow

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

IndexError: list index out of range #390

Open destindof opened 5 years ago

destindof commented 5 years ago

Describe the bug

When I try to convert the TensorFlow in pb format to ONNX model using the command onnx-tf convert -t onnx -i mobilenet_v2_1.4_224_frozen.pb -o output.onnx

The error shows up: INFO:root:Start converting tf pb to onnx pb: 2019-03-06 16:35:48.043052: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA Traceback (most recent call last): File "/home/ycxu/.local/bin/onnx-tf", line 11, in load_entry_point('onnx-tf', 'console_scripts', 'onnx-tf')() File "/home/ycxu/onnx-tensorflow-master/onnx_tf/cli.py", line 22, in main return onnx_tf.converter.main(args[1:]) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/converter.py", line 24, in main convert({k: v for k, v in vars(args).items() if v is not None}) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/converter.py", line 249, in convert onnx_model = frontend.tensorflow_graph_to_onnx_model(graph_def, kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/frontend.py", line 145, in tensorflow_graph_to_onnx_model ignore_unimplemented, optimizer_passes) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/frontend.py", line 158, in _make_onnx_model ignore_unimplemented) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/frontend.py", line 93, in tensorflow_graph_to_onnx_graph data_type_cast_map=onnx_graph.data_type_cast_map) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend_handler.py", line 41, in handle return super(FrontendHandler, cls).handle(node, kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/handler.py", line 60, in handle return ver_handle(node, kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend/convolution.py", line 32, in version_1 return cls.conv_op(node, d=d, **kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend/conv_mixin.py", line 30, in conv_op spatial_indices)) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend/conv_mixin.py", line 29, in map(lambda i: node_dict[node.inputs[0]].attr["_output_shapes"][0][i], IndexError: list index out of range

ONNX model file Downloaded at https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.4_224.tgz

Python, ONNX, ONNX-TF, Tensorflow version

Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]

fumihwh commented 5 years ago

@destindof The original graph doesn't have shape information. pb_wrapper.py L139. Replace _add_infer_shapes with following.

  @staticmethod
  def _add_infer_shapes(graph_def, input_shape=[1, 224, 224, 3]):
    with tf.Graph().as_default():
      with tf.Session(
          config=tf.ConfigProto(
              graph_options=tf.GraphOptions(infer_shapes=True))) as sess:
        if input_shape:
          input_node = [
              node for node in graph_def.node if node.name == "input"
          ][0]
          for i in input_shape:
            dim = TensorShapeProto.Dim()
            dim.size = i
            input_node.attr["shape"].shape.dim.extend([dim])
        tf.import_graph_def(graph_def, name="")
      return sess.graph_def
destindof commented 5 years ago

@fumihwh Thank you for your reply! But... You may not notice that name 'TensorShapeProto' is not defined in 'dim = TensorShapeProto.Dim()'.

XUYUNYUN666 commented 4 years ago

Describe the bug

When I try to convert the TensorFlow in pb format to ONNX model using the command onnx-tf convert -t onnx -i mobilenet_v2_1.4_224_frozen.pb -o output.onnx

The error shows up: INFO:root:Start converting tf pb to onnx pb: 2019-03-06 16:35:48.043052: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA Traceback (most recent call last): File "/home/ycxu/.local/bin/onnx-tf", line 11, in load_entry_point('onnx-tf', 'console_scripts', 'onnx-tf')() File "/home/ycxu/onnx-tensorflow-master/onnx_tf/cli.py", line 22, in main return onnx_tf.converter.main(args[1:]) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/converter.py", line 24, in main convert({k: v for k, v in vars(args).items() if v is not None}) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/converter.py", line 249, in convert onnx_model = frontend.tensorflow_graph_to_onnx_model(graph_def, kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/frontend.py", line 145, in tensorflow_graph_to_onnx_model ignore_unimplemented, optimizer_passes) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/frontend.py", line 158, in _make_onnx_model ignore_unimplemented) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/frontend.py", line 93, in tensorflow_graph_to_onnx_graph data_type_cast_map=onnx_graph.data_type_cast_map) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend_handler.py", line 41, in handle return super(FrontendHandler, cls).handle(node, kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/handler.py", line 60, in handle return ver_handle(node, kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend/convolution.py", line 32, in version_1 return cls.conv_op(node, d=d, **kwargs) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend/conv_mixin.py", line 30, in conv_op spatial_indices)) File "/home/ycxu/onnx-tensorflow-master/onnx_tf/handlers/frontend/conv_mixin.py", line 29, in map(lambda i: node_dict[node.inputs[0]].attr["_output_shapes"][0][i], IndexError: list index out of range

ONNX model file Downloaded at https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.4_224.tgz

Python, ONNX, ONNX-TF, Tensorflow version

  • Python version:

Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]

  • ONNX version: 1.3.0
  • ONNX-TF version: 1.2.1
  • Tensorflow version: 1.12.0

你解决了吗

fumihwh commented 4 years ago

@destindof Maybe the code is incorrect, I just want to say you should add shape to input_node.