onnx2keras icon indicating copy to clipboard operation
onnx2keras copied to clipboard

Onnx to keras model conversion failed

Open st186 opened this issue 4 years ago • 1 comments

import onnx
from onnx2keras import onnx_to_keras

# Load ONNX model
onnx_model = onnx.load('/home/pat-011/Desktop/deep_learning/POC1/output/tensorflow/pytorch_onnx_tf_onnx.onnx')

# Call the converter (input - is the main model input name, can be different for your model)
k_model = onnx_to_keras(onnx_model, ['input'])

Error -

Traceback (most recent call last): File "/home/pat-011/.virtualenvs/onnx/lib/python3.6/site-packages/keras/engine/base_layer.py", line 279, in assert_input_compatibility K.is_keras_tensor(x) File "/home/pat-011/.virtualenvs/onnx/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 474, in is_keras_tensor str(type(x)) + '. ' ValueError: Unexpectedly found an instance of type <class 'NoneType'>`. Expected a symbolic tensor instance.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "tf-onnx-pytorch-keras.py", line 30, in k_model = onnx_to_keras(onnx_model, ['input']) File "/home/pat-011/.virtualenvs/onnx/lib/python3.6/site-packages/onnx2keras/converter.py", line 146, in onnx_to_keras node_name File "/home/pat-011/.virtualenvs/onnx/lib/python3.6/site-packages/onnx2keras/operation_layers.py", line 184, in convert_split input_0 = ensure_tf_type(layers[node.input[0]]) File "/home/pat-011/.virtualenvs/onnx/lib/python3.6/site-packages/onnx2keras/utils.py", line 42, in ensure_tf_type return lambda_layer(fake_input_layer) File "/home/pat-011/.virtualenvs/onnx/lib/python3.6/site-packages/keras/engine/base_layer.py", line 414, in call self.assert_input_compatibility(inputs) File "/home/pat-011/.virtualenvs/onnx/lib/python3.6/site-packages/keras/engine/base_layer.py", line 285, in assert_input_compatibility str(inputs) + '. All inputs to the layer ' ValueError: Layer lambda_1 was called with an input that isn't a symbolic tensor. Received type: <class 'NoneType'>. Full input: [None]. All inputs to the layer should be tensors.

st186 avatar Jul 29 '19 19:07 st186

@nerox8664 This happens because in operation_layers, and probably in other places too, the fake_input_layer parameter for ensure_tf_type isn't set. I could go over all function the coming days and send a PR if you want. (Also happy if you do that ofc ;))

SleepProgger avatar Aug 01 '19 01:08 SleepProgger