onnx / keras-onnx

Convert tf.keras/Keras models to ONNX
Apache License 2.0
381 stars 109 forks source link

'NoneType' object has no attribute 'get_node_by_output' #224

Open stiv-yakovenko opened 5 years ago

stiv-yakovenko commented 5 years ago

Trying to convert model from keras .h5 file to .onnx:

import tensorflow as tf
import keras as K
import uff
import keras2onnx
file_path = 'lpr.h5'
sess = tf.Session(config=tf.ConfigProto())
K.backend.tensorflow_backend.set_session(sess)
K.backend.tensorflow_backend.set_learning_phase(0)
model = K.models.load_model(file_path, compile=False)
keras2onnx.convert_keras(model, model.name)

I get this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/ktf2onnx/tf2onnx/tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/ktf2onnx/tf2onnx/onnx_opset/tensor.py", line 1396, in version_10
    , "ReverseSequence batch size for axis {} is unknown".format(axis))
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/ktf2onnx/tf2onnx/utils.py", line 290, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: ReverseSequence batch size for axis 1 is unknown

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/stiv/lpr/convert_keras_to_uff.py", line 14, in <module>
    keras2onnx.convert_keras(model, model.name)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/main.py", line 102, in convert_keras
    parse_graph(topology, sess.graph, target_opset, output_names)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/parser.py", line 667, in parse_graph
    return _parse_graph_scope(graph, keras_layer_ts_map, topo, top_level, output_names)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/parser.py", line 626, in _parse_graph_scope
    _infer_graph_shape(topology, top_scope, varset)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/parser.py", line 389, in _infer_graph_shape
    _finalize_tf2onnx_op(topology, oop, varset)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/parser.py", line 359, in _finalize_tf2onnx_op
    g = tf2onnx_wrap(topo, subgraph, outputs, varset.target_opset)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/wrapper.py", line 32, in tf2onnx_wrap
    raise e
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/wrapper.py", line 26, in tf2onnx_wrap
    output_names=outputs)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/ktf2onnx/tf2onnx/tfonnx.py", line 571, in process_tf_graph
    mapped_op, unmapped_op, exceptions = tensorflow_onnx_mapping(g, ops_mapping)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/ktf2onnx/tf2onnx/tfonnx.py", line 355, in tensorflow_onnx_mapping
    logger.error("Failed to convert node %s\n%s", node.name, node.summary, exc_info=1)
  File "/usr/local/lib/python3.6/dist-packages/keras2onnx-1.5.2-py3.6.egg/keras2onnx/ktf2onnx/tf2onnx/graph.py", line 172, in summary
    node = g.get_node_by_output(name)
AttributeError: 'NoneType' object has no attribute 'get_node_by_output'

how do I fix these two errors, is that possible?

jiafatom commented 5 years ago

Can you share the model or script for us to debug?

stiv-yakovenko commented 5 years ago

https://drive.google.com/file/d/1IxPFgQO-7icao2ubgNpiJoTN0nX0aF44/view?usp=sharing

jiafatom commented 5 years ago

This model contains CuDNNGRU layer, we don't support it now. There is no plan for this in near future.