Keras: TypeError: add_weight() got multiple values for argument 'name'

Created on 11 Nov 2019  路  4Comments  路  Source: keras-team/keras

Hi I have this error and I am not sure why:

2019-11-10 19:28:49.105252: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-11-10 19:28:49.510154: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2400225000 Hz
2019-11-10 19:28:49.514852: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5eed2e0 executing computations on platform Host. Devices:
2019-11-10 19:28:49.514902: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wanitchaya/deepcut/deepcut/train.py", line 188, in train_model
    model = get_convo_nn2()
  File "/home/wanitchaya/deepcut/deepcut/model.py", line 57, in get_convo_nn2
    out = crf(x)
  File "/home/wanitchaya/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
    return func(*args, **kwargs)
  File "/home/wanitchaya/.local/lib/python3.5/site-packages/keras/engine/base_layer.py", line 463, in __call__
    self.build(unpack_singleton(input_shapes))
  File "/home/wanitchaya/deepcut/deepcut/layers.py", line 182, in build
    constraint=self.kernel_constraint)
TypeError: add_weight() got multiple values for argument 'name'

System information

  • OS: Scientific Linux 7.2
  • TensorFlow backend (yes / no): Not sure
  • TensorFlow version: 2.0
  • Keras version: 2.3.1
  • Python version: 3.5.2

To reproduce this behavior
You can clone my github repo and go to the deepcut/deepcut directory. Then you can run this in python interpreter:

>>> import train
>>> train.train_model("cleaned_data", "../weight/model_crf_weight.h5")

Thank you so much for your help!

tensorflow support

Most helpful comment

Please go to https://github.com/wanitchayap/deepcut/blob/master/deepcut/layers.py and find the above snippet. In _add_weight()_ function name the first arguments as 'shape' like:

self.kernel = self.add_weight(shape=(self.input_dim, self.units),
name='kernel',
initializer=self.kernel_initializer,
regularizer=self.kernel_regularizer,
constraint=self.kernel_constraint)

Do this in all your _add_weight_ functions. Most likely you will get rid of this error. This has worked for me.

Thank you,
Deepak Singh

All 4 comments

I am also getting the same error. Please help us in this.

Thank you

image

Please go to https://github.com/wanitchayap/deepcut/blob/master/deepcut/layers.py and find the above snippet. In _add_weight()_ function name the first arguments as 'shape' like:

self.kernel = self.add_weight(shape=(self.input_dim, self.units),
name='kernel',
initializer=self.kernel_initializer,
regularizer=self.kernel_regularizer,
constraint=self.kernel_constraint)

Do this in all your _add_weight_ functions. Most likely you will get rid of this error. This has worked for me.

Thank you,
Deepak Singh

I was getting the same error but your solution helped me to solve it :) tnx

Was this page helpful?
0 / 5 - 0 ratings

Related issues

somewacko picture somewacko  路  3Comments

anjishnu picture anjishnu  路  3Comments

NancyZxll picture NancyZxll  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments

amityaffliction picture amityaffliction  路  3Comments