Keras custom layer can't be saved because of duplicate weight names

278 views
Skip to first unread message

Christos Panagiotakopoulos

unread,
Feb 17, 2021, 5:18:09 AM2/17/21
to Keras-users
I have created a custom layer for a model in keras but when I try to save it, keras throws this error:

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/h5o.pyx", line 202, in h5py.h5o.link RuntimeError: Unable to create link (name already exists)

As I searched the above error, I found out that there are a couple of duplicate weight names inside my model

eg:

8 transformer_test/attention_test/dense/kernel:0 
9 transformer_test/attention_test/dense/bias:0 
10 transformer_test/attention_test/dense/kernel:0 
11 transformer_test/attention_test/dense/bias:0

The question is: What is causing those duplicate weight names? How could I prevent this from happening?

Here is the model's code. Thanks a lot in advance for your help! :)

Christos

Lance Norskog

unread,
Feb 17, 2021, 9:15:28 PM2/17/21
to Christos Panagiotakopoulos, Keras-users
I think that you can fix this by creating all of the inner layers (Conv1D etc.) with unique names.

If not, you will need to replace the uses of inner Layer with their tensorflow equivalents.

Lance Norskog

--
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/7f59a9a6-437a-47c2-b93b-5c847ea90ae9n%40googlegroups.com.


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

Christos Panagiotakopoulos

unread,
Feb 18, 2021, 5:17:31 AM2/18/21
to Lance Norskog, Keras-users
Thank you Lance, I just tried using unique names, and it worked!

Again thank you very much for your help!

Christos
Reply all
Reply to author
Forward
0 new messages