Search code examples
tensorflowkeraskeras-layer

Keras reset layer numbers


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.


Solution

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

    from keras import backend as K
    K.clear_session()