-
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
Keras save_weights does not support large number of layers #5253
Comments
I suggest that you save your weights manually by retrieving the weight
values via `model.get_weights()`.
I have never seen issue even though I have worked with very large models.
How many layers do you have?
…On 2 February 2017 at 09:59, Fei Xia ***@***.***> wrote:
Error on f.attrs['layer_names'] = [layer.name.encode('utf8') for layer in
flattened_layers].
If there are too many layers, the object header message will exceed hdf5's
limit 64KB. It's a problem of hdf5 and is marked as an known issue for hdf5
group. But it will be nice to see a work-around, for example, saving
weights to multiple files.
How to reproduce: Have a lot of layers and run model.save_weights.
Traceback (most recent call last):
File "train_model_pyramid.py", line 279, in <module>
model.save_weights('model_py_'+str(step)+'.hdf5')
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2652, in save_weights
self.save_weights_to_hdf5_group(f)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2663, in save_weights_to_hdf5_group
f.attrs['layer_names'] = [layer.name.encode('utf8') for layer in flattened_layers]
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2574)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2533)
File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/attrs.py", line 87, in __setitem__
self.create(name, data=value, dtype=base.guess_dtype(value))
File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/attrs.py", line 177, in create
attr = h5a.create(self._id, self._e(tempname), htype, space)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2574)
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2533)
File "h5py/h5a.pyx", line 47, in h5py.h5a.create (/tmp/pip_build_root/h5py/h5py/h5a.c:1809)
RuntimeError: Unable to create attribute (Object header message is too large)
Please make sure that the boxes below are checked before you submit your
issue. If your issue is an implementation question, please ask your
question on StackOverflow
<http://stackoverflow.com/questions/tagged/keras> or join the Keras Slack
channel <https://keras-slack-autojoin.herokuapp.com/> and ask there
instead of filing a GitHub issue.
Thank you!
-
[x ] Check that you are up-to-date with the master branch of Keras.
You can update with:
pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
-
[x ] If running on TensorFlow, check that you are up-to-date with the
latest version. The installation instructions can be found here
<https://www.tensorflow.org/get_started/os_setup>.
-
If running on Theano, check that you are up-to-date with the master
branch of Theano. You can update with:
pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
-
[x ] Provide a link to a GitHub Gist of a Python script that can
reproduce your issue (or just copy the script here if it is short).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5253>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AArWb8NcaPxeOLH0pw4N-cYkfJ0aoKkoks5rYhlogaJpZM4L1b7d>
.
|
Thanks, good idea. I have 5.6k layers. |
@fchollet |
@fxia22 How to use model.get_weights() and model.set_weights(). Could you give a simple example? |
This issue is reproduced with DPN https://github.com/titu1994/Keras-DualPathNetworks |
@burgalon There are a lot of additional lambda layers which I had to use in order to attempt grouped convolutions. When those are removed after TF and Keras adds them, it should be fine, I think. |
I've been able to reproduce this using NasNetLarge no top + ~10 additional layers. |
There is a PR for it, if you care about it please take over the PR or/and review it. #7508 |
updated at #9398 |
###USE get_weights AND set_weights TO SAVE AND LOAD MODEL, RESPECTIVELY. ############################################################################## #Assuming that this is your model architecture. However, you may use ################################################################################ #now, use pickle to save your model weights, instead of .h5 ################################################################################ pklfile= "D:/modelweights.pkl"
except:
restoredmodel= mymodel() ################################################################################ |
Read this drive link, it is better replica of above code: https://drive.google.com/open?id=1xzrqP7ExTmJiZqVt0A_G6AT69EbIjEI9tUDLD1twqj8 |
Error on
f.attrs['layer_names'] = [layer.name.encode('utf8') for layer in flattened_layers]
.If there are too many layers, the object header message will exceed hdf5's limit 64KB. It's a problem of hdf5 and is marked as an known issue for hdf5 group. But it will be nice to see a work-around, for example, saving weights to multiple files.
How to reproduce: Have a lot of layers and run
model.save_weights
.Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.
Thank you!
Check that you are up-to-date with the master branch of Keras. You can update with:
pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.
If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:
pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).
The text was updated successfully, but these errors were encountered: