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

ValueError: Unable to create group (Name already exists) while model.save() #6005

Closed
Dragonblf opened this issue Mar 27, 2017 · 11 comments
Closed

Comments

@Dragonblf
Copy link

Hey,
Every time I try to save my model (architecture and weights) I get an error.
I used the command: 'model.save('savepath')' and the ModelCheckpoint Callback funtcion, but at both I get this error message:

File "C:\Users\User\Downloads\Anaconda\lib\site-packages\keras\models.py", line 109, in save_model: topology.save_weights_to_hdf5_group(model_weights_group, model_layers)
File "C:\Users\User\Downloads\Anaconda\lib\site-packages\keras\engine\topology.py", line 2708, in save_weights_to_hdf5_group: g = f.create_group(layer.name)
File "C:\Users\User\Downloads\Anaconda\lib\site-packages\h5py\_hl\group.py", line 52, in create_group: gid = h5g.create(self.id, name, lcpl=lcpl)
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (C:\Minonda\conda-bld\h5py_1490030958306\work\h5py\_objects.c:2867)
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (C:\Minonda\conda-bld\h5py_1490030958306\work\h5py\_objects.c:2825)
File "h5py\h5g.pyx", line 151, in h5py.h5g.create (C:\Minonda\conda-bld\h5py_1490030958306\work\h5py\h5g.c:2851)

ValueError: Unable to create group (Name already exists)

Does anyone know how I can fix the problem?

@MarcoForte
Copy link

MarcoForte commented Mar 28, 2017

Updating h5py worked for me. I'm using Keras 2.0.1, python 3.5.
h5py: 2.6.0-np111py35_2 --> 2.7.0-np111py35_0

@Dragonblf
Copy link
Author

@MarcoForte That's good that it helped you, but I already have all the latest versions. I forgot to say that I'm using Anaconda with Python 3.6.

@fayeshine
Copy link

@Dragonblf same issue, very strange bug

@seanzzz
Copy link

seanzzz commented Apr 15, 2017

I had the same issue but was able to find the problem. What happened to me was that I assign a layer to a variable, eg. lstm_layer = LSTM(num_cells...), and repeatedly adding the same layer to a sequential model. I solved it by initializing a new layer each time I want to add the same layer. Hope this helps!

@nateGeorge
Copy link

@seanzzz what exactly do you mean? Can you give a quick code sample?

@frankherfert
Copy link

When you add layers and activations, you can either add them directly or as an instance:

leaky = keras.layers.advanced_activations.LeakyReLU()

classifier.add(Dense(units=32, kernel_initializer="uniform", input_dim=11))
classifier.add(leaky)
classifier.add(Dense(units=6, kernel_initializer="uniform"))
classifier.add(leaky)

This version will cause problems with a model_checkpoint. I assume that the checkpoint writes the weights into a column named "leaky" and since there are two with the exact same name, it gets confused.

What you can do is this:


classifier.add(Dense(units=32, kernel_initializer="uniform", input_dim=11))
classifier.add(keras.layers.advanced_activations.LeakyReLU())
classifier.add(Dense(units=6, kernel_initializer="uniform"))
classifier.add(keras.layers.advanced_activations.LeakyReLU())

@SmileyScientist
Copy link

Thanks. It worked. I was facing similar issues.

@atabakd
Copy link

atabakd commented Sep 4, 2017

The workaround is great, but it is still an issue.

@stale
Copy link

stale bot commented Dec 3, 2017

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.

@GoingMyWay
Copy link

try to use Lambda if you do some op on Inputs.

@innat
Copy link

innat commented Oct 20, 2021

this works for me

model.save_weights('a.h5') # value error 

for i in range(len(model.weights)):
    model.weights[i]._handle_name = model.weights[i].name + "_" + str(I)

model.save_weights('a.h5') # OK, saved.

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