ValueError: Unable to create dataset (name already exists)

5,719 views
Skip to first unread message

Harsha Medu

unread,
Dec 28, 2021, 9:12:42 PM12/28/21
to Keras-users
Hello Keras-users,
   I am using resnet50 pre-trained model for inference. I replace Conv2D layers with my custom layer. Inference works fine but when I save the modified model in ".h5" format, I get the following error.  I am using 2.7.0 version of keras and tensorflow.
Any clues to debug will definitely help.

Traceback (most recent call last):
  File "imagenet_sonos_inference.py", line 358, in <module>
    model.save('temp.h5')
  File "\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\h5py\_hl\group.py", line 148, in create_dataset
    dsid = dataset.make_new_dset(group, shape, dtype, data, name, **kwds)
  File "\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\h5py\_hl\dataset.py", line 137, in make_new_dset
    dset_id = h5d.create(parent.id, name, tid, sid, dcpl=dcpl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5d.pyx", line 87, in h5py.h5d.create
ValueError: Unable to create dataset (name already exists)

Thanks,

Harsha Medu

unread,
Dec 29, 2021, 2:02:51 AM12/29/21
to Keras-users
This is solved. I didn't set the name for weights and bias in custom layer. 
Now the problem is model.save("temp.h5") works fine. The inference too runs fine. 
But when I load the saved model as follows, I get error.
model = load_model('temp.h5', custom_objects={'Conv2DIMC':Conv2DIMC}) 

  File "\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\keras\layers\merge.py", line 79, in _compute_elemwise_op_output_shape
    'Inputs have incompatible shapes. '
ValueError: Inputs have incompatible shapes. Received shapes (112, 112, 256) and (110, 110, 256)

It should have been merge of two layers of size (56,56,256). Any clues why the save/load doesn't work ?

Thanks,

Lance Norskog

unread,
Dec 29, 2021, 3:57:32 PM12/29/21
to Harsha Medu, Keras-users
"It should have been merge of two layers of size (56,56,256)."
"Received shapes (112, 112, 256) and (110, 110, 256)"

As a quick guess: this is a padding problem. One side concatenates 56,56 to create 112,112 but the other side does not include padding of "same" or "causal", so it takes 112,112 and emits 110,110.

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/4758760f-1fdb-4ac3-b299-46c1411d260cn%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA

Snow Summer

unread,
May 19, 2022, 12:46:41 PM5/19/22
to Keras-users
Hello,

I am meeting the same problem when saving hdf5 format for my custom layer. How do you set the name for weights and bias?

Thanks,

Snow Summer

unread,
May 19, 2022, 3:27:30 PM5/19/22
to Keras-users
OK, I got it. When calling add_weight in building the custom layer, the name should be specified by `self.add_weight(name=...`.

Hamdi Mohamed

unread,
May 4, 2024, 10:43:03 AMMay 4
to Keras-users
hello 

I am meeting the same problem when saving hdf5 format for my custom layer. How do you set the name for weights and bias?
Thanks,
Reply all
Reply to author
Forward
0 new messages