我训练了两个模型来集成它们, 当我尝试使用此代码加载它们时:
from tensorflow.keras.models import load_model
models=[]
modelTemp=load_model('models/full.h5')
modelTemp.name = "inception1"
models.append(modelTemp)
发生错误:
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.
完整错误信息:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in __setattr__(self, name, value)
1968 try:
-> 1969 super(tracking.AutoTrackable, self).__setattr__(name, value)
1970 except AttributeError:
AttributeError: can't set attribute
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
2 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in __setattr__(self, name, value)
1972 ('Can\'t set the attribute "{}", likely because it conflicts with '
1973 'an existing read-only @property of the object. Please choose a '
-> 1974 'different name.').format(name))
1975 return
1976
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.
最佳答案
根据 this question here on StackOverflow 你需要使用:
modelTemp._name = 'inception'
关于python - 尝试重命名 tf.keras 上的预训练模型时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56886442/