keras-onnx
keras-onnx copied to clipboard
Having issue in converting autokeras functional model to onnx?
Hi, 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
Hi, Can i have some help on the above please, Using tensorflow == 2.3.0 keras == 2.4.3 Thanks
Hi, Can i have some help on the above please,
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_keras_model(autoKeras_model)
tflite_model = converter.convert()
tried this, same error