Autokeras: I can not use the method predict on keras model (AutoModel.export_model()) with categorical features

Created on 23 Jul 2020  路  6Comments  路  Source: keras-team/autokeras

Bug Description

When I use the StructuredDataClassifier and I export the model by export_model, I can not use the predict method - model.predict(test_data.to_numpy()) --, because the Keras model can not handle with categorical features. I believe that export_model does not add in the pipeline model the preprocess routine to treat the categorical features.

The error presented is: "ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float)."

below the code:

Bug Reproduction

Code for reproducing the bug:

train_features = dataset_train_features.to_numpy()
train_label = dataset_train_label.to_numpy()
test_features = dataset_test_features.to_numpy()
test_label = dataset_test_label.to_numpy()

estimator = ak.StructuredDataClassifier(**params)

estimator.fit(x=train_features,
y=train_label,
validation_data=(test_features, test_label),
epochs=epochs)

##### THIS PART WORKS

predict_values = estimator.predict(test_features)
eval_values = estimator.evaluate(test_features, test_label)

##### THIS PART DOES NOT WORK

model = estimator.export_model()
predict_values = model.predict(test_features) ####### here it is throw the error #########
predict_proba = model.predict_proba(test_features)

#

Data used by the code:
Titanic Dataset

Expected Behavior

Setup Details

Include the details about the versions of:

  • OS type and version: Linux Ubuntu
  • Python: 3.7
  • autokeras: 1.0.4
  • keras-tuner: keras-tuner-1.0.2rc0
  • scikit-learn:
  • numpy:
  • pandas:
  • tensorflow: 2.2.0

Additional context

I read the autokeras code and it only returns self.tuner.get_best_model(). I believe it is needed to add it in the same pipeline preprocessor and model.

##### export_model only get the best model but do not make a pipeline with the preprocessors

autokeras.autokeras.auto_model.py
class AutoModel(object):
def export_model(self):
return self.tuner.get_best_model()

bug report wontfix

Most helpful comment

Similar Issue here with the StructuredDataRegessor

All 6 comments

The prerprocess steps are using preprocessing layers of Keras, it should be part of the model. Would you paste your model.summary()?
I guess it might be cause of the format of the training data.
We use np.unicode for the data.

Thank you @haifeng-jin for your response.
When I put np.unicode this works to me. But I believe that is important to use the original type of numpy, or perhaps, you can put this transformation within the preprocess. This is only an idea/suggestion.
Again, thank you for your help!
Bellow, I put the de model.summary()


model.summary()
Model: "model"


Layer (type) Output Shape Param #

input_1 (InputLayer) [(None, 9)] 0


multi_column_categorical_enc (None, 9) 0


dense (Dense) (None, 64) 640


batch_normalization (BatchNo (None, 64) 256


re_lu (ReLU) (None, 64) 0


dropout (Dropout) (None, 64) 0


dense_1 (Dense) (None, 16) 1040


batch_normalization_1 (Batch (None, 16) 64


re_lu_1 (ReLU) (None, 16) 0


dropout_1 (Dropout) (None, 16) 0


dense_2 (Dense) (None, 32) 544


batch_normalization_2 (Batch (None, 32) 128


re_lu_2 (ReLU) (None, 32) 0


dropout_2 (Dropout) (None, 32) 0


regression_head_1 (Dense) (None, 1) 33

Total params: 2,705
Trainable params: 2,481
Non-trainable params: 224


Similar Issue here with the StructuredDataRegessor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Still having the bug with 1.0.12

Ok I have managed to understand the issue for me : all the numeric data have to me cast as str before calling "predict()" (though I am not sure why). I hope it will help people

Was this page helpful?
0 / 5 - 0 ratings