tstseby
tstseby

Reputation: 1319

Keras Layer Build Error: build() takes 1 Positional Argument but two were given

I have the following error in this simple layer:

class MyLayer(Layer):

def __init__(self):
    super(MyLayer, self).__init__()

def build(self):
    # Create a trainable weight variable for this layer.
    self.kernel = self.add_weight(name='kernel', 
                                  shape=(1)
                                  trainable=True)
    super(MyLayer, self).build() 

def call(self, x):
    return x/self.kernel

When I use it as:

m = MyLayer()
t = m (input)

Error: build() takes one positional argument but two were given.

Upvotes: 3

Views: 1495

Answers (1)

Shubham Panchal
Shubham Panchal

Reputation: 4289

Each layer in a Keras layer requires a input_shape argument. Add it to your build() method.

Upvotes: 5

Related Questions