python - Cannot add layers to saved Keras Model. 'Model' object has no attribute 'add' -
i have saved model using model.save()
. i'm trying reload model , add few layers , tune hyper-parameters, however, throws attributeerror.
model loaded using load_model()
.
i guess i'm missing understanding how add layers saved layers. if can guide me here, great. i'm novice deep learning , using keras, request silly.
snippet:
prev_model = load_model('final_model.h5') # loading saved model. prev_model.add(dense(256,activation='relu')) prev_model.add(dropout(0.5)) prev_model.add(dense(1,activation='sigmoid')) model = model(inputs=prev_model.input, outputs=prev_model(prev_model.output))
and error throws:
traceback (most recent call last): file "image_classifier_3.py", line 39, in <module> prev_model.add(dense(256,activation='relu')) attributeerror: 'model' object has no attribute 'add'
i know adding layers works on new sequential() model, how add existing saved models?
the add
method present in sequential models (sequential
class), simpler interface more powerful complicated functional model (model
class). load_model
return model
instance, generic class.
you can @ example see how can compose different models, idea that, in end, model
behaves pretty other layer. should able do:
prev_model = load_model('final_model.h5') # loading saved model. new_model = sequential() new_model.add(prev_model) new_model.add(dense(256,activation='relu')) new_model.add(dropout(0.5)) new_model.add(dense(1,activation='sigmoid')) new_model.compile(...)
Comments
Post a Comment