I'm trying to load a model that it was saved with: model.save('myModel.h5')
The model is defined like this:
self.model = VGGFace(input_tensor=input_tensor, include_top=True)
for layer in self.model.layers:
layer.trainable = False
self.model.get_layer('fc7').trainable = True
last_layer = self.model.get_layer('fc7').output
out = BatchNormalization()(last_layer)
out = Dense(self.n_outputs, activation='softmax', name='fc8')(out)
self.model = Model(input=self.model.input, output=out)
when i try to load myModel.h5
with model.load_model('myModel.h5')
it throws me the following error:
AttributeError: 'Model' object has no attribute 'load_model'
I supose it's because i'm not working with Sequential
models.
How can i load my model then? since model.save('myModel.h5')
seems to work.
Thanks!!!!
load_model()
isn't an attribute of an model obejct indeed. load_model()
is a function imported from keras.models that takes a file name and returns a model obejct.
You should use it like this :
from keras.models import load_model
model = load_model(path_to_model)
You can then use keras.models.load_model(filepath) to reinstantiate your model. load_model will also take care of compiling the model using the saved training configuration (unless the model was never compiled in the first place). from source
The reason is sequential doesn't have a way to load the full model along with optimizer etc only weights. To load the complete model after you performed model.save('myModel.h5')
you should load the model with
import tensorflow as tf
from tensorflow import keras
#...
myModel = tf.keras.models.load_model("myModel.h5")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With