python - Keras 层构建错误 : build() takes 1 Positional Argument but two were given

标签 python tensorflow keras keras-layer tf.keras

我在这个简单层中有以下错误:

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

当我将它用作:

m = MyLayer()
t = m (input)

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

最佳答案

Keras 层中的每一层都需要一个 input_shape 参数。将它添加到您的 build() 方法中。

关于python - Keras 层构建错误 : build() takes 1 Positional Argument but two were given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58618123/

相关文章:

python - 在不展平的情况下对字符串列表的列表进行子集化

python - 在我的 M1 Macbook Pro 上设置 keras-rl2

android - 错误 :tensorflow:Couldn't understand architecture name ''

python - Cloud Storage 存储桶的 Cloud SQL 导入权限问题

python - TensorFlow Master 和 Worker 服务

tensorflow - 为什么 LayerNormBasicLSTMCell 比 LSTMCell 慢得多且准确度低?

python - 如何构建具有多个输入的 Tensorflow 模型?

python - Keras Tokenizer 方法究竟做了什么?

apache-spark - 使用 Keras 模型作为 Apache Spark 和 Elephas 的广播变量

python - 是否有更 Pythonic 的方法来使用 string.format 将字符串填充为可变长度?