1

when i define my own layers with tf.keras,like this:

def build(self, input_shape):
    self.input_spec = [InputSpec(shape=input_shape)]
    shape = (input_shape[self.axis],)
    #print('shape:',type(shape))
    init_gamma = self.scale * np.ones(shape)
    self.gamma = tf.Variable(init_gamma,name='{}_gamma'.format(self.name))
    print('type',type([self.gamma]))
    self.trainable_weights=[self.gamma]

It raise a bug in the tf/python/keras/base_layer.py that I can't set the attribute "trainable_weights" likely because it conflicts with:

 an existing read-only @property  of the object. Please choose a different name

What should I do?

Mike
  • 342
  • 4
  • 13
gabriel777
  • 11
  • 1
  • 2
    [Possible duplicate. Check this post](https://stackoverflow.com/questions/63343563/cant-set-the-attribute-trainable-weights-likely-because-it-conflicts-with-an) – Mike Dec 18 '20 at 03:49
  • Does this answer your question? [Can't set the attribute "trainable\_weights", likely because it conflicts with an existing read-only](https://stackoverflow.com/questions/63343563/cant-set-the-attribute-trainable-weights-likely-because-it-conflicts-with-an) – Brandon Essler Apr 23 '21 at 00:17

0 Answers0