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.

Strange problem regarding model save_weights

See original GitHub issue

I’m running keras on a remoter server with SSH, training LSTM, the training process works correctly, the model is like this:

model = Sequential()
model.add(Masking(mask_value=0., input_shape=(None, len(chars))))
model.add(LSTM(4000, return_sequences=True))
model.add(LSTM(4000, return_sequences=True))
model.add(TimeDistributed(Dense(len(chars))))
model.add(Activation('softmax'))

rmsprop=RMSprop(lr=0.006)
model.compile(loss='categorical_crossentropy', optimizer=rmsprop)

after I training, I saved the model:

json_string = model.to_json()    
open('my_model_architecture21.json', 'w').write(json_string)
model.save_weights('my_model_weights21.h5',overwrite=True)

but this part works abnormally, as when I reload weights after training, the model works like never been trained, the same script works correctly in my one laptop. this is really strange, anyone have an idea? thanks very much!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
HanyEjustcommented, Jan 4, 2017

why you don not use these lines of code:

1- save the model: model.save(path+‘\name.hdf5’)

2- load the model: from keras.models import load_model

model=load_model(path+‘\name.hdf5’)

On Wed, Jan 4, 2017 at 9:28 AM, MrWanter notifications@github.com wrote:

The problem has been solved with changing the version of pythonand keras, previously I’m using python3andkeras 1.2.0, after reinstall python2 and keras 1.1.0, it works correctly.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fchollet/keras/issues/4904#issuecomment-270309729, or mute the thread https://github.com/notifications/unsubscribe-auth/ARxwS9qb7DSbaaFtFoXqAok9GfizJC5qks5rO0okgaJpZM4LZcik .

_________________ Hany A. EL-Ghaish

E-JUST University *PhD Candidate at School of Communication and Computer Engineering, Egypt-Japan University of Science and Technology * M. 01004393715

3reactions
dipanjannagcommented, Jan 4, 2017

Facing the same issue #4875 But for me it is working fine if it is in same session. Even model.save() doesn’t seem to be working in this matter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in loading the model with load_weights in Keras
You are saving the weights, not the whole model. A Model is more than just the weights, including architecture, losses, metrics and etc....
Read more >
Save and load models | TensorFlow Core
Model progress can be saved during and after training. This means a model can resume where it left off and avoid long training...
Read more >
How to Checkpoint Deep Learning Models in Keras
Checkpoint the weights for best model on validation accuracy ... One way to address this problem is to overestimate the number of epochs....
Read more >
Nengo DL converter - Deep Learning
An alternative is to define your model as usual, and then use model.save_weights and model.load_weights to save and load the weights. I'm not ......
Read more >
Training new dense layers not training at all resulting 0.5 ...
My problem is that the training does not even start to converge and in fact seems to ... model.save_weights(models_path+“vgg16_conv.h5”) ...
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