Keras清除所有GPU内存 [英] Keras clear all gpu memory

查看:130
本文介绍了Keras清除所有GPU内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做这样的事情:

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

ai_generator是使用不同配置实例化模型的生成器.
我的问题是gpu内存溢出,并且K.clear_session()不起作用,因为它抛出了此错误
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).
我如何清除新的喀拉拉邦记忆? 我只需要执行fit方法,就可以删除所有内容.

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.

推荐答案

我解决了删除模型之间共享的所有层的问题.输入为共享"实例. 然后我这样做了:

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

这篇关于Keras清除所有GPU内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆