Reputation: 445
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=[]
modelTemp=load_model('models/full.h5')
modelTemp.name = "inception1"
models.append(modelTemp)
error occur :
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.
full error message:
---------------------------------------------------------------------------
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.
Upvotes: 18
Views: 12316
Reputation: 91
I have answered the same topic here How to rename Pre-Trained model ? ValueError 'Trained Model' is not a valid scope name
Solution is:
model = load_model(r"C:\Master\Learning\Agri_Intelligence\Models\Model.h5")
model._name = "New_Model_Name"
model.save(r"C:\Master\Learning\Agri_Intelligence\Models\New_Model.h5")
Upvotes: -1
Reputation: 511
According to this question here on StackOverflow you need to use:
modelTemp._name = 'inception'
Upvotes: 26