Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

TypeError: __call__() got an unexpected keyword argument 'training' #471

Open
Abonia1 opened this issue May 17, 2020 · 6 comments
Open

TypeError: __call__() got an unexpected keyword argument 'training' #471

Abonia1 opened this issue May 17, 2020 · 6 comments

Comments

@Abonia1
Copy link

Abonia1 commented May 17, 2020

Hello I have issue in using dynamic_decode in tfa as below with tensorflow 2.X

I really appreciate if anyone have already resolved this issue as I have spent last 4 hours in it but still no solution out there.
image

@iamatsundere
Copy link

I have the same issue and stuck with it. Did you fix that?

@mukurgupta
Copy link

Hey, did you solve it?

@dr-alberto
Copy link

Same problem as well. In my case I was using keras sub classing for creating the model.

@dr-alberto
Copy link

SOLUTION FOR THIS ISSUE

In my case I'm subclassing the keras Model class, just as an example:

class Basic(tf.keras.Model):
    def __init__(self):
        super().__init__()
        
        self.dense1 = tf.keras.layers.Dense(32, input_shape=(10,), activation='relu')
        self.dense2 = tf.keras.layers.Dense(2, activation='sigmoid')
        
    def __call__(self, inputs):
        x = self.dense1(inputs)
        x = self.dense2(x)
        return x

model = Basic()    
model.compile(loss="categorical_crossentropy", optimizer='Adam', metrics=["accuracy"])
model.fit(X_encoded, y)

Running this I got this error: TypeError: __call__() got an unexpected keyword argument 'training'
The only thing I needed was to add training=False parameter to the __call__ function, so the code would be:

class Basic(tf.keras.Model):
    def __init__(self):
        super().__init__()
        
        self.dense1 = tf.keras.layers.Dense(32, input_shape=(10,), activation='relu')
        self.dense2 = tf.keras.layers.Dense(1, activation='sigmoid')
        
    def __call__(self, inputs, training=False):
        x = self.dense1(inputs)
        x = self.dense2(x)
        return x

model = Basic()    
model.compile(loss="categorical_crossentropy", optimizer='Adam', metrics=["accuracy"])
model.fit(X_encoded, y)

Hope this helps

@priya170807
Copy link

Thanks!..I did the same

@chaithyagr
Copy link

I think you need to define your custom call function as :

def call(self, inputs):
    <do stuff>
    return output

If you use __call__, you are essentially overloading the core python codes..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants