Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras in R: freeing up memory after multiple training sessions

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.

like image 866
Ingolifs Avatar asked Nov 06 '22 00:11

Ingolifs


1 Answers

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)

like image 167
bricx Avatar answered Nov 11 '22 06:11

bricx