Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unload a keras/tensorflow model from memory?

Here's the problem: My (Keras)model is listening to a task queue. If no task arrives in 10 min, I want to unload the model and free the memory.

But I never thought such a job would be so hard...

Here are some failed tries:

(1) Set model = None, hope GC collect the memory.

(2) del model

(3) Use K.clear_session(), tf.reset_defualt_graph().

(4) Any combination of above methods followed by calling gc.collect() manually.

Is it possible to unload a model from memory without exiting current process? Any other suggestions?

like image 421
Moyan Avatar asked Aug 30 '18 09:08

Moyan


1 Answers

numba library

Assuming you are using device 0

from numba import cuda
cuda.select_device(0)
cuda.close()
like image 170
Tom Z Avatar answered Oct 01 '22 10:10

Tom Z