gmalivenko / onnx2keras

Convert ONNX model graph to Keras model format.
MIT License
195 stars 116 forks source link

KeyError: 'split' #68

Open SelComputas opened 4 years ago

SelComputas commented 4 years ago

I am trying to convert a ONNX file to Keras using this onnx2keras functionality: k_model = onnx_to_keras(model, ['data'])

But I get an error message saying:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\onnx2keras\converter.py in onnx_to_keras(onnx_model, input_names, input_shapes, name_policy, verbose, change_ordering) 178 lambda_funcs, 179 node_name, --> 180 keras_names 181 ) 182

~\AppData\Local\Continuum\anaconda3\lib\site-packages\onnx2keras\operation_layers.py in convert_split(node, params, layers, lambda_func, node_name, keras_names) 211 212 input_0 = ensure_tf_type(layers[node.input[0]], name="%s_const" % keras_names[0]) --> 213 splits = params["split"] 214 axis = params.get("axis", 0) 215 if not isinstance(splits, Iterable):

KeyError: 'split'

Anybody have any tips?

SelComputas commented 4 years ago

So what I figured out was this: My model contains 12/13 nodes with op_type: "Split" as we can see here: image This triggers this part of the code: image Where node_type, at the end of the image, is split.

This in turn triggers image But as you can see from the first image, the node does not have any split parameter, which is the reason we get this error.

Tried solutions

So I tried to find some solutions such as finding an example of how values for this Split would look by accessing ONNX's model zoo: https://github.com/onnx/models#image_classification. I tried with 3 models:

And to my surprise only the mobilenet one worked - the other two returned different errors: squeezenet: ValueError: name for name_scope must be a string. shufflenet: ValueError: The channel dimension of the inputs should be defined. Found None.

So the mobilenet worked, but it does not contain any Split notes, making it pretty much useless for me, for information about my problem.

gmalivenko commented 4 years ago

Hello @SelComputas. I fixed problems related to Squeezenet (you can get latest changes from github, master branch). There was a problem with Dropout (in ONNX it returns not only operation result but mask as well).

Unfortunately, Shufflenet is quite more complex (they split channels and concat into new axes, it always causes problems, I will take a look but later.

SelComputas commented 4 years ago

Thank you @nerox8664!

To move on in my project I require a fix on the split channels, as seen in the first post, so fingers crossed

SelComputas commented 4 years ago

@nerox8664 - any updates on the "split"-nodes?

k-macdonald commented 3 years ago

I am running into this 'KeyError: split' issue too, were you able to find any resolution?

hiskuDN commented 1 year ago

same here

timoffenhaeusser commented 9 months ago

I am running into this 'KeyError: split' issue too, were you able to find any resolution?

me too, did anyone find a solution yet?