Keras clear all gpu memory

三世轮回 提交于 2019-12-10 11:31:58

问题


I'm doing something like this:

for ai in ai_generator:
   ai.fit(ecc...)

ai_generator is a generator that instantiate a model with different configuration.
My problem is gpu memory overflow, and K.clear_session() don't work because it throw this
ValueError: Tensor("conv2d_1/kernel:0", shape=(3, 3, 1, 1), dtype=float32_ref) must be from the same graph as Tensor("concat:0", shape=(?, 38, 300, 1), dtype=float32).
How can I clear keras memory as new? I need only performances of fit method, I can delete all.


回答1:


I resolved removing all layer shared between models. The "shared" instance was the input. Then I did this:

for ai in aigen:
   ai.fit(**params)
   del ai #  for avoid any trace on aigen
   tf.reset_default_graph() # for being sure
   K.clear_session() # removing session, it will instance another


来源:https://stackoverflow.com/questions/48530065/keras-clear-all-gpu-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!