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

Created on 27 Mar 2017  路  10Comments  路  Source: keras-team/keras

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?

stale

Most helpful comment

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())

All 10 comments

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

@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.

@Dragonblf same issue, very strange bug

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!

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

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())

Thanks. It worked. I was facing similar issues.

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings