onnx / keras-onnx

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

'NoneType' object has no attribute 'output_tensors' when converting keras_retinanet model #256

Open mrtgenet opened 5 years ago

mrtgenet commented 5 years ago

Hello,

I am working with python 3.6, tensorflow-gpu 1.13, keras-gpu 2.2, onnx 1.6 and pip-installed keras2onnx 1.5.2.

I'm fresh with onnx and I wanted to try with a keras_retinanet model which I trained myself using https://github.com/fizyr/keras-retinanet with default resnet50 backbone.

My code is as follows:

from keras_retinanet import models
import keras2onnx
import onnx

model_path = 'my_model.h5'
model = models.load_model(model_path, backbone_name='resnet50')
onnx_model = keras2onnx.convert_keras(model, model.name)
onnx.save_model(onnx_model, 'onnx_model.onnx')

And the error I get is:

Traceback (most recent call last):
    onnx_model = keras2onnx.convert_keras(model, model.name, target_opset=10)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx\main.py", line 98, in convert_keras
    parse_graph(topology, sess.graph, target_opset, output_names)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx\parser.py", line 736, in parse_graph
    return _parse_graph_scope(graph, keras_layer_ts_map, topo, top_level, output_names)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx\parser.py", line 648, in _parse_graph_scope
    ts_in, ts_out = _on_parsing_model_layer(layer_key_, graph, kenode, varset)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx\parser.py", line 295, in _on_parsing_model_layer
    bn_name_list = [bn_.name for bn_ in list_output_tensors(base_node)]

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx\ke2onnx\main.py", line 55, in list_output_tensors
    return [node.output_tensors] if hasattr(node.output_tensors, 'dtype') else node.output_tensors

AttributeError: 'NoneType' object has no attribute 'output_tensors'

Do I miss some simple trick to make it work or is there a problem with custom retinanet model ?

Thanks for help :)

jiafatom commented 5 years ago

This seems the same issue as here. Can you check there to see if it makes sense?

mrtgenet commented 5 years ago

Hi, I saw that issue, and the model is the same structure, but the error seems slightly different to me.

Anyway, I tried uninstall keras2onnx and install it from cloned repo and run same conversion script again, which outputs me a quite long message :

Failed to convert node TFNodes/filtered_detections/map/while/PadV2_2
OP=Pad
Name=TFNodes/filtered_detections/map/while/PadV2_2
Inputs:
        TFNodes/filtered_detections/map/while/embedding_lookup_14/Identity:0=Identity, [-1], 7
        TFNodes/filtered_detections/map/while/PadV2_2/paddings_Concat__1329:0=Concat, [1, 2], 6
        TFNodes/filtered_detections/map/while/PadV2_2/constant_values:0=Const, [], 7
Outpus:
        TFNodes/filtered_detections/map/while/PadV2_2:0=[-1], 7
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\onnx_opset\nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\graph.py", line 257, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))
ValueError: get tensor value: TFNodes/filtered_detections/map/while/PadV2_2/paddings_Concat__1329 must be Const
Failed to convert node TFNodes/filtered_detections/map/while/PadV2
OP=Pad
Name=TFNodes/filtered_detections/map/while/PadV2
Inputs:
        TFNodes/filtered_detections/map/while/embedding_lookup_13/Identity:0=Identity, [-1, 4], 1
        TFNodes/filtered_detections/map/while/PadV2/paddings_Concat__1340:0=Concat, [2, 2], 6
        TFNodes/filtered_detections/map/while/PadV2/constant_values:0=Const, [], 1
Outpus:
        TFNodes/filtered_detections/map/while/PadV2:0=[-1, -1], 1
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\onnx_opset\nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\graph.py", line 257, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))
ValueError: get tensor value: TFNodes/filtered_detections/map/while/PadV2/paddings_Concat__1340 must be Const
Failed to convert node TFNodes/filtered_detections/map/while/PadV2_1
OP=Pad
Name=TFNodes/filtered_detections/map/while/PadV2_1
Inputs:
        TFNodes/filtered_detections/map/while/TopKV2:0=TopK, [-1], 1
        TFNodes/filtered_detections/map/while/PadV2_1/paddings_Concat__1334:0=Concat, [1, 2], 6
        TFNodes/filtered_detections/map/while/PadV2_1/constant_values:0=Const, [], 1
Outpus:
        TFNodes/filtered_detections/map/while/PadV2_1:0=[-1], 1
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\onnx_opset\nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\graph.py", line 257, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))
ValueError: get tensor value: TFNodes/filtered_detections/map/while/PadV2_1/paddings_Concat__1334 must be Const
Exception on this tf.graph
TFNodes/filtered_detections/map/TensorArrayStack/range/start
TFNodes/filtered_detections/map/TensorArrayStack/range/delta
TFNodes/filtered_detections/map/TensorArrayStack_2/range/start
TFNodes/filtered_detections/map/TensorArrayStack_2/range/delta
TFNodes/filtered_detections/map/TensorArrayStack_1/range/start
TFNodes/filtered_detections/map/TensorArrayStack_1/range/delta
TFNodes/filtered_detections/map/strided_slice/stack
TFNodes/filtered_detections/map/strided_slice/stack_1
TFNodes/filtered_detections/map/strided_slice/stack_2
TFNodes/filtered_detections/map/while/PadV2/constant_values
TFNodes/filtered_detections/map/while/PadV2_1/constant_values
TFNodes/filtered_detections/map/while/PadV2/paddings/1_1
TFNodes/filtered_detections/map/while/iteration_counter
TFNodes/filtered_detections/map/while/Enter
TFNodes/filtered_detections/map/while/Merge
TFNodes/filtered_detections/map/Const
TFNodes/filtered_detections/map/while/Enter_1
TFNodes/filtered_detections/map/while/Merge_1
TFNodes/filtered_detections/map/while/PadV2_2/constant_values
TFNodes/filtered_detections/map/while/embedding_lookup_13/axis
TFNodes/filtered_detections/map/while/PadV2/paddings/0/0
TFNodes/filtered_detections/map/while/add/y
TFNodes/filtered_detections/map/while/add_1/y
TFNodes/filtered_detections/map/while/Minimum/x
TFNodes/filtered_detections/map/while/PadV2_1/paddings/0/0
TFNodes/filtered_detections/map/while/Maximum/x
TFNodes/filtered_detections/map/while/embedding_lookup_14/axis
TFNodes/filtered_detections/map/while/PadV2_2/paddings/0/0
TFNodes/filtered_detections/map/while/concat/axis
TFNodes/filtered_detections/map/while/strided_slice_25/stack
TFNodes/filtered_detections/map/while/strided_slice_25/stack_1
TFNodes/filtered_detections/map/while/strided_slice_25/stack_2
TFNodes/filtered_detections/map/while/embedding_lookup_12/axis
TFNodes/filtered_detections/map/while/sub/x
TFNodes/filtered_detections/map/while/strided_slice_24/stack
TFNodes/filtered_detections/map/while/strided_slice_24/stack_1
TFNodes/filtered_detections/map/while/strided_slice_24/stack_2
TFNodes/filtered_detections/map/while/strided_slice_26/stack
TFNodes/filtered_detections/map/while/strided_slice_26/stack_1
TFNodes/filtered_detections/map/while/strided_slice_26/stack_2
TFNodes/filtered_detections/map/while/strided_slice_27/stack
TFNodes/filtered_detections/map/while/strided_slice_27/stack_1
TFNodes/filtered_detections/map/while/strided_slice_27/stack_2
TFNodes/filtered_detections/map/while/strided_slice_3/stack
TFNodes/filtered_detections/map/while/strided_slice_3/stack_1
TFNodes/filtered_detections/map/while/strided_slice_3/stack_2
TFNodes/filtered_detections/map/while/strided_slice_7/stack
TFNodes/filtered_detections/map/while/strided_slice_7/stack_1
TFNodes/filtered_detections/map/while/strided_slice_7/stack_2
TFNodes/filtered_detections/map/while/strided_slice_11/stack
TFNodes/filtered_detections/map/while/strided_slice_11/stack_1
TFNodes/filtered_detections/map/while/strided_slice_11/stack_2
TFNodes/filtered_detections/map/while/strided_slice_15/stack
TFNodes/filtered_detections/map/while/strided_slice_15/stack_1
TFNodes/filtered_detections/map/while/strided_slice_15/stack_2
TFNodes/filtered_detections/map/while/strided_slice_19/stack
TFNodes/filtered_detections/map/while/strided_slice_19/stack_1
TFNodes/filtered_detections/map/while/strided_slice_19/stack_2
TFNodes/filtered_detections/map/while/strided_slice_23/stack
TFNodes/filtered_detections/map/while/strided_slice_23/stack_1
TFNodes/filtered_detections/map/while/strided_slice_23/stack_2
TFNodes/filtered_detections/map/TensorArrayUnstack/range/start
TFNodes/filtered_detections/map/TensorArrayUnstack/range/delta
TFNodes/filtered_detections/map/TensorArrayUnstack_1/range/start
TFNodes/filtered_detections/map/TensorArrayUnstack_1/range/delta
TFNodes/filtered_detections/map/while/mul/x
TFNodes/filtered_detections/map/while/mul_1/x
TFNodes/filtered_detections/map/while/mul_2/x
TFNodes/filtered_detections/map/while/mul_3/x
TFNodes/filtered_detections/map/while/mul_4/x
TFNodes/filtered_detections/map/while/mul_5/x
TFNodes/filtered_detections/map/TensorArrayUnstack/strided_slice/stack
TFNodes/filtered_detections/map/TensorArrayUnstack/strided_slice/stack_1
TFNodes/filtered_detections/map/TensorArrayUnstack/strided_slice/stack_2
TFNodes/filtered_detections/map/TensorArrayUnstack_1/strided_slice/stack
TFNodes/filtered_detections/map/TensorArrayUnstack_1/strided_slice/stack_1
TFNodes/filtered_detections/map/TensorArrayUnstack_1/strided_slice/stack_2
TFNodes/filtered_detections/map/while/embedding_lookup_1/axis
TFNodes/filtered_detections/map/while/ones/Const
TFNodes/filtered_detections/map/while/embedding_lookup_3/axis
TFNodes/filtered_detections/map/while/ones_1/Const
TFNodes/filtered_detections/map/while/embedding_lookup_5/axis
TFNodes/filtered_detections/map/while/ones_2/Const
TFNodes/filtered_detections/map/while/embedding_lookup_7/axis
TFNodes/filtered_detections/map/while/ones_3/Const
TFNodes/filtered_detections/map/while/embedding_lookup_9/axis
TFNodes/filtered_detections/map/while/ones_4/Const
TFNodes/filtered_detections/map/while/embedding_lookup_11/axis
TFNodes/filtered_detections/map/while/ones_5/Const
TFNodes/filtered_detections/map/while/non_max_suppression/NonMaxSuppressionV3/max_output_size
TFNodes/filtered_detections/map/while/non_max_suppression/iou_threshold
TFNodes/filtered_detections/map/while/non_max_suppression/score_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_1/NonMaxSuppressionV3/max_output_size
TFNodes/filtered_detections/map/while/non_max_suppression_1/iou_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_1/score_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_2/NonMaxSuppressionV3/max_output_size
TFNodes/filtered_detections/map/while/non_max_suppression_2/iou_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_2/score_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_3/NonMaxSuppressionV3/max_output_size
TFNodes/filtered_detections/map/while/non_max_suppression_3/iou_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_3/score_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_4/NonMaxSuppressionV3/max_output_size
TFNodes/filtered_detections/map/while/non_max_suppression_4/iou_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_4/score_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_5/NonMaxSuppressionV3/max_output_size
TFNodes/filtered_detections/map/while/non_max_suppression_5/iou_threshold
TFNodes/filtered_detections/map/while/non_max_suppression_5/score_threshold
TFNodes/filtered_detections/map/while/Greater/y
TFNodes/filtered_detections/map/while/strided_slice_2/stack
TFNodes/filtered_detections/map/while/strided_slice_2/stack_1
TFNodes/filtered_detections/map/while/strided_slice_2/stack_2
TFNodes/filtered_detections/map/while/strided_slice_1/stack
TFNodes/filtered_detections/map/while/strided_slice_1/stack_1
TFNodes/filtered_detections/map/while/strided_slice_1/stack_2
TFNodes/filtered_detections/map/while/Greater_1/y
TFNodes/filtered_detections/map/while/strided_slice_6/stack
TFNodes/filtered_detections/map/while/strided_slice_6/stack_1
TFNodes/filtered_detections/map/while/strided_slice_6/stack_2
TFNodes/filtered_detections/map/while/strided_slice_5/stack
TFNodes/filtered_detections/map/while/strided_slice_5/stack_1
TFNodes/filtered_detections/map/while/strided_slice_5/stack_2
TFNodes/filtered_detections/map/while/Greater_2/y
TFNodes/filtered_detections/map/while/strided_slice_10/stack
TFNodes/filtered_detections/map/while/strided_slice_10/stack_1
TFNodes/filtered_detections/map/while/strided_slice_10/stack_2
TFNodes/filtered_detections/map/while/strided_slice_9/stack
TFNodes/filtered_detections/map/while/strided_slice_9/stack_1
TFNodes/filtered_detections/map/while/strided_slice_9/stack_2
TFNodes/filtered_detections/map/while/Greater_3/y
TFNodes/filtered_detections/map/while/strided_slice_14/stack
TFNodes/filtered_detections/map/while/strided_slice_14/stack_1
TFNodes/filtered_detections/map/while/strided_slice_14/stack_2
TFNodes/filtered_detections/map/while/strided_slice_13/stack
TFNodes/filtered_detections/map/while/strided_slice_13/stack_1
TFNodes/filtered_detections/map/while/strided_slice_13/stack_2
TFNodes/filtered_detections/map/while/Greater_4/y
TFNodes/filtered_detections/map/while/strided_slice_18/stack
TFNodes/filtered_detections/map/while/strided_slice_18/stack_1
TFNodes/filtered_detections/map/while/strided_slice_18/stack_2
TFNodes/filtered_detections/map/while/strided_slice_17/stack
TFNodes/filtered_detections/map/while/strided_slice_17/stack_1
TFNodes/filtered_detections/map/while/strided_slice_17/stack_2
TFNodes/filtered_detections/map/while/Greater_5/y
TFNodes/filtered_detections/map/while/strided_slice_22/stack
TFNodes/filtered_detections/map/while/strided_slice_22/stack_1
TFNodes/filtered_detections/map/while/strided_slice_22/stack_2
TFNodes/filtered_detections/map/while/strided_slice_21/stack
TFNodes/filtered_detections/map/while/strided_slice_21/stack_1
TFNodes/filtered_detections/map/while/strided_slice_21/stack_2
TFNodes/filtered_detections/map/while/strided_slice/stack
TFNodes/filtered_detections/map/while/strided_slice/stack_1
TFNodes/filtered_detections/map/while/strided_slice/stack_2
TFNodes/filtered_detections/map/while/strided_slice_4/stack
TFNodes/filtered_detections/map/while/strided_slice_4/stack_1
TFNodes/filtered_detections/map/while/strided_slice_4/stack_2
TFNodes/filtered_detections/map/while/strided_slice_8/stack
TFNodes/filtered_detections/map/while/strided_slice_8/stack_1
TFNodes/filtered_detections/map/while/strided_slice_8/stack_2
TFNodes/filtered_detections/map/while/strided_slice_12/stack
TFNodes/filtered_detections/map/while/strided_slice_12/stack_1
TFNodes/filtered_detections/map/while/strided_slice_12/stack_2
TFNodes/filtered_detections/map/while/strided_slice_16/stack
TFNodes/filtered_detections/map/while/strided_slice_16/stack_1
TFNodes/filtered_detections/map/while/strided_slice_16/stack_2
TFNodes/filtered_detections/map/while/strided_slice_20/stack
TFNodes/filtered_detections/map/while/strided_slice_20/stack_1
TFNodes/filtered_detections/map/while/strided_slice_20/stack_2
TFNodes/filtered_detections/map/while/embedding_lookup/axis
TFNodes/filtered_detections/map/while/embedding_lookup_2/axis
TFNodes/filtered_detections/map/while/embedding_lookup_4/axis
TFNodes/filtered_detections/map/while/embedding_lookup_6/axis
TFNodes/filtered_detections/map/while/embedding_lookup_8/axis
TFNodes/filtered_detections/map/while/embedding_lookup_10/axis
TFNodes/clipped_boxes/stack
TFNodes/filtered_detections/map/Shape
TFNodes/filtered_detections/map/strided_slice
TFNodes/filtered_detections/map/TensorArray_2
TFNodes/filtered_detections/map/TensorArray_4
TFNodes/filtered_detections/map/TensorArray_3
TFNodes/filtered_detections/map/while/Enter_2
TFNodes/filtered_detections/map/while/Merge_2
TFNodes/filtered_detections/map/while/Enter_4
TFNodes/filtered_detections/map/while/Merge_4
TFNodes/filtered_detections/map/while/Enter_3
TFNodes/filtered_detections/map/while/Merge_3
TFNodes/filtered_detections/map/while/TensorArrayWrite/TensorArrayWriteV3/Enter
TFNodes/filtered_detections/map/while/Less/Enter
TFNodes/filtered_detections/map/while/Less
TFNodes/filtered_detections/map/while/Less_1
TFNodes/filtered_detections/map/while/LogicalAnd
TFNodes/filtered_detections/map/while/LoopCond
TFNodes/filtered_detections/map/while/Switch_2
TFNodes/filtered_detections/map/while/Exit_2
TFNodes/filtered_detections/map/TensorArrayStack/TensorArraySizeV3
TFNodes/filtered_detections/map/TensorArrayStack/range
TFNodes/filtered_detections/map/TensorArrayStack/TensorArrayGatherV3
TFNodes/filtered_detections/map/while/Switch_4
TFNodes/filtered_detections/map/while/Exit_4
TFNodes/filtered_detections/map/TensorArrayStack_2/TensorArraySizeV3
TFNodes/filtered_detections/map/TensorArrayStack_2/range
TFNodes/filtered_detections/map/TensorArrayStack_2/TensorArrayGatherV3
TFNodes/filtered_detections/map/while/Switch_3
TFNodes/filtered_detections/map/while/Exit_3
TFNodes/filtered_detections/map/TensorArrayStack_1/TensorArraySizeV3
TFNodes/filtered_detections/map/TensorArrayStack_1/range
TFNodes/filtered_detections/map/TensorArrayStack_1/TensorArrayGatherV3
TFNodes/filtered_detections/map/while/Identity_2
TFNodes/filtered_detections/map/while/TensorArrayWrite_2/TensorArrayWriteV3/Enter
TFNodes/filtered_detections/map/while/Identity_4
TFNodes/filtered_detections/map/while/TensorArrayWrite_1/TensorArrayWriteV3/Enter
TFNodes/filtered_detections/map/while/Identity_3
TFNodes/filtered_detections/map/while/Switch_1
TFNodes/filtered_detections/map/while/Identity_1
TFNodes/filtered_detections/map/while/add_1
TFNodes/filtered_detections/map/while/NextIteration_1
TFNodes/filtered_detections/map/while/Switch
TFNodes/filtered_detections/map/while/Identity
TFNodes/filtered_detections/map/while/add
TFNodes/filtered_detections/map/while/NextIteration
TFNodes/filtered_detections/map/TensorArray
TFNodes/filtered_detections/map/while/TensorArrayReadV3/Enter
TFNodes/filtered_detections/map/TensorArray_1
TFNodes/filtered_detections/map/while/TensorArrayReadV3_1/Enter
TFNodes/filtered_detections/map/TensorArrayUnstack/Shape
TFNodes/filtered_detections/map/TensorArrayUnstack/strided_slice
TFNodes/filtered_detections/map/TensorArrayUnstack/range
TFNodes/filtered_detections/map/TensorArrayUnstack/TensorArrayScatter/TensorArrayScatterV3
TFNodes/filtered_detections/map/while/TensorArrayReadV3/Enter_1
TFNodes/filtered_detections/map/while/TensorArrayReadV3
TFNodes/classification/concat
TFNodes/filtered_detections/map/TensorArrayUnstack_1/Shape
TFNodes/filtered_detections/map/TensorArrayUnstack_1/strided_slice
TFNodes/filtered_detections/map/TensorArrayUnstack_1/range
TFNodes/filtered_detections/map/TensorArrayUnstack_1/TensorArrayScatter/TensorArrayScatterV3
TFNodes/filtered_detections/map/while/TensorArrayReadV3_1/Enter_1
TFNodes/filtered_detections/map/while/TensorArrayReadV3_1
TFNodes/filtered_detections/map/while/strided_slice
TFNodes/filtered_detections/map/while/Greater
TFNodes/filtered_detections/map/while/Where
TFNodes/filtered_detections/map/while/GatherNd
TFNodes/filtered_detections/map/while/Shape
TFNodes/filtered_detections/map/while/strided_slice_1
TFNodes/filtered_detections/map/while/ones/packed
TFNodes/filtered_detections/map/while/ones
TFNodes/filtered_detections/map/while/mul
TFNodes/filtered_detections/map/while/strided_slice_4
TFNodes/filtered_detections/map/while/Greater_1
TFNodes/filtered_detections/map/while/Where_1
TFNodes/filtered_detections/map/while/GatherNd_2
TFNodes/filtered_detections/map/while/Shape_1
TFNodes/filtered_detections/map/while/strided_slice_5
TFNodes/filtered_detections/map/while/ones_1/packed
TFNodes/filtered_detections/map/while/ones_1
TFNodes/filtered_detections/map/while/mul_1
TFNodes/filtered_detections/map/while/strided_slice_8
TFNodes/filtered_detections/map/while/Greater_2
TFNodes/filtered_detections/map/while/Where_2
TFNodes/filtered_detections/map/while/GatherNd_4
TFNodes/filtered_detections/map/while/Shape_2
TFNodes/filtered_detections/map/while/strided_slice_9
TFNodes/filtered_detections/map/while/ones_2/packed
TFNodes/filtered_detections/map/while/ones_2
TFNodes/filtered_detections/map/while/mul_2
TFNodes/filtered_detections/map/while/strided_slice_12
TFNodes/filtered_detections/map/while/Greater_3
TFNodes/filtered_detections/map/while/Where_3
TFNodes/filtered_detections/map/while/GatherNd_6
TFNodes/filtered_detections/map/while/Shape_3
TFNodes/filtered_detections/map/while/strided_slice_13
TFNodes/filtered_detections/map/while/ones_3/packed
TFNodes/filtered_detections/map/while/ones_3
TFNodes/filtered_detections/map/while/mul_3
TFNodes/filtered_detections/map/while/strided_slice_16
TFNodes/filtered_detections/map/while/Greater_4
TFNodes/filtered_detections/map/while/Where_4
TFNodes/filtered_detections/map/while/GatherNd_8
TFNodes/filtered_detections/map/while/Shape_4
TFNodes/filtered_detections/map/while/strided_slice_17
TFNodes/filtered_detections/map/while/ones_4/packed
TFNodes/filtered_detections/map/while/ones_4
TFNodes/filtered_detections/map/while/mul_4
TFNodes/filtered_detections/map/while/strided_slice_20
TFNodes/filtered_detections/map/while/Greater_5
TFNodes/filtered_detections/map/while/Where_5
TFNodes/filtered_detections/map/while/GatherNd_10
TFNodes/filtered_detections/map/while/Shape_5
TFNodes/filtered_detections/map/while/strided_slice_21
TFNodes/filtered_detections/map/while/ones_5/packed
TFNodes/filtered_detections/map/while/ones_5
TFNodes/filtered_detections/map/while/mul_5
TFNodes/filtered_detections/map/while/embedding_lookup
TFNodes/filtered_detections/map/while/embedding_lookup/Identity
TFNodes/filtered_detections/map/while/strided_slice_2
TFNodes/filtered_detections/map/while/non_max_suppression/NonMaxSuppressionV3
TFNodes/filtered_detections/map/while/embedding_lookup_1
TFNodes/filtered_detections/map/while/embedding_lookup_1/Identity
TFNodes/filtered_detections/map/while/strided_slice_3
TFNodes/filtered_detections/map/while/GatherNd_1
TFNodes/filtered_detections/map/while/stack
TFNodes/filtered_detections/map/while/embedding_lookup_2
TFNodes/filtered_detections/map/while/embedding_lookup_2/Identity
TFNodes/filtered_detections/map/while/strided_slice_6
TFNodes/filtered_detections/map/while/non_max_suppression_1/NonMaxSuppressionV3
TFNodes/filtered_detections/map/while/embedding_lookup_3
TFNodes/filtered_detections/map/while/embedding_lookup_3/Identity
TFNodes/filtered_detections/map/while/strided_slice_7
TFNodes/filtered_detections/map/while/GatherNd_3
TFNodes/filtered_detections/map/while/stack_1
TFNodes/filtered_detections/map/while/embedding_lookup_4
TFNodes/filtered_detections/map/while/embedding_lookup_4/Identity
TFNodes/filtered_detections/map/while/strided_slice_10
TFNodes/filtered_detections/map/while/non_max_suppression_2/NonMaxSuppressionV3
TFNodes/filtered_detections/map/while/embedding_lookup_5
TFNodes/filtered_detections/map/while/embedding_lookup_5/Identity
TFNodes/filtered_detections/map/while/strided_slice_11
TFNodes/filtered_detections/map/while/GatherNd_5
TFNodes/filtered_detections/map/while/stack_2
TFNodes/filtered_detections/map/while/embedding_lookup_6
TFNodes/filtered_detections/map/while/embedding_lookup_6/Identity
TFNodes/filtered_detections/map/while/strided_slice_14
TFNodes/filtered_detections/map/while/non_max_suppression_3/NonMaxSuppressionV3
TFNodes/filtered_detections/map/while/embedding_lookup_7
TFNodes/filtered_detections/map/while/embedding_lookup_7/Identity
TFNodes/filtered_detections/map/while/strided_slice_15
TFNodes/filtered_detections/map/while/GatherNd_7
TFNodes/filtered_detections/map/while/stack_3
TFNodes/filtered_detections/map/while/embedding_lookup_8
TFNodes/filtered_detections/map/while/embedding_lookup_8/Identity
TFNodes/filtered_detections/map/while/strided_slice_18
TFNodes/filtered_detections/map/while/non_max_suppression_4/NonMaxSuppressionV3
TFNodes/filtered_detections/map/while/embedding_lookup_9
TFNodes/filtered_detections/map/while/embedding_lookup_9/Identity
TFNodes/filtered_detections/map/while/strided_slice_19
TFNodes/filtered_detections/map/while/GatherNd_9
TFNodes/filtered_detections/map/while/stack_4
TFNodes/filtered_detections/map/while/embedding_lookup_10
TFNodes/filtered_detections/map/while/embedding_lookup_10/Identity
TFNodes/filtered_detections/map/while/strided_slice_22
TFNodes/filtered_detections/map/while/non_max_suppression_5/NonMaxSuppressionV3
TFNodes/filtered_detections/map/while/embedding_lookup_11
TFNodes/filtered_detections/map/while/embedding_lookup_11/Identity
TFNodes/filtered_detections/map/while/strided_slice_23
TFNodes/filtered_detections/map/while/GatherNd_11
TFNodes/filtered_detections/map/while/stack_5
TFNodes/filtered_detections/map/while/concat
TFNodes/filtered_detections/map/while/GatherNd_12
TFNodes/filtered_detections/map/while/strided_slice_24
TFNodes/filtered_detections/map/while/Shape_6
TFNodes/filtered_detections/map/while/strided_slice_25
TFNodes/filtered_detections/map/while/Minimum
TFNodes/filtered_detections/map/while/TopKV2
TFNodes/filtered_detections/map/while/embedding_lookup_14
TFNodes/filtered_detections/map/while/embedding_lookup_14/Identity
TFNodes/filtered_detections/map/while/strided_slice_26
TFNodes/filtered_detections/map/while/embedding_lookup_12
TFNodes/filtered_detections/map/while/embedding_lookup_12/Identity
TFNodes/filtered_detections/map/while/embedding_lookup_13
TFNodes/filtered_detections/map/while/embedding_lookup_13/Identity
TFNodes/filtered_detections/map/while/Shape_7
TFNodes/filtered_detections/map/while/strided_slice_27
TFNodes/filtered_detections/map/while/sub
TFNodes/filtered_detections/map/while/Maximum
TFNodes/filtered_detections/map/while/PadV2/paddings/0
TFNodes/filtered_detections/map/while/PadV2/paddings
TFNodes/filtered_detections/map/while/PadV2
TFNodes/filtered_detections/map/while/TensorArrayWrite/TensorArrayWriteV3
TFNodes/filtered_detections/map/while/NextIteration_2
TFNodes/filtered_detections/map/while/PadV2_1/paddings/0
TFNodes/filtered_detections/map/while/PadV2_1/paddings
TFNodes/filtered_detections/map/while/PadV2_1
TFNodes/filtered_detections/map/while/TensorArrayWrite_1/TensorArrayWriteV3
TFNodes/filtered_detections/map/while/NextIteration_3
TFNodes/filtered_detections/map/while/PadV2_2/paddings/0
TFNodes/filtered_detections/map/while/PadV2_2/paddings
TFNodes/filtered_detections/map/while/PadV2_2
TFNodes/filtered_detections/map/while/Cast
TFNodes/filtered_detections/map/while/TensorArrayWrite_2/TensorArrayWriteV3
TFNodes/filtered_detections/map/while/NextIteration_4
TFNodes_identity
TFNodes_identity_1
TFNodes_identity_2
Traceback (most recent call last):

  File "<ipython-input-1-ef477d7c82d7>", line 1, in <module>
    runfile('C:/Users/martin.genet/Documents/GIT/keras-retinanet-master/keras_to_onnx.py', wdir='C:/Users/martin.genet/Documents/GIT/keras-retinanet-master')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/martin.genet/Documents/GIT/keras-retinanet-master/keras_to_onnx.py", line 18, in <module>
    onnx_model = keras2onnx.convert_keras(model, model.name)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\main.py", line 98, in convert_keras
    parse_graph(topology, sess.graph, target_opset, output_names)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\parser.py", line 736, in parse_graph
    return _parse_graph_scope(graph, keras_layer_ts_map, topo, top_level, output_names)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\parser.py", line 695, in _parse_graph_scope
    _infer_graph_shape(topology, top_scope, varset)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\parser.py", line 458, in _infer_graph_shape
    _finalize_tf2onnx_op(topology, oop, varset)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\parser.py", line 428, in _finalize_tf2onnx_op
    g = tf2onnx_wrap(topo, subgraph, outputs, varset.target_opset)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\wrapper.py", line 32, in tf2onnx_wrap
    raise e

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\wrapper.py", line 26, in tf2onnx_wrap
    output_names=outputs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\tfonnx.py", line 575, in process_tf_graph
    raise exceptions[0]

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\tfonnx.py", line 352, in tensorflow_onnx_mapping
    func(g, node, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\onnx_opset\nn.py", line 401, in version_1
    paddings = np.array(node.inputs[1].get_tensor_value()).transpose().flatten()

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ktf2onnx\tf2onnx\graph.py", line 257, in get_tensor_value
    raise ValueError("get tensor value: {} must be Const".format(self.name))

ValueError: get tensor value: TFNodes/filtered_detections/map/while/PadV2_2/paddings_Concat__1329 must be Const

If I rerun in the same python session I get the previous error again:

Traceback (most recent call last):
    onnx_model = keras2onnx.convert_keras(model, model.name)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\main.py", line 98, in convert_keras
    parse_graph(topology, sess.graph, target_opset, output_names)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\parser.py", line 736, in parse_graph
    return _parse_graph_scope(graph, keras_layer_ts_map, topo, top_level, output_names)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\parser.py", line 648, in _parse_graph_scope
    ts_in, ts_out = _on_parsing_model_layer(layer_key_, graph, kenode, varset)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\parser.py", line 295, in _on_parsing_model_layer
    bn_name_list = [bn_.name for bn_ in list_output_tensors(base_node)]

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras2onnx-1.5.2-py3.6.egg\keras2onnx\ke2onnx\main.py", line 55, in list_output_tensors
    return [node.output_tensors] if hasattr(node.output_tensors, 'dtype') else node.output_tensors

AttributeError: 'NoneType' object has no attribute 'output_tensors'

I would try the solution presented in that issue but can't figure where tf2onnx_contrib_op_conversion is defined.

jiafatom commented 5 years ago

Can you pull latest keras2onnx master? tf2onnx_contrib_op_conversion is in this file.

mrtgenet commented 5 years ago

Thanks, this solved the problem (at least the .onnx file was created, now I should check if it works fine)

In case other people struggle here is the simple script that made the work:

from keras_retinanet import models
import keras2onnx
import onnx

import sys 
import os
sys.path.append(os.path.abspath("./tests"))
from test_utils import tf2onnx_contrib_op_conversion

model_path = '/path/to/keras_model.h5'

model = models.load_model(model_path, backbone_name='resnet50')

onnx_model = keras2onnx.convert_keras(model, model.name,
                                      target_opset=10,
                                      custom_op_conversions=tf2onnx_contrib_op_conversion)

onnx.save_model(onnx_model, '{}.onnx'.format(os.path.splitext(model_path)[0]))
mrtgenet commented 5 years ago

Well, the onnx checker throws an error on the .onnx saved model:

[...]
    onnx.checker.check_model(model)

  File "C:\ProgramData\Anaconda3\lib\site-packages\onnx\checker.py", line 91, in check_model
    C.check_model(model.SerializeToString())

ValidationError: Nodes in a graph must be topologically sorted, however input 'TFNodes/clipped_boxes/stack:0' of node: 
input: "TFNodes/clipped_boxes/stack:0" input: "Unsqueeze__130:0" output: "Gather__131:0" name: "Gather__131" op_type: "Gather" domain: ""
 is not output of any previous nodes.

After that error the detailed context is provided, but I think it contains more characters than the scenarios of the GOT seasons all together...

jrtcppv commented 5 years ago

Has there been any progress on this? I also wanted to use retinanet in onnxruntime and ran into this same issue.

mrtgenet commented 4 years ago

No progress for me, I didn't manage to achieve a working conversion, and I had to put this work aside since I have tasks of higher priority to deal with.