Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save the keras model with model architecture and weights? #14

Open
AhmadShaik opened this issue Mar 21, 2019 · 2 comments
Open

Comments

@AhmadShaik
Copy link

I am able to save the keras model (nn4.small2.v1.h5) using the command model.save('new_model.h5'). But when I tried to load the model back, I am getting error, the complete details are given below.

nn4_small2_pretrained = create_model()
nn4_small2_pretrained.load_weights('weights/nn4.small2.v1.h5')

nn4_small2_pretrained.save("new_model.h5")

del nn4_small2_pretrained

from keras.models import load_model as lm

model = lm("new_model.h5")
Traceback (most recent call last):

  File "<ipython-input-8-74cf4e3a50de>", line 1, in <module>
    model = lm("waste.h5")

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/models.py", line 270, in load_model
    model = model_from_config(model_config, custom_objects=custom_objects)

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/models.py", line 347, in model_from_config
    return layer_module.deserialize(config, custom_objects=custom_objects)

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 144, in deserialize_keras_object
    list(custom_objects.items())))

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/engine/topology.py", line 2535, in from_config
    process_node(layer, node_data)

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/engine/topology.py", line 2492, in process_node
    layer(input_tensors[0], **kwargs)

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/engine/topology.py", line 619, in __call__
    output = self.call(inputs, **kwargs)

  File "/data/repos/tfenv/lib/python3.6/site-packages/keras/layers/core.py", line 685, in call
    return self.function(inputs, **arguments)

  File "/data/Work/workspace/person_recognition/python/face-recognition/utils.py", line 36, in LRN2D
    return tf.nn.lrn(x, alpha=1e-4, beta=0.75)

NameError: name 'tf' is not defined

How can I load a model without error

@lizhi1989
Copy link

i guess you do not have tensorflow, which is usually import as tf.
Keras by default make use of tensorflow backend.

@AhmadShaik
Copy link
Author

@lizhi1989 I do have tensorflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants