question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TF2 : AttributeError: 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.

See original GitHub issue

Implementation on TF2 gives me the error : AttributeError: 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. at the ssd_300 or ssd_500 model creation. –> model = ssd_300(...) with nothing changed to the parameters.

I have changed all the keras... to tensorflow.keras..., and the keras.engine... ones to tensorflow.keras.layers... tf.__version__ : 2.0.0 from scipy.misc import imread changed to from matplotlib.pyplot import imread

Anyone with a solution for this?

If more info is required, I would be glad to provide.

(I’m sorry for very brief explanation, I don’t have much time on my hands at this moment)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11

github_iconTop GitHub Comments

21reactions
faisalshahbazcommented, Sep 10, 2020

I actually found the solution, You need to set self._trainable_weights instead of self.trainable_weights

8reactions
jessebr2commented, Apr 23, 2020

Have the same problem with TimeSeriesAttention

def build(self, input_shape):
    dimensions = input_shape[2]
    timed = keras.models.Sequential(name='per_time_step')
    timed.add(
        keras.layers.Dense(dimensions, input_shape=(dimensions,), kernel_initializer='zeros', activation='softmax', name='att_dense1')
    )
    timed.add(keras.layers.Dense(dimensions, kernel_initializer='glorot_normal', activation='tanh', name='att_dense2'))
    self.timed = keras.layers.TimeDistributed(timed, name='att_td')
    self.timed.build(input_shape)
    self.trainable_weights = self.timed.trainable_weights
    self.non_trainable_weights = self.timed.non_trainable_weights
    self.built = True

Change the:

self.trainable_weights = self.timed.trainable_weights

For:

self.trainable_weights.append(self.timed.trainable_weights)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't set the attribute "trainable_weights", likely because it ...
It says Can't set the attribute "trainable_weights", likely because it conflicts with an existing read-only @property of the object. Please ...
Read more >
tf.keras.layers.Layer | TensorFlow v2.11.0
It shows how to implement build() and call() . Variables set as attributes of a layer are tracked as weights of the layers...
Read more >
tensorflow.python.keras.engine.base_layer - DCASE-models
Variables set as attributes of a layer are tracked as weights of the layers (in `layer.weights`). ```python class SimpleDense(Layer): def __init__(self, ...
Read more >
Making a read-only attribute - Python Morsels
If you need to make a read-only attribute in Python, you can turn your attribute into a property that delegates to an attribute...
Read more >
"Fossies" - the Fresh Open Source Software Archive
178 Variables set as attributes of a layer are tracked as weights 179 of the ... will fail if the object is 289...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found