question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not predict with exported model.

See original GitHub issue

Bug Description

After fitting my autokeras model, I export it, however, I can not predict nor evaluate with this exported Keras model.

from tensorflow.keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train.shape # (60000, 28, 28)
y_train.shape # (60000,)
y_train[:3] # array([7, 2, 1], dtype=uint8)

x_train = x_train[:1000]
x_test = x_test[:1000]
y_train = y_train[:1000]
y_test = y_test[:1000]

import autokeras as ak

clf = ak.ImageClassifier(max_trials=3, directory = "/tmp/")
clf.fit(x_train, y_train, epochs=3)
predicted_y = clf.predict(x_test)
clf.evaluate(x_test, y_test)

model = clf.export_model()

predicted_y_2 = model.predict(x_test)
# ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (1000, 28, 28)
model.evaluate(x_test, y_test)
# ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (1000, 28, 28)

Setup Details

Include the details about the versions of:

  • OS type and version: Ubuntu 18.04
  • Python: Python 3.6.10
  • autokeras: 1.0.0
  • numpy: 1.18.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
zhulingchencommented, Jan 31, 2020

Hi, before you train on x_train and y_train and test on x_test, did you expand a dimension to the last dimension of x_train and x_test and make it have a shape of (None, 28, 28, 1)?

That’s usually how people do on the datasets to train and test the CNNs with the regular TensorFlow/Keras.

0reactions
haifeng-jincommented, Jul 1, 2020

@zhulingchen Would you like to do a user study with us? Have a 30-minute meeting with me to talk about what do you think of AutoKeras. Your thinking is important to us. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Export Regression Model to Predict New Data - MathWorks
To exclude the training data, click Export Model and select Export Compact Model. This option exports the model with unnecessary data removed. That...
Read more >
keras - Autokeras exported model performs not as expected
But when I export and save it as a keras model the model performs really bad. It classifies everything wrongly and the predict-function...
Read more >
Exporting models for prediction - AI Platform - Google Cloud
To serve predictions from AI Platform Prediction, you must export your trained machine learning model as one or more artifacts. This guide describes...
Read more >
2. Exporting and deploying a model — IPU TensorFlow ...
For non-Keras models, the export method does not accept the batch-size parameter. ... The function is the same predict function that was exported...
Read more >
Export TensorFlow models in the SavedModel format
The assets directory is optional. It stores supporting files for the prediction service. The variables directory stores the variables saved by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found