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.

[Question] Can't load a model after training

See original GitHub issue

Hi! Long time didn’t see 😃 I faced some issue: I used custom model for classification task and trained it, saved weights as h5. And now I can’t to load it to test. Try this: model.load_weights("model_weights.h5")

and gets:

AttributeError: 'LSTM_Dropout_Dense_Model' object has no attribute 'load_weights'

class LSTM_Dropout_Dense_Model(BaseClassificationModel):
is based on BaseClassificationModel I found in other issues here to use something like loaded_model.model.load_weights(''') but I get AttributeError: 'LSTM_Dropout_Dense_Model' object has no attribute 'model'

What can I do?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MNCTTYcommented, Aug 6, 2019

I’ve never done it before, but a bit more experience and I’ll try! I try sometimes to accumulate my exp in small texts in my telegram blog, but it’s really rare and only for me and 2-3 people doing ± same tasks. Creating longreads very challenging for me! Never done it in english especially but I’ll try, in September, right after entry exams in the phd program because you develop really convenient, useful project – and it deserves to be more popular

1reaction
BrikerMancommented, Aug 6, 2019

Got it. You need to build a model first to get the tf_model object, try this,

# save the trained model
model.save('model_path')

# load model
# This includes model struct and model wights
new_model = kashgari.utils.load_model('model_path')
# You can reload model weights now
new_model.tf_model.load_weights('xx.h5')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Keras load_model not working after training - Stack Overflow
To load the model weights, create the model programmatically just as in step 1 but do not use the model.compile function.
Read more >
Custom GPT2 Model won't load after training - Intermediate
The Problem. I was able to train my customly build model but I am not able to load it with the from_pretrained() function....
Read more >
How to Save and Load Your Keras Deep Learning Model
In this post, you will discover how to save your Keras models to files and load them up again to make predictions. After...
Read more >
Saving and loading models for inference in PyTorch
There are two approaches for saving and loading models for inference in PyTorch. The first is saving and loading the state_dict , and...
Read more >
Save and load models in Tensorflow - GeeksforGeeks
The development of the model can be saved both before and after ... We can not load the weights of a model(having 2...
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