onnx / keras-onnx

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

AttributeError: 'Model' object has no attribute 'model' #695

Closed codethief closed 3 years ago

codethief commented 3 years ago

I installed keras-onnx 1.7.0 on Ubuntu 20.04 / Python 3.6.12 and tried to convert a model using keras2onnx.cli. Unfortunately, it failed before it even got to converting the model:

python3 -m keras2onnx.cli my_keras_model.h5 --output_file model.onnx --opset 11
WARNING:tensorflow:From /home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2021-03-05 13:28:57.812519: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-03-05 13:28:57.835159: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2299965000 Hz
2021-03-05 13:28:57.835671: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x558904e5f3a0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-03-05 13:28:57.835693: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
  File "/home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/site-packages/keras2onnx/cli.py", line 36, in <module>
    fire.Fire(main)
  File "/home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/user/opt/miniconda3/envs/my-conda-env/lib/python3.6/site-packages/keras2onnx/cli.py", line 28, in main
    oxml = convert_keras(kml, kml.model, '', opset, channel_first)
AttributeError: 'Model' object has no attribute 'model'

I would appreciate any help!

jiafatom commented 3 years ago

Can you pull keras2onnx master and try?

codethief commented 3 years ago
$ pip3 install git+https://github.com/microsoft/onnxconverter-common@1.8.0#egg=onnxconverter-common
$ pip3 install git+https://github.com/onnx/keras-onnx@63f3b5085273787ca464d436401151f813f7f636#egg=keras2onnx
$ python3 -m keras2onnx.cli my_keras_model.h5 --output_file model.onnx --opset 11

did the trick! Thank you so much!