KerasでRuntimeError: The name is used 2 times in the model.All layer names should be unique

Kerasで同じモデルを複数使った時に表題のエラー。

model1 = vgg16.VGG16(...)
model2 = vgg16.VGG16(...)

みたいなコードを書いていたら、

RuntimeError: The name is used 2 times in the model.All layer names should be unique.

名前を変えないとダメらしい。

model1.name = 'vgg1'
model2.name = 'vgg2'

今度は別のエラー。

AttributeError: Can't set the attribute "name", likely because it conflicts with an existing read-only @property of the object. Please choose a different name.

name属性はread-onlyになっているらしい。

_nameというアンダーバー付きの隠し属性を設定して回避する。

model1._name = 'vgg1'
model2._name = 'vgg2'

これで解決。

参考

Keras - All layer names should be unique
I combine two VGG net in keras together to make classification task. When I run the program, it shows an error: RuntimeError: The name "predictions" is used ...
Error when trying to rename a pretrained model on tf.keras
I trained two models in order to ensemble them, when I try to load them with this code: from tensorflow.keras.models import load_model models=[] modelTem...
Keras rename model and layers
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....

コメント

タイトルとURLをコピーしました