Firstly, I would like to give the memory information before the processes.
pmem(rss=288796672, vms=4105973760, shared=107503616, text=2039808, lib=0, data=771235840, dirty=0)
I built a model using Keras and assign it to the model variable. Then, I sent the model object to a class constructor for cloning:
from tensorflow.python.keras.models import clone_model
from tensorflow.python.keras import backend as K
class Source:
def __init__(self, model):
config = Config()
self.model = clone_model(model)
# breakpoint to read memory
self.model.compile(optimizer=config.optimizer, loss=config.loss, metrics=config.metrics)
The memory information after the cloning process is showed below:
pmem(rss=289615872, vms=4333002752, shared=107843584, text=2039808, lib=0, data=797331456, dirty=0)
So far, so good. When I try to delete the self.model object by del self.model, memory is not decreased.
pmem(rss=289615872, vms=4333002752, shared=107843584, text=2039808, lib=0, data=797331456, dirty=0)
Then I tried to execute garbage collector by gc.collect(), but the result was the same, nothing has changed.
pmem(rss=289615872, vms=4333002752, shared=107843584, text=2039808, lib=0, data=797331456, dirty=0)
Lastly, I tried to clear the session by using K.clear_session(). Nothing has changed again.
pmem(rss=289615872, vms=4333002752, shared=107843584, text=2039808, lib=0, data=797331456, dirty=0)
Keras version: 2.1.6 (downgraded from last version to solve this problem but it is not worked.)
Tensorflow version: 2.0.0-alpha0