Having issue in converting autokeras functional model to onnx?
See original GitHub issueHi, I am trying to convert autokeras model to onnx, i get error
from autokeras import StructuredDataClassifier
model = StructuredDataClassifier(max_trials=100)
model.fit(x=X_train, y=y_train, validation_data=(X_valid, y_valid), epochs=1000, verbose=1)
autoKeras_model = model.export_model()
autoKeras_model.summary()
Model: "functional_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) [(None, 18)] 0
_________________________________________________________________
multi_category_encoding (Mul (None, 18) 0
_________________________________________________________________
dense (Dense) (None, 32) 608
_________________________________________________________________
re_lu (ReLU) (None, 32) 0
_________________________________________________________________
dense_1 (Dense) (None, 32) 1056
_________________________________________________________________
re_lu_1 (ReLU) (None, 32) 0
_________________________________________________________________
dense_2 (Dense) (None, 1) 33
_________________________________________________________________
classification_head_2 (Activ (None, 1) 0
=================================================================
Total params: 1,697
Trainable params: 1,697
Non-trainable params: 0
_________________________________________________________________
converting to onnx
import onnxruntime
import keras2onnx
onnx_model = keras2onnx.convert_keras(autoKeras_model, "autokeras", debug_mode=1)
I get error
tf executing eager_mode: True
INFO:keras2onnx:tf executing eager_mode: True
tf.keras model eager_mode: False
INFO:keras2onnx:tf.keras model eager_mode: False
Model: "functional_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) [(None, 18)] 0
_________________________________________________________________
multi_category_encoding (Mul (None, 18) 0
_________________________________________________________________
dense (Dense) (None, 32) 608
_________________________________________________________________
re_lu (ReLU) (None, 32) 0
_________________________________________________________________
dense_1 (Dense) (None, 32) 1056
_________________________________________________________________
re_lu_1 (ReLU) (None, 32) 0
_________________________________________________________________
dense_2 (Dense) (None, 1) 33
_________________________________________________________________
classification_head_2 (Activ (None, 1) 0
=================================================================
Total params: 1,697
Trainable params: 1,697
Non-trainable params: 0
_________________________________________________________________
None
Traceback (most recent call last):
File "<ipython-input-76-0567e6de6858>", line 1, in <module>
onnx_model = keras2onnx.convert_keras(ExportedautoKeras_model, model_name, debug_mode=1)
File "C:\Users\Pe\Anaconda3\lib\site-packages\keras2onnx\main.py", line 62, in convert_keras
tf_graph = build_layer_output_from_model(model, output_dict, input_names, output_names)
File "C:\Users\Pe\Anaconda3\lib\site-packages\keras2onnx\_parser_tf.py", line 302, in build_layer_output_from_model
return extract_outputs_from_subclassing_model(model, output_dict, input_names, output_names)
File "C:\Users\Pe\Anaconda3\lib\site-packages\keras2onnx\_parser_tf.py", line 264, in extract_outputs_from_subclassing_model
concrete_func, lower_control_flow=True)
File "C:\Users\Pe\Anaconda3\lib\site-packages\keras2onnx\_graph_cvt.py", line 437, in convert_variables_to_constants_v2
tensor_data = _get_tensor_data(func)
File "C:\Users\Pe\Anaconda3\lib\site-packages\keras2onnx\_graph_cvt.py", line 209, in _get_tensor_data
data = val_tensor.numpy()
File "C:\Users\Pe\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1063, in numpy
maybe_arr = self._numpy() # pylint: disable=protected-access
File "C:\Users\Pe\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1031, in _numpy
six.raise_from(core._status_to_exception(e.code, e.message), None) # pylint: disable=protected-access
File "<string>", line 3, in raise_from
InvalidArgumentError: Cannot convert a Tensor of dtype resource to a NumPy array.
May i have some help Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
How to Convert Your Keras Model to ONNX - Medium
There are some points for converting Keras model to ONNX: Remember to import onnx and keras2onnx packages. keras2onnx.convert_keras() function ...
Read more >Export Model - AutoKeras
You can easily export your model the best model found by AutoKeras as a Keras Model. ... All the tasks and the AutoModel...
Read more >What I Like and Don't Like About AutoML as a Data Scientist
As for ONNX, it also proved problematic to convert a scikit-learn ensemble pipeline to ONNX. Often AutoML candidate models grow very complex, and...
Read more >Unable to convert .h5 model to ONNX for inferencing through ...
Try converting it to saved model format and then to onnx. import numpy as np import tensorflow as tf from tensorflow import keras...
Read more >Available CRAN Packages By Name
base.rms, Convert Regression Between Base Function and 'rms' Package. base64, Base64 Encoder and Decoder ... BTM, Biterm Topic Models for Short Text.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@torronen Following combinations working fine for me
Thank you @hanzigs , that solved the issue.
I believe my problem was using keras2onnx instead of tf2onnx. Package versioning may have had something to do with it, but probably not.
onnx_model, _ = tf2onnx.convert.from_keras(model)