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

Saving and Loading Model #40

Closed
nfmcclure opened this issue Feb 6, 2018 · 3 comments
Closed

Saving and Loading Model #40

nfmcclure opened this issue Feb 6, 2018 · 3 comments

Comments

@nfmcclure
Copy link

nfmcclure commented Feb 6, 2018

Hello,

Thank you for your wonderful work on this model! Very interesting. I'm working to save and then load the model for future evaluations.

Considering Keras' guide on saving/loading here:

https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model

I've tried this code:

from keras.models import load_model
model.save('my_model.h5')
model_loaded = load_model('my_model.h5')

But I get the following error:

Traceback (most recent call last):
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-124-9911263901fe>", line 1, in <module>
    model2 = load_model('my_model.h5')
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/models.py", line 243, in load_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/models.py", line 317, in model_from_config
    return layer_module.deserialize(config, custom_objects=custom_objects)
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 143, in deserialize_keras_object
    list(custom_objects.items())))
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/models.py", line 1353, in from_config
    model.add(layer)
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/models.py", line 492, in add
    output_tensor = layer(self.outputs[0])
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/engine/topology.py", line 617, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/keras/layers/core.py", line 663, in call
    return self.function(inputs, **arguments)
  File "/home/python/envs/python3.6/lib/python3.6/site-packages/wtte/wtte.py", line 85, in output_lambda
    a, b = _keras_unstack_hack(x)
NameError: name '_keras_unstack_hack' is not defined

Which I find strange because the function _keras_unstack_hack clearly exists in the wtte.py.

I'm running Ubuntu 16.04.3 and Python 3.6, with Keras v 2.1.3.

@nfmcclure nfmcclure reopened this Feb 6, 2018
@nfmcclure
Copy link
Author

nfmcclure commented Feb 6, 2018

Sorry for all the comments. Still getting the above error. Reinstalling seemed to work, then fail after rebooting. (With the same error as above)

@ragulpr
Copy link
Owner

ragulpr commented Feb 7, 2018

Hi thank you I'm glad you appreciate it!
See #8749, basically, keras can't save custom layers it's not wtte-specific. Saving weights is fine, just do model.save_weights(path) and run the same script you used to create the model before model.load_weights(path).

I'm sure there's other pickling-options but I haven't tried good luck!

@nfmcclure
Copy link
Author

Thanks for the response.

I see how to do it now. I didn't see that Keras issue, thanks for pointing it out. I'll close this issue.

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