问题
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 thisValueError: 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