gmalivenko / onnx2keras

Convert ONNX model graph to Keras model format.
MIT License
193 stars 114 forks source link

Tensorflow to ONNX to Keras Model Conversion Failed #15

Open ghost opened 5 years ago

ghost commented 5 years ago
import onnx
import torch
from onnx2keras import onnx_to_keras

# Load ONNX model
model = onnx.load('ONNX/tensorflow-onnx/output/model.onnx')

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

File "/home/pat-011/.local/lib/python3.6/site-packages/onnx2keras/converter.py", line 138, in onnx_to_keras raise AttributeError('Current node is not in weights / model inputs / layers.') AttributeError: Current node is not in weights / model inputs / layers.

tsvetiko commented 4 years ago

Replace the ['input'] with the input name for your network - like ['input_0']:

k_model = onnx_to_keras(model, ['input_0'])
anuragtr commented 3 years ago

Hi, even on adding the input name of the network, it doesn't work. Used this approach: Use input_all = [node.name for node in onnx_model.graph.input], print (input_all) and replace the 'input' from change k_model = onnx_to_keras(onnx_model, ['input']) to the output of print(input_all)

so on trying: keras_model = onnx_to_keras(onnx_model, ['dense_4_input']) # ['dense_4_input'] is the input name Error: ValueError: 'dense_4/Identity:0' is not a valid scope name

Attaching the onnx model for reference (zipped): model_best_onnx.zip

Note: This onnx model was created from a working keras h5 model using keras2onnx library.