Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does keras save_weights() function overwrite previous weights?

Tags:

python

keras

I just want to confirm if the save_weights() function in keras defaults to overwriting a previous weights file if the weight file already exists?

For example, if I train my neural net for 10 epochs, save the weights to 'myweights.h5' via save_weights, and then I load those weights and train it for another 10 epochs and then save the weights to 'myweights.h5' again, will the first 10 epoch's weights get erased and now I'll have new weights from after 20 epochs? I looked at the documentation at https://keras.io/getting-started/faq/#savingloading-only-a-models-weights but it didn't specify whether it overwrites the old file or not. Some searching on google seems to say that it doesn't default to overwriting the older weights, but those are older threads and probably for older versions of keras.

like image 371
enumaris Avatar asked Feb 28 '26 15:02

enumaris


1 Answers

Yes absolutely, if you don't want this behaviour you have to use different names each times (composing with steps/epochs for instance).

like image 139
Jonathan DEKHTIAR Avatar answered Mar 02 '26 05:03

Jonathan DEKHTIAR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!