Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save and load model #1603

Closed
Marcosuff opened this issue May 22, 2019 · 4 comments
Closed

How to save and load model #1603

Marcosuff opened this issue May 22, 2019 · 4 comments

Comments

@Marcosuff
Copy link

Marcosuff commented May 22, 2019

Hello,

I'm trying to train a multitask regression using the same approach posted here:
https://github.com/deepchem/deepchem/blob/master/examples/notebooks/Multitask_Networks_on_MUV.ipynb.
Everything works fine until I need to save and load the model to make predictions. However when I load my model using the approach posted here
#650 (comment)
the evaluation results are completely different. Here's a sample output:

Best neural network prior to saving:

computed_metrics: [0.32803591086520073, 0.5407940796855545, 0.51435272945748, 1.5072726859368315, 0.8059894834144922, 0.43465885298644813, 0.7546208137228906, 0.5057226961061108, 0.5968139410991427, 0.4166696352270262, 0.40835529858]

Loaded model:

computed_metrics: [18.97499015453843, 18.11683325035692, 48.087994983626494,     36.00984590302385, 45.557838677120536, 36.11361848497406, 46.199146758789865,     54.76305977799556, 69.88862611897348, 37.10991454276001, 52.028279977709545]

As you can see the metrics are worse after loading the model.

Am I doing it the wrong way? Is there another way to save and load the model for predictions?

@rbharath
Copy link
Member

We've converted to Keras as our backend, so we're just using the Keras save/load functionality. I believe that these errors (which may have been with our custom TensorGraph code) should no longer occur. I'm going to close this issue, but please re-open if you're still facing problems.

@sorenwacker
Copy link

Please add an example.

@rbharath
Copy link
Member

So if you have a model, you can just call

model = GraphConvModel(model_dir="/place/to/save/your/model")
model.fit(dataset, nb_epoch=15)

And the model will automatically be saved to "/place/to/save/your/model". To reload the model you can do

model = GraphConvModel(model_dir="/place/to/save/your/model")
model.restore()

And you're all set!

@croqquettes02
Copy link

croqquettes02 commented Jun 3, 2022

how can i reload the model that saved using model.restore()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants