TypeError: __init__() got an unexpected keyword argument ‘name‘

When I wrote a custom class of Keras, I met this error.

Solution: 

change from the snippet below  

class custconv2d(keras.layers.Layer):
    def __init__(self):
        super(custconv2d, self).__init__()
        self.k = self.add_weight(shape=(1, ), initializer="random_normal", trainable=True, name='k1')
    

To

#add **kwargs in the __init__()
class custconv2d(keras.layers.Layer):
    def __init__(self, **kwargs):
        super(custconv2d, self).__init__(**kwargs)
        self.k = self.add_weight(shape=(1, ), initializer="random_normal", trainable=True, name='k1')
    

你可能感兴趣的:(debug,python,leetcode)