Keras rename model and layers

For changing names of model.layers with tf.keras you can use the following lines:

for layer in model.layers:
    layer._name = layer.name + str("_2")

I needed this in a two-input model case and ran into the “AttributeError: can’t set attribute”, too. The thing is that there is an underlying hidden attribute _name, which causes the conflict.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)