The clear_session() method of keras.backend does not clean up the previously execution

81 views
Skip to first unread message

ram

unread,
Apr 24, 2020, 8:06:57 PM4/24/20
to Keras-users
When I run the model, I find that it was conflicting with the previously executed model. In addition,  global variables in my program contain values from the previous run. I used keras.backend.clear_session() and del model but the problem persists. How can I return to the initial state at each execution?
I used google colab notebook as an execution environment with keras version 2.3.1 and Tensorflow backend 2.2.0

Lance Norskog

unread,
Apr 25, 2020, 4:07:58 AM4/25/20
to ram, Keras-users
Use the Colab 'restart runtime' option. 

Lance

On Fri, Apr 24, 2020 at 5:07 PM ram <ram...@gmail.com> wrote:
When I run the model, I find that it was conflicting with the previously executed model. In addition,  global variables in my program contain values from the previous run. I used keras.backend.clear_session() and del model but the problem persists. How can I return to the initial state at each execution?
I used google colab notebook as an execution environment with keras version 2.3.1 and Tensorflow backend 2.2.0

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/d30614f1-7e13-4097-a0f0-a7d09af9fd1f%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA

ram

unread,
Apr 25, 2020, 9:57:05 AM4/25/20
to Keras-users
Thanks Lance,
 If I use a loop in my program for training many models. How I can do for each iteration to reset the model to the "initial" state for training another one?
 Can i use reset_seeds() at the start of each loop in addition del model and keras.backend.clear_session() at the end ? This in order to clear the memory. 

Lance Norskog

unread,
Apr 26, 2020, 11:18:50 PM4/26/20
to ram, Keras-users
Ah, ok. Yes, global variables are retained as long as the notebook runtime is up. There is a 'gc' package in Python to call Python's garbage collection. I have used this in the past (not with keras).

Colab has a UI item in the top right corner that shows you how much ram is used in CPU and GPU, and disk space. 

Lance

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages