Keras reset layer numbers

你说的曾经没有我的故事 提交于 2019-12-18 17:27:22

问题


Keras assigns incrementing ID numbers to layers of the same type, e.g. max_pooling1d_7, max_pooling1d_8, max_pooling1d_9,etc. Each iteration of my code constructs a new model, starting with model = Sequential() and then adding layers via model.add(). Even though each cycle creates a new Sequential object, the layer ID numbers continue incrementing from the previous cycle. Since my process is long-running these ID numbers can grow very large. I am concerned that this could cause some problem. Why are the IDs not reset by model = Sequential()? Is there a way to reset them? After each cycle I have no use for the layer ID numbers and can discard them, but how? I am using the Tensorflow backend.


回答1:


The solution, from Attempting to reset tensorflow graph when using keras, failing:

from keras import backend as K
K.clear_session()



回答2:


Do you use jupyter notebooks? It seems like while you're rebuilding your model your tensorlow session won't restart. Because keras refers to tensorflow graphs per name it's necessary, that the counting continues.

So if you don't want to restartthe session you're fine. However this also means, that the tensorflow session gets bigger and bigger, so restarting the session might be the desired approach. For this restart the complete program/kernel.




回答3:


Each iteration shouldn't construct a new model. Training should go through in same model. Maybe post your code to see what might goes wrong.



来源:https://stackoverflow.com/questions/49123194/keras-reset-layer-numbers

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