-
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
Allow saving weights of a very deep model into a HDF5 file. #7508
Conversation
…_group() methods that can deal with the problem of saving models with a lot of layers (or with nested deep models) into HDF5 files
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.
Please add a unit test that covers the case where header chunking occurs.
What's the number of layers past which you need this?
…robust to unrealistically long layer names
…ghts_names` HDF5 file attributes splitting
@fchollet FYI, I added the unit tests you asked for. I am not sure whether it is required to check the internals of the created HDF5 file or not, but the current tests do so. The number of layers of the model I could not save was over 1K. But the issue was not with the So, when you try to save a model containing a nested model, what happens is that the names of weights of the nested model are all saved within a single |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
Sorry for not reviewing this earlier. It got forgotten in the PR queue. But it seems like it would still be a useful fix. This PR has merge conflicts and will need a review (at a glance there will be at least small style issues to fix). Are you still interested in working on it? |
Thanks for @tunystom ! |
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.
I tried this and it works well 👍
I was able to rebase this PR against the current master. This required a minor conflict resolution in a unit test file within the test folder (which frankly I resolved quite randomly - only a few lines of code). Then I copied the newly rebased topology.py file into my keras library folder, and it did work without any issues. I was able to save NASNetMobile weights. |
Allow saving weights of a very deep model into a HDF5 file. # Conflicts: # tests/test_model_saving.py
merged and created an updated PR in #9398 |
@ahundt Thank you so much ! I just tried it, it's cool |
Merged updated PR. |
#Assuming that this is your model architecture. However, you may use whatever architecture, you want to (big or small; any). ################################################################################ #now, use pickle to save your model weights, instead of .h5 ################################################################################ pklfile= "D:/modelweights.pkl"
except:
restoredmodel= mymodel() ################################################################################ |
I encountered a problem while saving weights of very deep Keras models into HDF5 file. The culprit is the HDF5 file format's inability to save object headers larger than 64 kB (according to https://support.hdfgroup.org/HDF5/faq/limits.html).
This pull request should solve the following issues (without the need to implement any custom saving/loading methods as proposed by some comments)
I also answered to a question to a related issue on StackOverflow:
The fix is really simple. If the data array (
layer_names
andweight_names
specifically) being saved to HDF5 group is too large, it is simply chunked into several pieces (until they fit the memory limit) and saved individually under the original attribute name with an associated chunk number appended to it. The loading from a HDF5 file is implemented correspondingly.