Reputation: 25
When I re-create a model, keras always makes a new name for a layer (conv2d_2 and so on) even if I override the model. How to make keras using the same name every time I run it without restarting the kernel.
Upvotes: 2
Views: 706
Reputation: 19153
When using Tensorflow (1.X) as a backend, whenever you add a new layer to any model, the name of the layer -unless manually set- will be set to the default name for that layer, plus an incremental index at the end.
Defining a new model is not enough to reset the incrementing index, because all models end up on the same underlying graph. To reset the index, you must reset the underlying graph.
In TF 1.X, this is done via tf.reset_default_graph()
. In TF 2.0, you can do this via the v1 compatibility API: tf.compat.v1.reset_default_graph()
(the latter will also solve some deprecation warnings you might get with the latest versions of TF 1.X)
Upvotes: 2