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.

Model saving doesn't work for StructuredDataRegressor

See original GitHub issue

Bug Description

I can’t save the best model as h5 or even a tf file

Bug Reproduction

Code for reproducing the bug:

model = regressor.export_model()

model.save('testmodel.h5')

gives me

NotImplementedError: Save or restore weights that is not an instance of `tf.Variable` is not supported in h5, use `save_format='tf'` instead. Got a model or layer CategoricalEncoding with weights ....

It suggests I use tf instead of h5, but when I do that I get this error

model.save('testmodel', save_format='tf')
2020-04-03 14:44:31.041453: W tensorflow/python/util/util.cc:329] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
*** RuntimeError: Attempting to capture an EagerTensor without building a function.

Data used by the code:

Expected Behavior

Save the best model in either h5 or tf format

Setup Details

  • OS type and version: Ubuntu 18.04.01
  • Python: 3.6.6
  • autokeras: 1.0.2
  • scikit-learn: 0.20.3
  • numpy: 1.18.2
  • pandas: 1.0.1
  • tensorflow: 2.2.0-dev20200401 (nightly)

Additional context

I also can’t load the model json after saving it but I think that’s related to #1023

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
haifeng-jincommented, Jun 26, 2020

As I tested the latest version of AutoKeras can save the structureddataregressor fine.

2reactions
alexfdocommented, Jun 17, 2020

@utkarshgupta137

save and load model

def load_pickle_model_from_file(name_file):
    with open(name_file, 'rb') as file:
        loaded_model = pickle.load(file)
    return loaded_model

def save_pickle_model_to_file(model, name_model):
    with open(Path(str(name_model)+".pickle"), 'wb') as file:
        pickle.dump(model, file)
    print(str(Path(str(name_model)+".pickle"))+' - model saved!')

create: model_name - you select own name; directory - you select place for model’s data

model = ak.StructuredDataRegressor(max_trials=max_trials,
                                               column_names=data_cols,
                                               column_types=data_type,
                                               project_name=model_name
                                               directory='data/models_saved_data/'
                                               )

save after creating: model_name - your selected name on previouse stage

save_pickle_model_to_file(model, model_name)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Model saving doesn't work for StructuredDataRegressor -
Bug Description. I can't save the best model as h5 or even a tf file. Bug Reproduction. Code for reproducing the bug: model...
Read more >
Trial ID of the best model - Stack Overflow
I'm using Autokeras to find the best regression model and I need to plot ... #path for saving the logs import datetime %load_ext...
Read more >
How to Use AutoKeras for Classification and Regression
The models and results are all saved in a folder called “structured_data_classifier” in your current working directory.
Read more >
StructuredDataRegressor - AutoKeras
Defaults to 0.2. Fraction of the training data to be used as validation data. The model will set apart this fraction of the...
Read more >
Complete guide to AutoKeras - Medium
Don't worry if all of this looks too overwhelming, you will get hold ... we can work with our model or save for...
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