Keras rename model and layers

前端 未结 8 847
情话喂你
情话喂你 2020-12-31 00:46

1) I try to rename a model and the layers in Keras with TF backend, since I am using multiple models in one script. Class Model seem to have the property model.name, but whe

8条回答
  •  不思量自难忘°
    2020-12-31 01:12

    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.

提交回复
热议问题