michetonu / gradient_reversal_keras_tf

Keras implementation of a gradient reversal layer for the Tensorflow backend
GNU General Public License v3.0
91 stars 24 forks source link

AttributeError: Can't set the attribute "trainable_weights" #9

Open emoebel opened 2 years ago

emoebel commented 2 years ago

Hi, what tensorflow and keras versions are you using?

I have:

tensorflow-gpu          2.6.0
keras                   2.6.0

I had to adapt your imports:

from tensorflow.keras.layers import Layer
import tensorflow.keras.backend as K

instead of:

from keras.engine import Layer
import keras.backend as K

When I try to instanciate your gradient reversal layer, I get 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.

How should I edit the code to make it work with recent versions of tensorflow ?

emoebel commented 2 years ago

fyi, I am following solution in: https://stackoverflow.com/questions/56841166/how-to-implement-gradient-reversal-layer-in-tf-2-0

for now it seems to work

michetonu commented 2 years ago

Hey, thanks for pointing this out! Indeed my solution seems to only work with TF1. I added a requirements file where a specify the Keras and TF version – I'll also update the readme. I'm not really maintaining this actively anymore, but I'm happy to see that others have found solutions for TF2