I am training multiple models in R. After a while, I run out of memory.
From rudimentary googling, the tensorflow sessions seems to hold things in memory after the objects have been overwritten in R. This has been a problem that others have encountered, however I have seen no answers that help for keras in R in particular.
Keras: release memory after finish training process
Tensorflow2.0: GPU runs out of memory during hyperparameter tuning loop
I've tried running these commands after each loop:
rm(model)
k_clear_session()
tf$compat$v1$keras$backend$clear_session()
but these problems persist. Any ideas on how to release the memory Keras uses?
I'm running this code on a laptop, and I'm pretty sure I don't have a GPU.
I recall having some memory issues in R (can't remember if it was with keras or something else), but one or a combination of the following should help:
remove(list=ls()) #remove your objects
gc() #garbage collection
.rs.restartR() #restart the R session (clean the memory but doesn't detach your packages)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With