-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Make Keras models Pickle-able #10483
Conversation
@farizrahman4u cool, I was going to do the same thing. any chance we can do this without introducing about 95% code duplication for |
@fchollet unrelated test seems to be failing? |
The CNTK test is a fluke, but the pep8 one is real?
|
keras/engine/saving.py
Outdated
raise TypeError('Not JSON Serializable:', obj) | ||
|
||
|
||
def get_model_state(model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function would exist exclusively for pickling, so I think it should have "pickle" or some such in the name (e.g. get_model_state_for_pickling
Additionally, the code seems highly redundant with save_model / load_model. How can we refactor to minimize code duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fchollet What about - we have a common get_model_state()
/load_model_from_state()
which will be called by pickle_model()
/unpickle_model()
and load_model()
/save_model()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After further thought, that would make h5py write sub-optimal. We would be creating a fully copy of the model weights in memory and writing it all at once to disk. So probably leave save_model
as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fchollet ping ping
I think that it may be possible to use the hdf5 serialization and pickle at the same time. The trick is to hdf5 serialize the model in memory (which can be done, see As a side-benefit of this process, there need not be another materially different serialization method. Anybody see any pitfalls to this design? |
Hi, I think this is a useful feature and we should merge it. What's the status on this PR? Thanks. |
It is functional. You had asked me to refactor it such that we have a single serialization method which would be called by |
Seemingly some issues on CI: https://travis-ci.org/keras-team/keras/builds/421708916?utm_source=github_status&utm_medium=notification |
# if obj is any numpy type | ||
if type(obj).__module__ == np.__name__: | ||
if isinstance(obj, np.ndarray): | ||
return {'type': type(obj), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've changed this behavior recently, this will need to be updated
Is there any possibility that using a shared function with a callback structure would work? In one case the callback would write to a HDF5 file, in the other case it would just build a dict. |
Or we create a dict-like HDF5 file class. |
Let's close this PR and move this to #11030. |
I am having the same problem when I try to run
Is there any workaround this problem? |
#10475